Skip to content

[FrameworkBundle][HttpKernel] Fix resources loading for bundles with custom structure #21113

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

Merged
merged 1 commit into from
Jan 4, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Dec 31, 2016

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #18563
License MIT
Doc PR n/a

This fixes twig/translator/validator/serializer resource loading for bundles overriding Bundle::getPath(), adding a kernel parameter containing the bundle metadata (i.e. path, namespace and parent).

Fixes #18563 and unlocks #19586

@chalasr chalasr changed the title [FrameworkBundle] Fix resources loading for bundles with custom structure [FrameworkBundle][HttpKernel] Fix resources loading for bundles with custom structure Dec 31, 2016
@ogizanagi
Copy link
Contributor

I hope this can be accepted as a bugfix rather than a new feature though :/

@xabbuh
Copy link
Member

xabbuh commented Dec 31, 2016

The minimum required version of the HttpKernel component in the FrameworkBundle must be updated from ~2.7.15|~2.8.8 to ~2.7.23|~2.8.16.

@chalasr chalasr force-pushed the kernel/bundle_metadata branch from a49e87d to 6c87d77 Compare December 31, 2016 12:32
@chalasr
Copy link
Member Author

chalasr commented Dec 31, 2016

@xabbuh thanks, done

$reflection = new \ReflectionClass($class);
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
if (is_dir($dir = dirname($bundle['path']).'/Resources/translations')) {
Copy link
Member

Choose a reason for hiding this comment

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

Calling dirname() here (and in all places below) looks wrong to me as the path key should already just refer to directory in which the bundle is stored.

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, fixed

Copy link
Member

@xabbuh xabbuh Dec 31, 2016

Choose a reason for hiding this comment

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

Maybe it would be good to have a dedicated test case working with a bundle that follows the default behaviour (i.e. extending the base Bundle class without overriding the getPath() method) to detect a similar issue in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I missed this comment. I think the test you have in mind already exists, the one added here is a copy paste: https://github.com/symfony/symfony/pull/21113/files#diff-b0c828e732d3d31f0b2bfb2378bd1011R340
Correct me if I'm wrong

@chalasr chalasr force-pushed the kernel/bundle_metadata branch 2 times, most recently from 1582a32 to 332aeb8 Compare December 31, 2016 14:30
@chalasr
Copy link
Member Author

chalasr commented Dec 31, 2016

Tests are green

foreach ($this->bundles as $name => $bundle) {
$bundles[$name] = get_class($bundle);
$bundlesMetadata[$name] = array('parent' => $bundle->getParent(), 'path' => $bundle->getPath(), 'namespace' => $bundle->getNamespace());
Copy link
Member

Choose a reason for hiding this comment

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

To make this more readable I would change the code style to this:

$bundlesMetadata[$name] = array(
    'parent' => $bundle->getParent(),
    'path' => $bundle->getPath(),
    'namespace' => $bundle->getNamespace(),
);

@xabbuh
Copy link
Member

xabbuh commented Dec 31, 2016

👍

Status: Reviewed

@chalasr chalasr force-pushed the kernel/bundle_metadata branch 2 times, most recently from fc6afb3 to 278186f Compare January 2, 2017 12:33
@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jan 2, 2017
@chalasr chalasr force-pushed the kernel/bundle_metadata branch 2 times, most recently from a4b54c0 to e29fdf9 Compare January 4, 2017 08:54
@xabbuh
Copy link
Member

xabbuh commented Jan 4, 2017

ping @symfony/deciders

@stof
Copy link
Member

stof commented Jan 4, 2017

This should also update the TwigBundle path registration

@chalasr chalasr force-pushed the kernel/bundle_metadata branch 2 times, most recently from cd5c429 to 6ba13a9 Compare January 4, 2017 18:14
@chalasr
Copy link
Member Author

chalasr commented Jan 4, 2017

@stof done

@@ -21,7 +21,7 @@
"symfony/twig-bridge": "~2.7",
"twig/twig": "~1.28|~2.0",
"symfony/http-foundation": "~2.5",
"symfony/http-kernel": "~2.7"
"symfony/http-kernel": "~2.7.23"
Copy link
Member

Choose a reason for hiding this comment

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

This forbids using 2.8, you should add |~2.8.16.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@chalasr chalasr force-pushed the kernel/bundle_metadata branch from 6ba13a9 to fef3146 Compare January 4, 2017 19:27
@fabpot
Copy link
Member

fabpot commented Jan 4, 2017

Thank you @chalasr.

@fabpot fabpot merged commit fef3146 into symfony:2.7 Jan 4, 2017
fabpot added a commit that referenced this pull request Jan 4, 2017
…ndles with custom structure (chalasr)

This PR was merged into the 2.7 branch.

Discussion
----------

[FrameworkBundle][HttpKernel] Fix resources loading for bundles with custom structure

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18563
| License       | MIT
| Doc PR        |  n/a

This fixes twig/translator/validator/serializer resource loading for bundles overriding `Bundle::getPath()`, adding a kernel parameter containing the bundle metadata (i.e. `path`, `namespace` and `parent`).

Fixes #18563 and unlocks #19586

Commits
-------

fef3146 Fix serializer/translations/validator resources loading for bundles overriding getPath()
@chalasr chalasr deleted the kernel/bundle_metadata branch January 4, 2017 20:00
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.

8 participants