Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpKernel][FrameworkBundle] Add alternative convention for bundle directories #32845

Merged
merged 1 commit into from
Aug 13, 2019

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Aug 1, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #32453
License MIT
Doc PR TODO

We already know that bundles must be compatible with many Symfony's versions, so it is very likely that current bundles won't be able to use this feature soon, unless they create symbolic links to support both structures.

The point is that this is already happening, so in the future when our bundles stop to support <=4.3 then you'll be sure to change the current directory structure.

We have recently added the getPublicDir() method in #31975, here I'm removing it in favor of hardcoding a new convention.

I've added some functional tests in which I've changed everything to this structure:

-- ModernBundle
   |-- config/ 
   |-- public/
   |-- src/
       |-- ModernBundle.php
   |-- templates/
   |-- translations/

WDYT?

@nicolas-grekas
Copy link
Member

As I wrote in #32453 (comment), I'm not sure we want to make dirs configurable. Even getPublicDir is suspicious to me.

@linaori
Copy link
Contributor

linaori commented Aug 1, 2019

I think making them configurable isn't necessarily what I want, it's the confusing structure it has right now I'd like to change. Making dirs configurable is one way to do this, because it means I don't have to follow the current structure and that it provides a migration path to change the default.

I very much prefer the structure as shown in the example. The fact that the non-code directory is called "Resources" (mind you, capital R) is bothering me since the start. the "views" directory isn't named correctly anymore either as it's called "templates" in Symfony.

Not sure if the proposed API is a good idea, but I do think that the bundle is responsible for the exposure of certain directories.

  • "Hey Symfony, you can find templates in this directory!"
  • "Hey, this directory contains entities, if you use doctrine, please register this"
  • etc.

Symfony telling where everything should be feels like something we could change, though it should have sane defaults. I don't agree with the current structure being a sane default anymore due to the changes in the Symfony structure; app/Resources vs bundle/Resources.

@ro0NL
Copy link
Contributor

ro0NL commented Aug 1, 2019

what if we create a single entrypoint similar like Kernel, e.g. $bundle->locateResource(BundlePaths::CONFIG_DIR[, 'validator.yaml'])

with a built-in deprecation for views in favor of templates

for DI extensions we should also consider injecting the config dir somehow, or access to any path for that matter

@yceruto
Copy link
Member Author

yceruto commented Aug 1, 2019

As I wrote in #32453 (comment), I'm not sure we want to make dirs configurable. Even getPublicDir is suspicious to me.

I'm fine if it's not configurable, but we still want a new bundle directory structure, do you want it too?

with a built-in deprecation for views in favor of templates

@ro0NL we shouldn't deprecating yet -> ... bundles must be compatible with many Symfony's versions. at least until we're sure we can all migrate to the new structure without any compatibility issue.

for DI extensions we should also consider injecting the config dir somehow, or access to any path for that matter

I'm not sure it's necessary, you can hardcode it safely there, it's in userland.

@nicolas-grekas
Copy link
Member

we still want a new bundle directory structure, do you want it too

yes! that'd look consistent with the new directory structure of apps

I'd just do it in FrameworkExtension only (and remove/deprecate getPublicDir)

@yceruto yceruto changed the title [HttpKernel][FrameworkBundle] Add new method for bundle paths configuration [HttpKernel][FrameworkBundle] Add alternative convension for bundle directories Aug 1, 2019
@yceruto yceruto changed the title [HttpKernel][FrameworkBundle] Add alternative convension for bundle directories [HttpKernel][FrameworkBundle] Add alternative convention for bundle directories Aug 1, 2019
@yceruto
Copy link
Member Author

yceruto commented Aug 1, 2019

Update

Removed the configuration of the bundle directory, it is now a new convension that we can optionally use as of 4.4 version.

Added getBundleDir method to the Bundle class, which is intended to define the root directory of the bundle. It may differ from the directory where the Bundle.php file is located (aka getPath()), e.g. when we have the new structure src/Bundle.php then ->getBundleDir() is a folder higher up.

