13
13
14
14
use ProxyManager \Generator \ClassGenerator ;
15
15
use ProxyManager \GeneratorStrategy \BaseGeneratorStrategy ;
16
+ use ProxyManager \Version ;
16
17
use Symfony \Component \DependencyInjection \Container ;
17
18
use Symfony \Component \DependencyInjection \Definition ;
18
19
use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \DumperInterface ;
@@ -94,11 +95,35 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
94
95
*/
95
96
public function getProxyCode (Definition $ definition )
96
97
{
97
- return preg_replace (
98
+ $ code = $ this ->classGenerator ->generate ($ this ->generateProxyClass ($ definition ));
99
+
100
+ $ code = preg_replace (
98
101
'/(\$this->initializer[0-9a-f]++) && \1->__invoke\(\$this->(valueHolder[0-9a-f]++), (.*?), \1\);/ ' ,
99
102
'$1 && ($1->__invoke(\$$2, $3, $1) || 1) && $this->$2 = \$$2; ' ,
100
- $ this -> classGenerator -> generate ( $ this -> generateProxyClass ( $ definition ))
103
+ $ code
101
104
);
105
+
106
+ if (version_compare (self ::getProxyManagerVersion (), '2.2 ' , '< ' )) {
107
+ $ code = preg_replace (
108
+ '/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]++/ ' ,
109
+ '${1} ' .$ this ->getIdentifierSuffix ($ definition ),
110
+ $ code
111
+ );
112
+ }
113
+
114
+ return $ code ;
115
+ }
116
+
117
+ /**
118
+ * @return string
119
+ */
120
+ private static function getProxyManagerVersion ()
121
+ {
122
+ if (!\class_exists (Version::class)) {
123
+ return '0.0.1 ' ;
124
+ }
125
+
126
+ return defined (Version::class.'::VERSION ' ) ? Version::VERSION : Version::getVersion ();
102
127
}
103
128
104
129
/**
@@ -108,7 +133,7 @@ public function getProxyCode(Definition $definition)
108
133
*/
109
134
private function getProxyClassName (Definition $ definition )
110
135
{
111
- return preg_replace ('/^.* \\\\/ ' , '' , $ definition ->getClass ()).'_ ' .substr ( hash ( ' sha256 ' , $ definition -> getClass (). $ this -> salt ), - 7 );
136
+ return preg_replace ('/^.* \\\\/ ' , '' , $ definition ->getClass ()).'_ ' .$ this -> getIdentifierSuffix ( $ definition );
112
137
}
113
138
114
139
/**
@@ -122,4 +147,12 @@ private function generateProxyClass(Definition $definition)
122
147
123
148
return $ generatedClass ;
124
149
}
150
+
151
+ /**
152
+ * @return string
153
+ */
154
+ private function getIdentifierSuffix (Definition $ definition )
155
+ {
156
+ return substr (hash ('sha256 ' , $ definition ->getClass ().$ this ->salt ), -7 );
157
+ }
125
158
}
0 commit comments