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

[DependencyInjection] fix regression when extending the Container class without a constructor#26427

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

Conversation

@lsmith77
Copy link
Contributor

@lsmith77lsmith77 commentedMar 6, 2018
edited
Loading

QA
Branch?3.4+
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#26397
LicenseMIT
Doc PR-

fix regression introduced inc026ec6#diff-f7b23d463cba27ac5e4cb677f2be7623R985

@xabbuh
Copy link
Member

Can we add a test case that would fail without the fix?

@lsmith77
Copy link
ContributorAuthor

we definitely should .. I am a bit scared to creating a test case since it seems like such an obscure case.


if (null !==$r && (null !==$constructor =$r->getConstructor()) &&0 ===$constructor->getNumberOfRequiredParameters()) {
if (null !==$r
&&$r->getMethod('__construct')->class ===$baseClassWithNamespace
Copy link
Member

Choose a reason for hiding this comment

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

we use$constructor = $r->getConstructor() to get the constructor (and your code here breaks in case there is no constructor). Add this logic after the retrieval of$constructor.

And I would check insteadContainer::class !== $contructor->getDeclaringClass(), to exclude only the Container constructor.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

you mean$constructor->getDeclaringClass() === Container::class ?

@lsmith77lsmith77force-pushed thefix-php-dumper-when-extending-container-without-constructor branch from68483c8 toaaa737aCompareMarch 6, 2018 12:27
@lsmith77lsmith77 changed the titlefix regression when extending the Container class without a constructor[DependencyInjection] fix regression when extending the Container class without a constructorMar 6, 2018
$r =$this->container->getReflectionClass($baseClassWithNamespace,false);

if (null !==$r && (null !==$constructor =$r->getConstructor()) &&0 ===$constructor->getNumberOfRequiredParameters()) {
if (null !==$r && (null !==$constructor =$r->getConstructor()) &&0 ===$constructor->getNumberOfRequiredParameters() &&$constructor->getDeclaringClass() === Container::class) {
Copy link
Member

Choose a reason for hiding this comment

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

should be!==, not=== We want to call the parent constructor when it is a custom one.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

that doesn't fix the issue .. since in the MockContainer the declaring class of the constructor is the Container class, since the MockContainer doesn't define its own constructor

Copy link
Member

Choose a reason for hiding this comment

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

and that's precisely the goal: wedon't want to call the parent constructor for the MockContainer case (otherwise, you would not have a bug currently when it is called).

The Container constructor initializes the ParameterBag, and the dumped container wants to do it in its own way.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

but in that case we don't want to call the parent ..
if I do!== the bug remains .. I have confirmed this, because we still end up calling the parent constructor.

Copy link
Member

Choose a reason for hiding this comment

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

your code is adding theparent::__constructonly when the declaring class of the constructor is Container now.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

ah you are right .. the issue was that it needed to be$constructor->getDeclaringClass()->name and not$constructor->getDeclaringClass() in the comparison.

@lsmith77
Copy link
ContributorAuthor

travis result are also strange:
https://travis-ci.org/symfony/symfony/builds/349789606?utm_source=github_status&utm_medium=notification

don't understand how they can be passing on 5.6 an 7.0 but fail on other versions ..

@stof
Copy link
Member

stof commentedMar 7, 2018

@lsmith77 read the output:Intermediate PHP version 5.6 is skipped for pull requests.

@lsmith77lsmith77force-pushed thefix-php-dumper-when-extending-container-without-constructor branch fromaaa737a to74b976aCompareMarch 8, 2018 07:52
@stof
Copy link
Member

stof commentedMar 8, 2018

as the only thing the Container constructor is doing is initializing the ParameterBag, and this is what we absolutely don't want to be done (as it breaks the lazy-initialization in the dumped container), we could simply reset the property tonull after calling the parent constructor. This way, it would work even when the parent constructor is a custom one (needing to be called) which itself calls the Container one.
The current PR still breaks in this case (as it would determine that the parent constructor needs to be called).

So the code should become

-    $code .= "        parent::__construct();\n\n";+    $code .= "        parent::__construct();\n";+    $code .= "        $this->parameterBag = null;\n\n";

@lsmith77lsmith77force-pushed thefix-php-dumper-when-extending-container-without-constructor branch 2 times, most recently fromae94ed6 to864d935CompareMarch 8, 2018 08:46
@lsmith77
Copy link
ContributorAuthor

I have included your change@stof .. I also added some adjustments to the tests.

@lsmith77lsmith77force-pushed thefix-php-dumper-when-extending-container-without-constructor branch from864d935 to0beb64aCompareMarch 8, 2018 09:22
@lsmith77
Copy link
ContributorAuthor

note the current tests simply do a string comparison on what code we expect to have generated, rather than testing if the generated code behaves the way we expect it to. the adjustments to the tests I did haven't improved things.

@lsmith77
Copy link
ContributorAuthor

@stof ok now?

class NoConstructorContainer
useSymfony\Component\DependencyInjection\Container;

class NoConstructorContainerextends Container
Copy link
Member

Choose a reason for hiding this comment

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

Should we create a new test case to still keep the existing one (a class without a constructor not inheriting one from its base class)?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I was also thinking about that .. and to me the old test just seemed incomplete since that class didn't even implement the interface.

@nicolas-grekas
Copy link
Member

Thank you@lsmith77.

@nicolas-grekasnicolas-grekas merged commit0beb64a intosymfony:3.4Mar 19, 2018
nicolas-grekas added a commit that referenced this pull requestMar 19, 2018
…ntainer class without a constructor (lsmith77)This PR was merged into the 3.4 branch.Discussion----------[DependencyInjection] fix regression when extending the Container class without a constructor| Q             | A| ------------- | ---| Branch?       | 3.4+| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#26397| License       | MIT| Doc PR        | -fix regression introduced inc026ec6#diff-f7b23d463cba27ac5e4cb677f2be7623R985Commits-------0beb64a fix regression when extending the Container class without a constructor
This was referencedApr 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof requested changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@xabbuhxabbuhxabbuh approved these changes

@chalasrchalasrchalasr approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

6 participants

@lsmith77@xabbuh@stof@nicolas-grekas@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp