1313
1414use ProxyManager \Generator \ClassGenerator ;
1515use ProxyManager \GeneratorStrategy \BaseGeneratorStrategy ;
16+ use ProxyManager \Version ;
1617use Symfony \Component \DependencyInjection \Container ;
1718use Symfony \Component \DependencyInjection \Definition ;
1819use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \DumperInterface ;
@@ -94,11 +95,35 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
9495 */
9596 public function getProxyCode (Definition $ definition )
9697 {
97- return preg_replace (
98+ $ code = $ this ->classGenerator ->generate ($ this ->generateProxyClass ($ definition ));
99+
100+ $ code = preg_replace (
98101 '/(\$this->initializer[0-9a-f]++) && \1->__invoke\(\$this->(valueHolder[0-9a-f]++), (.*?), \1\);/ ' ,
99102 '$1 && ($1->__invoke(\$$2, $3, $1) || 1) && $this->$2 = \$$2; ' ,
100- $ this -> classGenerator -> generate ( $ this -> generateProxyClass ( $ definition ))
103+ $ code
101104 );
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 ();
102127 }
103128
104129 /**
@@ -108,7 +133,7 @@ public function getProxyCode(Definition $definition)
108133 */
109134 private function getProxyClassName (Definition $ definition )
110135 {
111- return preg_replace ('/^.* \\\\/ ' , '' , $ definition ->getClass ()).'_ ' .substr ( hash ( ' sha256 ' , $ definition -> getClass (). $ this -> salt ), - 7 );
136+ return preg_replace ('/^.* \\\\/ ' , '' , $ definition ->getClass ()).'_ ' .$ this -> getIdentifierSuffix ( $ definition );
112137 }
113138
114139 /**
@@ -122,4 +147,12 @@ private function generateProxyClass(Definition $definition)
122147
123148 return $ generatedClass ;
124149 }
150+
151+ /**
152+ * @return string
153+ */
154+ private function getIdentifierSuffix (Definition $ definition )
155+ {
156+ return substr (hash ('sha256 ' , $ definition ->getClass ().$ this ->salt ), -7 );
157+ }
125158}
0 commit comments