Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Use Bundle#getPath() to load config files#18579

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
chalasr wants to merge2 commits intosymfony:2.7fromchalasr:ticket_18563

Conversation

@chalasr
Copy link
Member

@chalasrchalasr commentedApr 18, 2016
edited
Loading

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#18563
LicenseMIT
Doc PRn/a

This is the better workaround I found for now.
As proposed by@wouterj, it would be cleaner to move the whole logic in a compiler pass and use the bundle classes instance directly, but$container->get('kernel')->getBundles() is not accessible because the service is synthetic (tried within the SerializerPass for instance), same problem in the extension.
I would like to have your suggestions if you think that would be even better to use a compiler pass.

I've kept the reflection and used it to invoke thegetPath() method of each bundle, rather than callingdirname($reflection->getFilename()) and so totally ignore thegetPath() method.

{
$reflection =new \ReflectionClass($fqcn);
$getPathReflection =new \ReflectionMethod($fqcn,'getPath');

Copy link
Member

Choose a reason for hiding this comment

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

this is broken in case the class has some mandatory controller arguments (a few bundles do)

Copy link
MemberAuthor

@chalasrchalasrApr 18, 2016
edited
Loading

Choose a reason for hiding this comment

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

@stof Of course ... Do you know how a way to access the bundles instances directly from a compiler pass?@wouterj ?

privatefunctiongetBundlePath($fqcn)
{
$reflection =new \ReflectionClass($fqcn);
$getPathReflection =new \ReflectionMethod($fqcn,'getPath');
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@stof I replaced the instance by this one, but I'm not sure if it can be a solution?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's a solution, the bundle could use on of it's constructor arguments to determine it's path.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@jvasseur Yes this is what I mean. Any suggestion?

Copy link
Contributor

@jvasseurjvasseurApr 19, 2016
edited
Loading

Choose a reason for hiding this comment

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

I don't think we can do anything without the actual bundle instances, maybe we can update the Kernel class to set the kernel service into the ContainerBuilder ?

Copy link
MemberAuthor

@chalasrchalasrApr 19, 2016
edited
Loading

Choose a reason for hiding this comment

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

ATM the only working way I found is to pass the Kernel instance as argument to the FrameworkBundle when register it (e.g.new FrameworkBundle($this) in theAppKernel), then pass the kernel as argument to a compiler pass (from the FrameworkBundle class) and use it to get the bundle instances. It works but I think that adding an argument to the FrameworkBundle is really not an alternative :/

@wouterj
Copy link
Member

Is there an actual use-case to define the bundle path based on constructor arguments? I don't see any reason to do that.

What about making the method static? Won't that be an easy solution?

@chalasr
Copy link
MemberAuthor

chalasr commentedApr 19, 2016
edited
Loading

@wouterj I don't see any reason to use the constructor args inside the method, but in this case it leads to a fatal error.
Making the method static wouldeasily solve the issue.

EDIT

@wouterj Making the method static gives unexpected side effects as the method uses$reflected->getFilename() as default path and the baseBundle is abstract.

@jvasseur
Copy link
Contributor

@wouterj the use case is see is to have a "virtual" bundle class that you can add multiple times, specifying the path in the constructor.

@chalasr
Copy link
MemberAuthor

chalasr commentedApr 19, 2016
edited
Loading

@jvasseur In case of setting the path ingetPath depending on constructor args, callgetPath from an instance without constructor would result in the default value (that isdirname($reflected->getFilename()), called bySymfony\Component\HttpKernel\Bundle\Bundle#getPath), or at worstnull.

In case ofgetPath returningnull, the value would be the default too (dirname($reflection->getFilename()) called fromFrameworkExtension#getBundlePath()).

ATM I see a real gain into use the bundle#getPath if available (it will for most bundles), and a real loss if we don't try to use it at all.
Plus, I never saw a bundle that make such logic in itsgetPath (maybe you have an example?).

@jvasseur
Copy link
Contributor

jvasseur commentedApr 19, 2016
edited
Loading

@chalasr the example i had in mind ishttps://github.com/WouterJ/Bundleless/blob/master/VirtualBundle.php

The problem with creating a bundle withnewInstanceWithoutConstructor is that you don't get a properly instantiated class that could error in the getPath method (for example calling a method on one of its properties).

@chalasr
Copy link
MemberAuthor

chalasr commentedApr 19, 2016
edited
Loading

@jvasseur As the properties are declared but not set (constructor not called), callinggetPath of the example you given would returnnull, and so, because of the condition in the return statement ofFrameworkExtension#getBundlePath, the reflection file directory would be used (i.e.return $getPathReflection->invoke($reflectionInstance) ?: dirname($reflection->getFilename());).

As I understand, you're right, this fixes the issue for most cases but not for this particular (where it would behave as actually), but, while members are properly declared, I don't see how it could lead to errors?

@jvasseur
Copy link
Contributor

@chalasr It could lead to errors if you do something like this

class Bundle{publicfunction__construct($someProperty)    {$this->someProperty =$someProperty;    }publicfunctiongetPath()    {return$this->someProperty->someMethod();    }}

@chalasr
Copy link
MemberAuthor

As said, the proposed fix would cover most of cases (all bundles classes that don't use any constructor argument into thegetPath method). Also it removes duplicated code (getting the reflection file directory was repeated in each method before) and finally, I don't see any other alternative that doesn't involve to add/update/move lots of code (and give BC breaks).

@chalasr
Copy link
MemberAuthor

I close this simply because it doesn't solve the problem entirely. Cover it partially would not be a good thing. Hope we soon find a real solution for this blocking issue.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@chalasr@wouterj@jvasseur@stof@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp