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

Serializer and Validator mappings don't use Bundle#getPath() #18563

Closed
wouterj opened this issue Apr 16, 2016 · 8 comments
Closed

Serializer and Validator mappings don't use Bundle#getPath() #18563

wouterj opened this issue Apr 16, 2016 · 8 comments

Comments

@wouterj
Copy link
Member

wouterj commented Apr 16, 2016

Description

The bundle class has a getPath() method, allowing you to override the path of the bundle. However, inside the FrameworkExtension, $reflection->getFileName() is used to get the path to the bundle. This means that getPath() is ignored.

Use-case

In my case, my bundle directory structure looks like:

MyBundle/
  src/
    MyBundle.php
    ...
  Resources/
    config/
      serializer.yml
      validator.yml

In the MyBundle class, I override getPath() to return MyBundle/. This way, I would expect the serializer and validator configuration to be loaded. However, since they use reflection they're looking for MyBundle/src/Resources/config/serializer.yml.

Possible Solution

The auto-discovery of config files should be moved to a compiler pass. These have access to the bundle class instance (instead of FQCN) and can call ->getPath() on this instance instead of simulating the default behaviour of this method.

@chalasr
Copy link
Member

chalasr commented Apr 16, 2016

👍 Same here, forced to use the default location.

@wouterj How would you access the bundle class instance in a compiler pass?
I mean without manually creating the instance from the FQCN (as it's possible to do in the FrameworkExtension).

@linaori
Copy link
Contributor

linaori commented Apr 16, 2016

I think one of my colleagues hit this bump when trying to register virtual bundles.

@linaori
Copy link
Contributor

linaori commented Apr 18, 2016

If I understand the issue correctly, the problem lies with the Bundle files being meta information and functional at the same time.

@chalasr
Copy link
Member

chalasr commented Apr 19, 2016

@ro0NL
Copy link
Contributor

ro0NL commented Aug 10, 2016

@wouterj what about this approach?

@chalasr
Copy link
Member

chalasr commented Aug 18, 2016

According to this line, this issue should concern the bundle's translations directory too.

Some solutions are actually proposed in #19606 and #19646 (Only tested with #19646 and it indeed fix it as it makes bundle instances available from any extension).

@ro0NL
Copy link
Contributor

ro0NL commented Aug 18, 2016

To clarify; this is also not about moving things from extensions to compilers (it could be legit though) as in both cases there's no context/service object/kernel/whatsoever available. Extensions are just part of a compiler.

@chalasr
Copy link
Member

chalasr commented Dec 31, 2016

See #21113

fabpot added a commit that referenced this issue 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()
@fabpot fabpot closed this as completed Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants