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

Retro-fit proxy code to make it deterministic for older proxy manager implementations #26176

Merged
merged 1 commit into from
Feb 17, 2018
Merged

Retro-fit proxy code to make it deterministic for older proxy manager implementations #26176

merged 1 commit into from
Feb 17, 2018

Conversation

lstrojny
Copy link
Contributor

@lstrojny lstrojny commented Feb 14, 2018

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 -

@lstrojny lstrojny changed the base branch from master to 3.4 February 14, 2018 15:43
@lstrojny lstrojny mentioned this pull request Feb 14, 2018
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Feb 14, 2018

if (version_compare(Version::getVersion(), '2.2', '<')) {
$code = preg_replace(
'/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]+/',
Copy link
Member

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)

Copy link
Contributor Author

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))
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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.

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 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),
Copy link
Member

Choose a reason for hiding this comment

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

$1 for consistency

Copy link
Member

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', '<')) {
Copy link
Member

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

Copy link
Member

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', '<')

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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 :)

Copy link
Contributor Author

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 :)

Copy link
Member

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... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lstrojny
Copy link
Contributor Author

Ready to be merged from my POV

@fabpot
Copy link
Member

fabpot commented Feb 16, 2018

Tests do not pass and it looks related to the changes made here.

@lstrojny
Copy link
Contributor Author

@fabpot good point, made the version check somewhat more complicated.

@lstrojny
Copy link
Contributor Author

Tests look good now

@nicolas-grekas
Copy link
Member

Thank you @lstrojny.

@nicolas-grekas nicolas-grekas merged commit 0f16056 into symfony:3.4 Feb 17, 2018
nicolas-grekas added a commit that referenced this pull request Feb 17, 2018
…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
This was referenced Mar 1, 2018
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.

5 participants