-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Retro-fit proxy code to make it deterministic for older proxy manager implementations #26176
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
Retro-fit proxy code to make it deterministic for older proxy manager implementations #26176
Conversation
|
||
if (version_compare(Version::getVersion(), '2.2', '<')) { | ||
$code = preg_replace( | ||
'/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]+/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use a possessive quantifier to avoid backtracking (as done in the previous regex)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had no idea what possessive quantifiers are but I hope I got what it means
'/(\$this->initializer[0-9a-f]++) && \1->__invoke\(\$this->(valueHolder[0-9a-f]++), (.*?), \1\);/', | ||
'$1 && ($1->__invoke(\$$2, $3, $1) || 1) && $this->$2 = \$$2;', | ||
$this->classGenerator->generate($this->generateProxyClass($definition)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could even keep this code here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could but it’s less symmetric
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas is this replacement related to backporting some ProxyManager too, or would be also keep it after dropping support for ProxyManager 2.1 and older ?
If it is meant to stay, I would not try to make it symmetric with the feature backporting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is Symfony-only feature, has been refused in ProxyManager (at least not merged yet), so not part of any versions of it
if (version_compare(Version::getVersion(), '2.2', '<')) { | ||
$code = preg_replace( | ||
'/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]++/', | ||
'${1}'.$this->getSuffix($definition), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$1 for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas no. We need the braces here, because the suffix could start with a number, which would change the placeholder when concatenating the string
); | ||
|
||
if (version_compare(Version::getVersion(), '2.2', '<')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the class doesn't exist in the lowest versions we support, per composer.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and so should be changed to !\class_exists(Version::class) || version_compare(Version::getVersion(), '2.2', '<')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@@ -122,4 +135,16 @@ private function generateProxyClass(Definition $definition) | ||
|
||
return $generatedClass; | ||
} | ||
|
||
/** | ||
* Generate unique suffix for a definition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this docblock, it adds little value IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -122,4 +135,14 @@ private function generateProxyClass(Definition $definition) | ||
|
||
return $generatedClass; | ||
} | ||
|
||
/** | ||
* @param Definition $definition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still suggest to drop the docblock entirely :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least it provides the return value :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so let's keep only the return value if you want... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Ready to be merged from my POV |
Tests do not pass and it looks related to the changes made here. |
@fabpot good point, made the version check somewhat more complicated. |
Tests look good now |
Thank you @lstrojny. |
…oxy manager implementations (lstrojny) This PR was merged into the 3.4 branch. Discussion ---------- Retro-fit proxy code to make it deterministic for older proxy manager implementations Follow up on #25958 (comment) ProxyManager >= 7.2 already implements a deterministic identifier naming strategy which is critical for reproducible builds (#25958). but versions below that don’t. This is what this PR fixes. Here is more context: Ocramius/ProxyManager#411 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 0f16056 Retro-fit proxy code to make it deterministic for older proxy manager implementations
Follow up on #25958 (comment)
ProxyManager >= 7.2 already implements a deterministic identifier naming strategy which is critical for reproducible builds (#25958). but versions below that don’t. This is what this PR fixes. Here is more context: Ocramius/ProxyManager#411