The current convention is not being obsolete yet, it will (in the future).

Convention from 3rd-party bundles like Doctrine (/Resources/config/doctrine) must progressively support the new method in order to finally be able to deprecating/remove the old structure.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this approach :)
What's the purpose of getPath now? Should we deprecated it? Or should we plan to deprecate it in 5.1, to help bundles migrate smoothly?

src/Symfony/Component/HttpKernel/Bundle/Bundle.php Outdated Show resolved Hide resolved
@yceruto
Copy link
Member Author

yceruto commented Aug 5, 2019

What's the purpose of getPath now? Should we deprecated it? Or should we plan to deprecate it in 5.1, to help bundles migrate smoothly?

I think that as of 5.2 (NOV 2020) where we should start to deprecating the legacy structure as well. That'll match with the end of support for 3.4.

@yceruto
Copy link
Member Author

yceruto commented Aug 6, 2019

Sorry for the rebasing after the approved revisions, I needed to update my PhpUnit bridge to make my local phpunit work properly.

Status: This Is Ready In My Side ;)

UPGRADE-4.4.md Outdated Show resolved Hide resolved
@yceruto yceruto force-pushed the bundle_paths branch 4 times, most recently from 5de3197 to 12c4c16 Compare August 13, 2019 13:28
@nicolas-grekas
Copy link
Member

Thank you @yceruto.

@nicolas-grekas nicolas-grekas merged commit 6996e1c into symfony:4.4 Aug 13, 2019
nicolas-grekas added a commit that referenced this pull request Aug 13, 2019
…on for bundle directories (yceruto)

This PR was squashed before being merged into the 4.4 branch (closes #32845).

Discussion
----------

[HttpKernel][FrameworkBundle] Add alternative convention for bundle directories

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32453
| License       | MIT
| Doc PR        | TODO

We already know that bundles must be compatible with many Symfony's versions, so it is very likely that current bundles won't be able to use this feature soon, unless they create symbolic links to support both structures.

The point is that this is already happening, so in the future when our bundles stop to support <=4.3 then you'll be sure to change the current directory structure.

We have recently added the `getPublicDir()` method in #31975, here I'm removing it in favor of hardcoding a new convention.

I've added some functional tests in which I've changed everything to this structure:
```
-- ModernBundle
   |-- config/
   |-- public/
   |-- src/
       |-- ModernBundle.php
   |-- templates/
   |-- translations/
```
WDYT?

Commits
-------

6996e1c [HttpKernel][FrameworkBundle] Add alternative convention for bundle directories
@yceruto yceruto deleted the bundle_paths branch August 13, 2019 13:30
@yceruto
Copy link
Member Author

yceruto commented Aug 13, 2019

Yujuuu!! 🎉

@anyt
Copy link

anyt commented Jan 8, 2020

Hi,

Bundle::getPublicDir() method is mentioned in the documentation but it's not used.

Are there any plans to introduce the function back or remove it from documentation?

@yceruto
Copy link
Member Author

yceruto commented Jan 8, 2020

Are there any plans to introduce the function back or remove it from documentation?

Yes, it should be removed from the documentation (leftover of #31975)

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Jan 12, 2020
This PR was merged into the 4.4 branch.

Discussion
----------

remove getPublicDir() documentation

see symfony/symfony#32845 (comment)

Commits
-------

e3fa2e6 remove getPublicDir() documentation
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 18, 2021
…e (yceruto)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

Promoting new bundle directory structure as best practice

As Symfony 3.4 is not currently supported (security fixes only) I would like to propose to start promoting the new bundle directory structure (compatible since 4.4) consistent with the project one.

What do you think?

Fix: #12156
PR: symfony/symfony#32845

Commits
-------

d44bfa8 Promoting new bundle directory structure as best practice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants