From 17c8eb11b91e87f5245c562772d42a726f8a769e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:06:40 +0200 Subject: [PATCH 01/99] Implementing a static constructor to avoid overriding an object's `__construct` --- .../StaticProxyConstructor.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php new file mode 100644 index 000000000..07e334e87 --- /dev/null +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -0,0 +1,96 @@ + + * @license MIT + */ +class StaticProxyConstructor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct('staticProxyConstructor', array(), static::FLAG_PUBLIC | static::FLAG_STATIC); + + $localizedObject = new ParameterGenerator('localizedObject'); + $prefix = new ParameterGenerator('prefixInterceptors'); + $suffix = new ParameterGenerator('suffixInterceptors'); + + $localizedObject->setType($originalClass->getName()); + $prefix->setDefaultValue(array()); + $suffix->setDefaultValue(array()); + $prefix->setType('array'); + $suffix->setType('array'); + + $this->setParameter($localizedObject); + $this->setParameter($prefix); + $this->setParameter($suffix); + + $localizedProperties = array(); + $instanceGenerator = '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' + . "\n\n"; + + foreach ($originalClass->getProperties() as $originalProperty) { + if ((PHP_VERSION_ID < 50400 || (defined('HHVM_VERSION'))) && $originalProperty->isPrivate()) { + // @codeCoverageIgnoreStart + throw UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty($originalProperty); + // @codeCoverageIgnoreEnd + } + + $propertyName = $originalProperty->getName(); + + if ($originalProperty->isPrivate()) { + $localizedProperties[] = "\\Closure::bind(function () use (\$localizedObject, \$instance) {\n " + . '$instance->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";\n" + . '}, $instance, ' . var_export($originalProperty->getDeclaringClass()->getName(), true) + . ')->__invoke();'; + } else { + $localizedProperties[] = '$instance->' . $propertyName + . ' = & $localizedObject->' . $propertyName . ";"; + } + } + + $this->setDocblock( + "@override constructor to setup interceptors\n\n" + . "@param \\" . $originalClass->getName() . " \$localizedObject\n" + . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" + . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" + ); + $this->setBody( + $instanceGenerator + . (empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") + . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" + . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + ); + } +} From f94ebf1b003a6643d2de80533e8bda4e556b79b6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:07:06 +0200 Subject: [PATCH 02/99] Using the static constructor in the `AccessInterceptorScopeLocalizer` codegen --- .../ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php index b6edee35a..04ecdcfc0 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php @@ -30,6 +30,7 @@ use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset; +use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; use ReflectionClass; @@ -81,6 +82,7 @@ function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptor ), array( new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors), + new StaticProxyConstructor($originalClass, $prefixInterceptors, $suffixInterceptors), new SetMethodPrefixInterceptor($prefixInterceptors), new SetMethodSuffixInterceptor($suffixInterceptors), new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors), From ec200ac0ebc2b789023fe93c99be7ea797998703 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:07:35 +0200 Subject: [PATCH 03/99] Implementing new static constructor in the `AccessInterceptorValueHolderMock` --- .../AccessInterceptorValueHolderMock.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php index 8324d978f..2aa4702bc 100644 --- a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php +++ b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php @@ -27,29 +27,31 @@ class AccessInterceptorValueHolderMock { /** - * @var mixed + * @var object */ public $instance; /** - * @var mixed + * @var callable[] */ public $prefixInterceptors; /** - * @var mixed + * @var callable[] */ public $suffixInterceptors; /** - * @param mixed $instance - * @param mixed $prefixInterceptors - * @param mixed $suffixInterceptors + * @param object $instance + * @param callable[] $prefixInterceptors + * @param callable[] $suffixInterceptors */ - public function __construct($instance, $prefixInterceptors, $suffixInterceptors) + public static function staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors) { - $this->instance = $instance; - $this->prefixInterceptors = $prefixInterceptors; - $this->suffixInterceptors = $suffixInterceptors; + $instance = new self(); + + $instance->instance = $instance; + $instance->prefixInterceptors = $prefixInterceptors; + $instance->suffixInterceptors = $suffixInterceptors; } } From 1ffaf9c385e5482d35efaebb576480cd0af2ebae Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:08:16 +0200 Subject: [PATCH 04/99] Variable collision fix (`$instance` was a parameter and a local variable as well) --- .../AccessInterceptorValueHolderMock.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php index 2aa4702bc..65882af6f 100644 --- a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php +++ b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php @@ -48,10 +48,10 @@ class AccessInterceptorValueHolderMock */ public static function staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors) { - $instance = new self(); + $selfInstance = new self(); - $instance->instance = $instance; - $instance->prefixInterceptors = $prefixInterceptors; - $instance->suffixInterceptors = $suffixInterceptors; + $selfInstance->instance = $instance; + $selfInstance->prefixInterceptors = $prefixInterceptors; + $selfInstance->suffixInterceptors = $suffixInterceptors; } } From 59049d1aaddd09e6356e3d672afb5abefcee865f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:08:49 +0200 Subject: [PATCH 05/99] Using the new static proxy constructor where implemented --- .../Factory/AccessInterceptorScopeLocalizerFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php b/src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php index 57d78e7e2..d3d7ca8aa 100644 --- a/src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php +++ b/src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php @@ -46,7 +46,7 @@ public function createProxy($instance, array $prefixInterceptors = array(), arra { $proxyClassName = $this->generateProxy(get_class($instance)); - return new $proxyClassName($instance, $prefixInterceptors, $suffixInterceptors); + return $proxyClassName::staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors); } /** From 28d73f0ce7a73eda92c0e3554752c3fc4c319f55 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:09:37 +0200 Subject: [PATCH 06/99] Avoiding usage of `$this` in static context --- .../MethodGenerator/StaticProxyConstructor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index 07e334e87..d5cbaa1fe 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -89,8 +89,8 @@ public function __construct( $this->setBody( $instanceGenerator . (empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") - . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" - . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" + . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" ); } } From cf0f7cc8c616c9e7c7e51ad3618c73d6592273c0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:19:34 +0200 Subject: [PATCH 07/99] Implementing a static constructor for `AccessInterceptorValueHolder` to avoid overriding `__construct` --- .../StaticProxyConstructor.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php new file mode 100644 index 000000000..6ec38f6b1 --- /dev/null +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -0,0 +1,82 @@ + + * @license MIT + */ +class StaticProxyConstructor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $valueHolder, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct('__construct'); + + $prefix = new ParameterGenerator('prefixInterceptors'); + $suffix = new ParameterGenerator('suffixInterceptors'); + + $prefix->setDefaultValue(array()); + $suffix->setDefaultValue(array()); + $prefix->setType('array'); + $suffix->setType('array'); + + $this->setParameter(new ParameterGenerator('wrappedObject')); + $this->setParameter($prefix); + $this->setParameter($suffix); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $unsetProperties = array(); + $instanceGenerator = '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' + . "\n\n"; + + foreach ($publicProperties as $publicProperty) { + $unsetProperties[] = '$instance->' . $publicProperty->getName(); + } + + $this->setDocblock( + "@override constructor to setup interceptors\n\n" + . "@param \\" . $originalClass->getName() . " \$wrappedObject\n" + . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" + . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" + ); + $this->setBody( + $instanceGenerator, + ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') + . '$instance->' . $valueHolder->getName() . " = \$wrappedObject;\n" + . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" + . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + ); + } +} From bc8b850f772f02d4e032e678f0421438ce41d8a1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:21:58 +0200 Subject: [PATCH 08/99] Fixed static constructor name (not `__construct`!) --- .../MethodGenerator/StaticProxyConstructor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index 6ec38f6b1..0c60132d9 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -41,7 +41,7 @@ public function __construct( PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors ) { - parent::__construct('__construct'); + parent::__construct('staticProxyConstructor'); $prefix = new ParameterGenerator('prefixInterceptors'); $suffix = new ParameterGenerator('suffixInterceptors'); From 217840e04b306ccfe73f55b222dc3ac48130c3ad Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:31:48 +0200 Subject: [PATCH 09/99] Adding the static constructor to generated code --- .../ProxyGenerator/AccessInterceptorValueHolderGenerator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php index 4b055495e..f6c00ead4 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php @@ -31,6 +31,7 @@ use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicIsset; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicSet; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicUnset; +use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\StaticProxyConstructor; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty; use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; @@ -97,6 +98,7 @@ function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptor ), array( new Constructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), + new StaticProxyConstructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), new GetWrappedValueHolderValue($valueHolder), new SetMethodPrefixInterceptor($prefixInterceptors), new SetMethodSuffixInterceptor($suffixInterceptors), From cfd117c33e0262c398f323da7b6a9b73e2e80c65 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:33:23 +0200 Subject: [PATCH 10/99] Static proxy constructor is public and static --- .../MethodGenerator/StaticProxyConstructor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index 0c60132d9..5bccab388 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -41,7 +41,7 @@ public function __construct( PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors ) { - parent::__construct('staticProxyConstructor'); + parent::__construct('staticProxyConstructor', array(), static::FLAG_PUBLIC | static::FLAG_STATIC); $prefix = new ParameterGenerator('prefixInterceptors'); $suffix = new ParameterGenerator('suffixInterceptors'); From 5fef9ff95c526abf26511e5fe69e8ab7d18efa54 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:34:27 +0200 Subject: [PATCH 11/99] Using the new static proxy constructor when available --- .../Factory/AccessInterceptorValueHolderFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php b/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php index d5ef5044a..95adac134 100644 --- a/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php +++ b/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php @@ -46,7 +46,7 @@ public function createProxy($instance, array $prefixInterceptors = array(), arra { $proxyClassName = $this->generateProxy(get_class($instance)); - return new $proxyClassName($instance, $prefixInterceptors, $suffixInterceptors); + return $proxyClassName::staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors); } /** From 199cfd93d20a27142b6fff0673198008ff559442 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:36:38 +0200 Subject: [PATCH 12/99] Built instance should be returned by the static constructor --- .../MethodGenerator/StaticProxyConstructor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index d5cbaa1fe..9d05348b2 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -90,7 +90,8 @@ public function __construct( $instanceGenerator . (empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" - . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n" + . 'return $instance' ); } } From 9d1d2ac8867676e13857f11c025f8ad2fbf8ca8d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:36:57 +0200 Subject: [PATCH 13/99] Built instance should be returned by the static constructor --- .../MethodGenerator/StaticProxyConstructor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index 5bccab388..fd7669e59 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -76,7 +76,8 @@ public function __construct( ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') . '$instance->' . $valueHolder->getName() . " = \$wrappedObject;\n" . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" - . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n" + . 'return $instance' ); } } From b33467c24742836d21003cde5c53bb2ff2942c70 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 16:37:35 +0200 Subject: [PATCH 14/99] Missing semicolon in generated code --- .../MethodGenerator/StaticProxyConstructor.php | 2 +- .../MethodGenerator/StaticProxyConstructor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index 9d05348b2..aca53243f 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -91,7 +91,7 @@ public function __construct( . (empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n" - . 'return $instance' + . 'return $instance;' ); } } diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index fd7669e59..42d5d93ee 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -77,7 +77,7 @@ public function __construct( . '$instance->' . $valueHolder->getName() . " = \$wrappedObject;\n" . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n" - . 'return $instance' + . 'return $instance;' ); } } From a1bf5abff322a50c68fe988e8d64d7f574d441e8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 17:12:59 +0200 Subject: [PATCH 15/99] Mock should return the built instance when using the static constructor --- .../ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php index 65882af6f..648b94fd1 100644 --- a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php +++ b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php @@ -53,5 +53,7 @@ public static function staticProxyConstructor($instance, $prefixInterceptors, $s $selfInstance->instance = $instance; $selfInstance->prefixInterceptors = $prefixInterceptors; $selfInstance->suffixInterceptors = $suffixInterceptors; + + return $selfInstance; } } From ea933034ae1376d0feaf59861d6e71cdd1071293 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 17:13:32 +0200 Subject: [PATCH 16/99] Minor docblock fixes --- .../ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php index 648b94fd1..20ae2d85f 100644 --- a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php +++ b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php @@ -45,6 +45,8 @@ class AccessInterceptorValueHolderMock * @param object $instance * @param callable[] $prefixInterceptors * @param callable[] $suffixInterceptors + * + * @return self */ public static function staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors) { From 3166a178d525d693ede73d479fb0df474326a548 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 17:14:17 +0200 Subject: [PATCH 17/99] Minor docblock fixes (missing `@return`) --- .../MethodGenerator/StaticProxyConstructor.php | 3 ++- .../MethodGenerator/StaticProxyConstructor.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index aca53243f..fb5a25542 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -84,7 +84,8 @@ public function __construct( "@override constructor to setup interceptors\n\n" . "@param \\" . $originalClass->getName() . " \$localizedObject\n" . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" - . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" + . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n" + . "@return self" ); $this->setBody( $instanceGenerator diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index 42d5d93ee..15d28f095 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -69,7 +69,8 @@ public function __construct( "@override constructor to setup interceptors\n\n" . "@param \\" . $originalClass->getName() . " \$wrappedObject\n" . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" - . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" + . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n" + . "@return self" ); $this->setBody( $instanceGenerator, From c3e9145a64194a98c548b11b1853d2159ca16327 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 17:30:57 +0200 Subject: [PATCH 18/99] Typo fix causing massive codegen changes (`,` replaced by concatenation operator `.`) --- .../MethodGenerator/StaticProxyConstructor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index 15d28f095..3c1750450 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -73,8 +73,8 @@ public function __construct( . "@return self" ); $this->setBody( - $instanceGenerator, - ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') + $instanceGenerator + . ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') . '$instance->' . $valueHolder->getName() . " = \$wrappedObject;\n" . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n" From 31af1b2935fa0328661c7374d5ac12c190849920 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 17:40:25 +0200 Subject: [PATCH 19/99] Cannot bind a closure that was built in static context to an object, therefore using an instance method --- .../MethodGenerator/BindProxyProperties.php | 92 +++++++++++++++++++ .../StaticProxyConstructor.php | 4 +- ...cessInterceptorScopeLocalizerGenerator.php | 1 + 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php new file mode 100644 index 000000000..60146d202 --- /dev/null +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php @@ -0,0 +1,92 @@ + + * @license MIT + */ +class BindProxyProperties extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct('bindProxyProperties', array(), static::FLAG_PRIVATE); + + $localizedObject = new ParameterGenerator('localizedObject'); + $prefix = new ParameterGenerator('prefixInterceptors'); + $suffix = new ParameterGenerator('suffixInterceptors'); + + $localizedObject->setType($originalClass->getName()); + $prefix->setDefaultValue(array()); + $suffix->setDefaultValue(array()); + $prefix->setType('array'); + $suffix->setType('array'); + + $this->setParameter($localizedObject); + $this->setParameter($prefix); + $this->setParameter($suffix); + + $localizedProperties = array(); + + foreach ($originalClass->getProperties() as $originalProperty) { + if ((PHP_VERSION_ID < 50400 || (defined('HHVM_VERSION'))) && $originalProperty->isPrivate()) { + // @codeCoverageIgnoreStart + throw UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty($originalProperty); + // @codeCoverageIgnoreEnd + } + + $propertyName = $originalProperty->getName(); + + if ($originalProperty->isPrivate()) { + $localizedProperties[] = "\\Closure::bind(function () use (\$localizedObject) {\n " + . '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";\n" + . '}, $this, ' . var_export($originalProperty->getDeclaringClass()->getName(), true) + . ')->__invoke();'; + } else { + $localizedProperties[] = '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";"; + } + } + + $this->setDocblock( + "@override constructor to setup interceptors\n\n" + . "@param \\" . $originalClass->getName() . " \$localizedObject\n" + . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" + . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" + ); + $this->setBody( + (empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") + . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" + . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + ); + } +} diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index fb5a25542..f99da7559 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -89,9 +89,7 @@ public function __construct( ); $this->setBody( $instanceGenerator - . (empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") - . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" - . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n" + . '$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors);' . "\n\n" . 'return $instance;' ); } diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php index 04ecdcfc0..6d4a01315 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php @@ -22,6 +22,7 @@ use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodPrefixInterceptor; use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors; +use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\BindProxyProperties; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone; From bb5a1527f6ee8c2b653a488c8a6c925180b76497 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 19:39:02 +0200 Subject: [PATCH 20/99] On-the-fly generated classes don't need to re-implement method `#staticProxyConstructor()` --- .../ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php index 20ae2d85f..ddff4a60a 100644 --- a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php +++ b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php @@ -50,7 +50,7 @@ class AccessInterceptorValueHolderMock */ public static function staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors) { - $selfInstance = new self(); + $selfInstance = new static(); // note: static because on-the-fly generated classes in tests extend this one. $selfInstance->instance = $instance; $selfInstance->prefixInterceptors = $prefixInterceptors; From 4605d633759f44eada410dcae3c6f76bdbbc5faa Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 20:01:30 +0200 Subject: [PATCH 21/99] All tests should rely on the new static constructor of the access interceptors --- ...AccessInterceptorScopeLocalizerFunctionalTest.php | 6 +++--- .../AccessInterceptorValueHolderFunctionalTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php index 2e8984de8..478128482 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php @@ -226,7 +226,7 @@ public function testCanWriteToArrayKeysInPublicProperty() $className = get_class($instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicArrayProperty */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $proxy->arrayProperty['foo'] = 'bar'; @@ -267,7 +267,7 @@ public function testWillModifyByRefRetrievedPublicProperties() $className = get_class($instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $variable = & $proxy->property0; $this->assertSame('property0', $variable); @@ -360,7 +360,7 @@ public function getPropertyAccessProxies() return array( array( $instance1, - new $proxyName1($instance1), + $proxyName1::staticProxyConstructor($instance1), 'publicProperty', 'publicPropertyDefault', ), diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php index 7740e2e58..9ae5fefdd 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php @@ -48,7 +48,7 @@ public function testMethodCalls($className, $instance, $method, $params, $expect $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $this->assertSame($instance, $proxy->getWrappedValueHolderValue()); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); @@ -90,7 +90,7 @@ public function testMethodCallsWithSuffixListener($className, $instance, $method $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $listener = $this->getMock('stdClass', array('__invoke')); $listener ->expects($this->once()) @@ -127,7 +127,7 @@ public function testMethodCallsAfterUnSerialization($className, $instance, $meth { $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ - $proxy = unserialize(serialize(new $proxyName($instance))); + $proxy = unserialize(serialize($proxyName::staticProxyConstructor($instance))); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); $this->assertEquals($instance, $proxy->getWrappedValueHolderValue()); @@ -141,7 +141,7 @@ public function testMethodCallsAfterCloning($className, $instance, $method, $par $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $cloned = clone $proxy; $this->assertNotSame($proxy->getWrappedValueHolderValue(), $cloned->getWrappedValueHolderValue()); @@ -345,13 +345,13 @@ public function getPropertyAccessProxies() return array( array( $instance1, - new $proxyName1($instance1), + $proxyName1::staticProxyConstructor($instance1), 'publicProperty', 'publicPropertyDefault', ), array( $instance2, - unserialize(serialize(new $proxyName2($instance2))), + unserialize(serialize($proxyName2::staticProxyConstructor($instance2))), 'publicProperty', 'publicPropertyDefault', ), From f06f1bf05420a5d88ea855adafd33a2bd2b33d3c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 20:02:00 +0200 Subject: [PATCH 22/99] Removing usage of the `__construct` override --- .../ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php | 1 + .../ProxyGenerator/AccessInterceptorValueHolderGenerator.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php index 6d4a01315..bc95a254b 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php @@ -84,6 +84,7 @@ function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptor array( new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors), new StaticProxyConstructor($originalClass, $prefixInterceptors, $suffixInterceptors), + new BindProxyProperties($originalClass, $prefixInterceptors, $suffixInterceptors), new SetMethodPrefixInterceptor($prefixInterceptors), new SetMethodSuffixInterceptor($suffixInterceptors), new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors), diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php index f6c00ead4..62f10503b 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php @@ -97,7 +97,6 @@ function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptor ProxiedMethodsFilter::getProxiedMethods($originalClass) ), array( - new Constructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), new StaticProxyConstructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), new GetWrappedValueHolderValue($valueHolder), new SetMethodPrefixInterceptor($prefixInterceptors), From e93a368acff3da1a3582fbd451e3e1c344495c09 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 20:05:53 +0200 Subject: [PATCH 23/99] Static constructors do not override any methods --- .../MethodGenerator/StaticProxyConstructor.php | 2 +- .../MethodGenerator/StaticProxyConstructor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index f99da7559..c692bb762 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -81,7 +81,7 @@ public function __construct( } $this->setDocblock( - "@override constructor to setup interceptors\n\n" + "Constructor to setup interceptors\n\n" . "@param \\" . $originalClass->getName() . " \$localizedObject\n" . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n" diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index 3c1750450..fcab09102 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -66,7 +66,7 @@ public function __construct( } $this->setDocblock( - "@override constructor to setup interceptors\n\n" + "Constructor to setup interceptors\n\n" . "@param \\" . $originalClass->getName() . " \$wrappedObject\n" . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n" From 016863f51cb93a303968c62b6999e1ce19d80841 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 20:37:41 +0200 Subject: [PATCH 24/99] Implementing static proxy constructor for lazy loading objects --- .../StaticProxyConstructor.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php diff --git a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php new file mode 100644 index 000000000..acc7a0341 --- /dev/null +++ b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php @@ -0,0 +1,60 @@ + + * @license MIT + */ +class StaticProxyConstructor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty) + { + parent::__construct('staticProxyConstructor'); + + $this->setParameter(new ParameterGenerator('initializer')); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $unsetProperties = array(); + + foreach ($publicProperties as $publicProperty) { + $unsetProperties[] = '$instance->' . $publicProperty->getName(); + } + + $this->setDocblock("Constructor for lazy initialization\n\n@param \\Closure|null \$initializer"); + $this->setBody( + '$instance = (new \ReflectionClass())->newInstanceWithoutConstructor();' . "\n\n" + . ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') + . '$instance->' . $initializerProperty->getName() . ' = $initializer;' . "\n\n" + . 'return $instance;' + ); + } +} From d08695dbe66919750f954e5d8b831611edfe25f5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 20:38:16 +0200 Subject: [PATCH 25/99] Using the newly implemented `StaticProxyConstructor` in the lazy loading implementations --- src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php index 1f9d88e5a..b13b50c4f 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php @@ -21,6 +21,7 @@ use ProxyManager\Generator\Util\ClassGeneratorUtils; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor; +use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\StaticProxyConstructor; use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer; use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer; use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy; @@ -97,6 +98,7 @@ function (ReflectionMethod $method) use ($initializer, $init) { array( $init, new Constructor($originalClass, $initializer), + new StaticProxyConstructor($originalClass, $initializer), new MagicGet($originalClass, $initializer, $init, $publicProperties), new MagicSet($originalClass, $initializer, $init, $publicProperties), new MagicIsset($originalClass, $initializer, $init, $publicProperties), From ee046bc120bae1728466433b929d8a3d2cc43aac Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 20:38:56 +0200 Subject: [PATCH 26/99] Using the newly implemented `StaticProxyConstructor` in the lazy loading value holder implementations --- .../ProxyGenerator/LazyLoadingValueHolderGenerator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php index 0a9ab363a..3fb3f1385 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php @@ -18,6 +18,10 @@ namespace ProxyManager\ProxyGenerator; +use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\StaticProxyConstructor; +use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; +use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; +use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue; use ProxyManager\Generator\Util\ClassGeneratorUtils; use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; @@ -92,6 +96,7 @@ function (ReflectionMethod $method) use ($initializer, $valueHolder) { ), array( new Constructor($originalClass, $initializer), + new StaticProxyConstructor($originalClass, $initializer), new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties), From 90f94d79d743d746d1185fc99b538edb6f352ed9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:01:00 +0200 Subject: [PATCH 27/99] `staticProxyConstructor` must be static --- .../LazyLoading/MethodGenerator/StaticProxyConstructor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php index acc7a0341..0529c96c8 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php @@ -37,7 +37,7 @@ class StaticProxyConstructor extends MethodGenerator */ public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty) { - parent::__construct('staticProxyConstructor'); + parent::__construct('staticProxyConstructor', array(), static::FLAG_PUBLIC | static::FLAG_STATIC); $this->setParameter(new ParameterGenerator('initializer')); From ee763d3016d9f590b9a8cf95893fe6b25f51a349 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:04:28 +0200 Subject: [PATCH 28/99] Implementing `staticProxyConstructor` for null objects --- .../StaticProxyConstructor.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php diff --git a/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php new file mode 100644 index 000000000..66e084d1f --- /dev/null +++ b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php @@ -0,0 +1,57 @@ + + * @license MIT + */ +class StaticProxyConstructor extends MethodGenerator +{ + /** + * Constructor + * + * @param ReflectionClass $originalClass Reflection of the class to proxy + */ + public function __construct(ReflectionClass $originalClass) + { + parent::__construct('staticProxyConstructor', array(), static::FLAG_PUBLIC | static::FLAG_STATIC); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $nullableProperties = array(); + + foreach ($publicProperties as $publicProperty) { + $nullableProperties[] = '$body->' . $publicProperty->getName() . ' = null;'; + } + + $this->setDocblock("Constructor for null object initialization"); + $this->setBody( + '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" + . ($nullableProperties ? implode("\n", $nullableProperties) . "\n\n" : '') + . 'return $instance;' + ); + } +} From f353cca28b8fbcac09f0e16f34ee94df357fc775 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:07:11 +0200 Subject: [PATCH 29/99] Variable name mismatch fix --- .../NullObject/MethodGenerator/StaticProxyConstructor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php index 66e084d1f..18b032447 100644 --- a/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php @@ -44,7 +44,7 @@ public function __construct(ReflectionClass $originalClass) $nullableProperties = array(); foreach ($publicProperties as $publicProperty) { - $nullableProperties[] = '$body->' . $publicProperty->getName() . ' = null;'; + $nullableProperties[] = '$instance->' . $publicProperty->getName() . ' = null;'; } $this->setDocblock("Constructor for null object initialization"); From 93160face9ef5b764fcc1b135d925b97258a042d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:09:59 +0200 Subject: [PATCH 30/99] Proxy test should only interact with non-static methods --- .../ProxyGenerator/NullObjectGeneratorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php b/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php index 11a6cbdd5..f09ccd1c8 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php @@ -24,6 +24,7 @@ use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; use ProxyManager\ProxyGenerator\NullObjectGenerator; use ReflectionClass; +use ReflectionMethod; use ReflectionProperty; /** @@ -71,9 +72,8 @@ public function testGeneratesValidCode($className) $this->assertNull($proxyGenerated->$property); } - /** @var \ReflectionMethod $method */ - foreach ($generatedReflection->getMethods(ReflectionProperty::IS_PUBLIC) as $method) { - if ($method->getNumberOfParameters() == 0) { + foreach ($generatedReflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { + if (! ($method->getNumberOfParameters() || $method->isStatic())) { $this->assertNull(call_user_func(array($proxyGenerated, $method->getName()))); } } From b57ad039fd4481756ea186f4ebd89d5dc1754689 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:10:48 +0200 Subject: [PATCH 31/99] Using newly implemented static proxy constructor in codegen of null objects --- src/ProxyManager/ProxyGenerator/NullObjectGenerator.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php b/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php index db177ac4f..242b2749b 100644 --- a/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php +++ b/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php @@ -21,6 +21,7 @@ use ProxyManager\Generator\Util\ClassGeneratorUtils; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor; +use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor; use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; use ReflectionClass; @@ -61,5 +62,10 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe } ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, new Constructor($originalClass)); + ClassGeneratorUtils::addMethodIfNotFinal( + $originalClass, + $classGenerator, + new StaticProxyConstructor($originalClass) + ); } } From 610ade02d7a847d8b322006d6827aabe2092951c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:14:20 +0200 Subject: [PATCH 32/99] Implementing static constructor for remote objects --- .../StaticProxyConstructor.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php diff --git a/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php new file mode 100644 index 000000000..db2605c23 --- /dev/null +++ b/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php @@ -0,0 +1,69 @@ + + * @author Marco Pivetta + * @license MIT + */ +class StaticProxyConstructor extends MethodGenerator +{ + /** + * Constructor + * + * @param ReflectionClass $originalClass Reflection of the class to proxy + * @param PropertyGenerator $adapter Adapter property + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapter) + { + parent::__construct( + 'staticProxyConstructor', + array(), + MethodGenerator::FLAG_PUBLIC | MethodGenerator::FLAG_STATIC + ); + + $adapterName = $adapter->getName(); + + $this->setParameter(new ParameterGenerator($adapterName, 'ProxyManager\Factory\RemoteObject\AdapterInterface')); + + $this->setDocblock( + 'Constructor for remote object control\n\n' + . '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \$adapter' + ); + + $body = '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" + . '$instance->' . $adapterName . ' = $' . $adapterName . ';'; + + foreach ($originalClass->getProperties() as $property) { + if ($property->isPublic() && ! $property->isStatic()) { + $body .= "\nunset(\$instance->" . $property->getName() . ');'; + } + } + + $this->setBody($body); + } +} From ae54f413902128ae44b97dc400272f9201687fe6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:14:55 +0200 Subject: [PATCH 33/99] Using newly introduced static proxy constructor for remote objects in codegen --- src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php index 8a4a4e97b..06965250c 100644 --- a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php +++ b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php @@ -18,6 +18,9 @@ namespace ProxyManager\ProxyGenerator; +use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod; +use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor; +use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty; use ProxyManager\Generator\Util\ClassGeneratorUtils; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor; @@ -26,7 +29,6 @@ use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod; -use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; use ReflectionClass; use ReflectionMethod; @@ -82,6 +84,7 @@ function (ReflectionMethod $method) use ($adapter, $originalClass) { ), array( new Constructor($originalClass, $adapter), + new StaticProxyConstructor($originalClass, $adapter), new MagicGet($originalClass, $adapter), new MagicSet($originalClass, $adapter), new MagicIsset($originalClass, $adapter), From 5262aa063f5686f99605a13dddc88a5d80e4014c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:30:26 +0200 Subject: [PATCH 34/99] Test stubs should implement the `staticProxyConstructor` --- .../ProxyManagerTestAsset/LazyLoadingMock.php | 14 +++++-- .../ProxyManagerTestAsset/NullObjectMock.php | 7 ++++ .../RemoteProxy/RemoteObjectMock.php | 38 +++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tests/ProxyManagerTestAsset/RemoteProxy/RemoteObjectMock.php diff --git a/tests/ProxyManagerTestAsset/LazyLoadingMock.php b/tests/ProxyManagerTestAsset/LazyLoadingMock.php index b199f8fa9..1c1228005 100644 --- a/tests/ProxyManagerTestAsset/LazyLoadingMock.php +++ b/tests/ProxyManagerTestAsset/LazyLoadingMock.php @@ -27,15 +27,21 @@ class LazyLoadingMock { /** - * @var mixed + * @var callable */ public $initializer; /** - * @param mixed $initializer + * @param callable $initializer + * + * @return static */ - public function __construct($initializer) + public static function staticProxyConstructor($initializer) { - $this->initializer = $initializer; + $instance = new static(); + + $instance->initializer = $initializer; + + return $instance; } } diff --git a/tests/ProxyManagerTestAsset/NullObjectMock.php b/tests/ProxyManagerTestAsset/NullObjectMock.php index b747f3b39..2d8e980de 100644 --- a/tests/ProxyManagerTestAsset/NullObjectMock.php +++ b/tests/ProxyManagerTestAsset/NullObjectMock.php @@ -26,4 +26,11 @@ */ class NullObjectMock { + /** + * @return static + */ + public static function staticProxyConstructor() + { + return new static(); + } } diff --git a/tests/ProxyManagerTestAsset/RemoteProxy/RemoteObjectMock.php b/tests/ProxyManagerTestAsset/RemoteProxy/RemoteObjectMock.php new file mode 100644 index 000000000..ebb29946c --- /dev/null +++ b/tests/ProxyManagerTestAsset/RemoteProxy/RemoteObjectMock.php @@ -0,0 +1,38 @@ + + * @license MIT + */ +class RemoteObjectMock implements RemoteObjectInterface +{ + /** + * @return static + */ + public static function staticProxyConstructor() + { + return new static(); + } +} From d9b77094af1a2d82519f511f92a15b4d97b62edc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:30:56 +0200 Subject: [PATCH 35/99] Fixed broken assertion (was using `stdClass` instead of a proxy implementation) --- tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php b/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php index a7385e0fa..6644d9757 100644 --- a/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php +++ b/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php @@ -96,14 +96,14 @@ public function testWillSkipAutoGeneration() ->expects($this->once()) ->method('getProxyClassName') ->with('ProxyManagerTestAsset\\BaseInterface') - ->will($this->returnValue('StdClass')); + ->will($this->returnValue('ProxyManagerTestAsset\\RemoteProxy\\RemoteObjectMock')); $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface'); $factory = new RemoteObjectFactory($adapter, $this->config); /* @var $proxy \stdClass */ $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter); - $this->assertInstanceOf('stdClass', $proxy); + $this->assertInstanceOf('ProxyManagerTestAsset\\RemoteProxy\\RemoteObjectMock', $proxy); } /** From 894b7520949d7ad41931b9e5d097a7d289204250 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:34:25 +0200 Subject: [PATCH 36/99] Added missing `get_class()` call, which was causing a reflection exception to spawn --- .../LazyLoading/MethodGenerator/StaticProxyConstructor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php index 0529c96c8..15fe018c4 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php @@ -51,7 +51,7 @@ public function __construct(ReflectionClass $originalClass, PropertyGenerator $i $this->setDocblock("Constructor for lazy initialization\n\n@param \\Closure|null \$initializer"); $this->setBody( - '$instance = (new \ReflectionClass())->newInstanceWithoutConstructor();' . "\n\n" + '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') . '$instance->' . $initializerProperty->getName() . ' = $initializer;' . "\n\n" . 'return $instance;' From f14d2bbb1e9e5a90d821f06b4b19079d8723b344 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:37:04 +0200 Subject: [PATCH 37/99] Forgot a return statement in a static proxy constructor --- .../RemoteObject/MethodGenerator/StaticProxyConstructor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php index db2605c23..0b7369274 100644 --- a/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php @@ -64,6 +64,6 @@ public function __construct(ReflectionClass $originalClass, PropertyGenerator $a } } - $this->setBody($body); + $this->setBody($body . "\n\nreturn \$instance;"); } } From a20a06be874735b94217eb647bff39f2262f5c00 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:37:41 +0200 Subject: [PATCH 38/99] Tests should also use the `staticProxyConstructor` where applicable --- tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php b/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php index 6644d9757..046bde584 100644 --- a/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php +++ b/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php @@ -145,7 +145,9 @@ function (ClassGenerator $targetClass) use ($proxyClassName) { function () use ($proxyClassName) { eval( 'class ' . $proxyClassName - . ' extends stdClass {}' + . ' extends stdClass {' + . 'public static function staticProxyConstructor() { return new static(); }' + . '}' ); } ) From de9bbdca3d8fda492922948bffa2743b9641667d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:38:02 +0200 Subject: [PATCH 39/99] Minor cleanups in the remote object factory code --- src/ProxyManager/Factory/RemoteObjectFactory.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ProxyManager/Factory/RemoteObjectFactory.php b/src/ProxyManager/Factory/RemoteObjectFactory.php index 52778d3ce..256debed2 100644 --- a/src/ProxyManager/Factory/RemoteObjectFactory.php +++ b/src/ProxyManager/Factory/RemoteObjectFactory.php @@ -60,10 +60,11 @@ public function __construct(AdapterInterface $adapter, Configuration $configurat */ public function createProxy($instanceOrClassName) { - $className = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName; - $proxyClassName = $this->generateProxy($className); + $proxyClassName = $this->generateProxy( + is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName + ); - return new $proxyClassName($this->adapter); + return $proxyClassName::staticProxyConstructor($this->adapter); } /** From f46e45f66269c35e55efa8ddd0d3121dd22c1be0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:38:25 +0200 Subject: [PATCH 40/99] Using the `staticProxyConstructor` in factories where applicable --- src/ProxyManager/Factory/AbstractLazyFactory.php | 2 +- src/ProxyManager/Factory/NullObjectFactory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProxyManager/Factory/AbstractLazyFactory.php b/src/ProxyManager/Factory/AbstractLazyFactory.php index 690bfa15c..d5067ade6 100644 --- a/src/ProxyManager/Factory/AbstractLazyFactory.php +++ b/src/ProxyManager/Factory/AbstractLazyFactory.php @@ -41,6 +41,6 @@ public function createProxy($className, Closure $initializer) { $proxyClassName = $this->generateProxy($className); - return new $proxyClassName($initializer); + return $proxyClassName::staticProxyConstructor($initializer); } } diff --git a/src/ProxyManager/Factory/NullObjectFactory.php b/src/ProxyManager/Factory/NullObjectFactory.php index 9c605cbaf..0fb43159c 100644 --- a/src/ProxyManager/Factory/NullObjectFactory.php +++ b/src/ProxyManager/Factory/NullObjectFactory.php @@ -43,7 +43,7 @@ public function createProxy($instanceOrClassName) $className = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName; $proxyClassName = $this->generateProxy($className); - return new $proxyClassName(); + return $proxyClassName::staticProxyConstructor(); } /** From 0333fb4eb690e875811e4955eb792fef1944d45a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:43:12 +0200 Subject: [PATCH 41/99] Using the `staticProxyConstructor` in the test suite where applicable --- ...nterceptorScopeLocalizerFunctionalTest.php | 10 ++++----- ...ssInterceptorValueHolderFunctionalTest.php | 6 ++--- .../LazyLoadingGhostFunctionalTest.php | 22 +++++++++---------- .../LazyLoadingGhostPerformanceTest.php | 6 ++--- .../LazyLoadingValueHolderFunctionalTest.php | 12 +++++----- .../LazyLoadingValueHolderPerformanceTest.php | 6 ++--- .../Functional/NullObjectFunctionalTest.php | 6 ++--- .../Functional/RemoteObjectFunctionalTest.php | 6 ++--- .../NullObjectGeneratorTest.php | 2 +- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php index 478128482..c59fb30e9 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php @@ -63,7 +63,7 @@ public function testMethodCalls($className, $instance, $method, $params, $expect $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $this->assertProxySynchronized($instance, $proxy); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); @@ -106,7 +106,7 @@ public function testMethodCallsWithSuffixListener($className, $instance, $method $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $listener = $this->getMock('stdClass', array('__invoke')); $listener ->expects($this->once()) @@ -144,7 +144,7 @@ public function testMethodCallsAfterUnSerialization($className, $instance, $meth { $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ - $proxy = unserialize(serialize(new $proxyName($instance))); + $proxy = unserialize(serialize($proxyName::staticProxyConstructor($instance))); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); $this->assertProxySynchronized($instance, $proxy); @@ -158,7 +158,7 @@ public function testMethodCallsAfterCloning($className, $instance, $method, $par $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $cloned = clone $proxy; $this->assertProxySynchronized($instance, $proxy); @@ -247,7 +247,7 @@ public function testWillNotModifyRetrievedPublicProperties() $className = get_class($instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $variable = $proxy->property0; $this->assertSame('property0', $variable); diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php index 9ae5fefdd..eca9a55c1 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php @@ -207,7 +207,7 @@ public function testCanWriteToArrayKeysInPublicProperty() $className = get_class($instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicArrayProperty */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $proxy->arrayProperty['foo'] = 'bar'; @@ -227,7 +227,7 @@ public function testWillNotModifyRetrievedPublicProperties() $className = get_class($instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $variable = $proxy->property0; $this->assertSame('property0', $variable); @@ -246,7 +246,7 @@ public function testWillModifyByRefRetrievedPublicProperties() $className = get_class($instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($instance); + $proxy = $proxyName::staticProxyConstructor($instance); $variable = & $proxy->property0; $this->assertSame('property0', $variable); diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php index a6690f100..3118350b8 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php @@ -53,7 +53,7 @@ public function testMethodCalls($className, $instance, $method, $params, $expect $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ - $proxy = new $proxyName($this->createInitializer($className, $instance)); + $proxy = $proxyName::staticProxyConstructor($this->createInitializer($className, $instance)); $this->assertFalse($proxy->isProxyInitialized()); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); @@ -68,7 +68,7 @@ public function testMethodCallsAfterUnSerialization($className, $instance, $meth $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ - $proxy = unserialize(serialize(new $proxyName($this->createInitializer($className, $instance)))); + $proxy = unserialize(serialize($proxyName::staticProxyConstructor($this->createInitializer($className, $instance)))); $this->assertTrue($proxy->isProxyInitialized()); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); @@ -82,7 +82,7 @@ public function testMethodCallsAfterCloning($className, $instance, $method, $par $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ - $proxy = new $proxyName($this->createInitializer($className, $instance)); + $proxy = $proxyName::staticProxyConstructor($this->createInitializer($className, $instance)); $cloned = clone $proxy; $this->assertTrue($cloned->isProxyInitialized()); @@ -157,7 +157,7 @@ public function testCanWriteToArrayKeysInPublicProperty() $initializer = $this->createInitializer($className, $instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicArrayProperty */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $proxy->arrayProperty['foo'] = 'bar'; @@ -178,7 +178,7 @@ public function testWillNotModifyRetrievedPublicProperties() $initializer = $this->createInitializer($className, $instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $variable = $proxy->property0; $this->assertSame('property0', $variable); @@ -198,7 +198,7 @@ public function testWillModifyByRefRetrievedPublicProperties() $initializer = $this->createInitializer($className, $instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $variable = & $proxy->property0; $this->assertSame('property0', $variable); @@ -215,7 +215,7 @@ public function testKeepsInitializerWhenNotOverwitten() $initializer = function () { }; /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $proxy->initializeProxy(); @@ -234,7 +234,7 @@ public function testKeepsInitializedPublicProperties() $proxy->publicProperty = 'newValue'; }; /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $proxy->initializeProxy(); $this->assertSame('newValue', $proxy->publicProperty); @@ -254,7 +254,7 @@ public function testPublicPropertyDefaultWillBePreserved() $instance = new ClassWithPublicProperties(); $proxyName = $this->generateProxy(get_class($instance)); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName(function () { + $proxy = $proxyName::staticProxyConstructor(function () { }); $this->assertSame('property0', $proxy->property0); @@ -268,7 +268,7 @@ public function testProtectedPropertyDefaultWillBePreserved() $instance = new ClassWithProtectedProperties(); $proxyName = $this->generateProxy(get_class($instance)); /* @var $proxy ClassWithProtectedProperties */ - $proxy = new $proxyName(function () { + $proxy = $proxyName::staticProxyConstructor(function () { }); // Check protected property via reflection @@ -286,7 +286,7 @@ public function testPrivatePropertyDefaultWillBePreserved() $instance = new ClassWithPrivateProperties(); $proxyName = $this->generateProxy(get_class($instance)); /* @var $proxy ClassWithPrivateProperties */ - $proxy = new $proxyName(function () { + $proxy = $proxyName::staticProxyConstructor(function () { }); // Check protected property via reflection diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php index 21b9f49ca..1dafff9c0 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php @@ -58,7 +58,7 @@ public function testProxyInstantiationPerformance( $instances = array(); /* @var $proxies \ProxyManager\Proxy\GhostObjectInterface[] */ $proxies = array(); - $realInstance = new $className(); + $realInstance = $className::staticProxyConstructor(); $initializer = function ( GhostObjectInterface $proxy, $method, @@ -80,7 +80,7 @@ public function testProxyInstantiationPerformance( $this->startCapturing(); for ($i = 0; $i < $iterations; $i += 1) { - $instances[] = new $className(); + $instances[] = $className::staticProxyConstructor(); } $baseProfile = $this->endCapturing( @@ -89,7 +89,7 @@ public function testProxyInstantiationPerformance( $this->startCapturing(); for ($i = 0; $i < $iterations; $i += 1) { - $proxies[] = new $proxyName($initializer); + $proxies[] = $proxyName::staticProxyConstructor($initializer); } $proxyProfile = $this->endCapturing( diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php index a638760b1..a5305b736 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php @@ -50,7 +50,7 @@ public function testMethodCalls($className, $instance, $method, $params, $expect $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ - $proxy = new $proxyName($this->createInitializer($className, $instance)); + $proxy = $proxyName::staticProxyConstructor($this->createInitializer($className, $instance)); $this->assertFalse($proxy->isProxyInitialized()); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); @@ -66,7 +66,7 @@ public function testMethodCallsAfterUnSerialization($className, $instance, $meth $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ - $proxy = unserialize(serialize(new $proxyName($this->createInitializer($className, $instance)))); + $proxy = unserialize(serialize($proxyName::staticProxyConstructor($this->createInitializer($className, $instance)))); $this->assertTrue($proxy->isProxyInitialized()); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); @@ -81,7 +81,7 @@ public function testMethodCallsAfterCloning($className, $instance, $method, $par $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ - $proxy = new $proxyName($this->createInitializer($className, $instance)); + $proxy = $proxyName::staticProxyConstructor($this->createInitializer($className, $instance)); $cloned = clone $proxy; $this->assertTrue($cloned->isProxyInitialized()); @@ -163,7 +163,7 @@ public function testCanWriteToArrayKeysInPublicProperty() $initializer = $this->createInitializer($className, $instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicArrayProperty */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $proxy->arrayProperty['foo'] = 'bar'; @@ -184,7 +184,7 @@ public function testWillNotModifyRetrievedPublicProperties() $initializer = $this->createInitializer($className, $instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $variable = $proxy->property0; $this->assertSame('property0', $variable); @@ -204,7 +204,7 @@ public function testWillModifyByRefRetrievedPublicProperties() $initializer = $this->createInitializer($className, $instance); $proxyName = $this->generateProxy($className); /* @var $proxy ClassWithPublicProperties */ - $proxy = new $proxyName($initializer); + $proxy = $proxyName::staticProxyConstructor($initializer); $variable = & $proxy->property0; $this->assertSame('property0', $variable); diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php index 1279526ae..4f6d30d7f 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php @@ -61,7 +61,7 @@ public function testProxyInstantiationPerformance($className, array $methods, ar & $initializer ) use ($className) { $initializer = null; - $valueHolder = new $className(); + $valueHolder = $className::staticProxyConstructor(); return true; }; @@ -69,7 +69,7 @@ public function testProxyInstantiationPerformance($className, array $methods, ar $this->startCapturing(); for ($i = 0; $i < $iterations; $i += 1) { - $instances[] = new $className(); + $instances[] = $className::staticProxyConstructor(); } $baseProfile = $this->endCapturing( @@ -78,7 +78,7 @@ public function testProxyInstantiationPerformance($className, array $methods, ar $this->startCapturing(); for ($i = 0; $i < $iterations; $i += 1) { - $proxies[] = new $proxyName($initializer); + $proxies[] = $proxyName::staticProxyConstructor($initializer); } $proxyProfile = $this->endCapturing( diff --git a/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php b/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php index adfeae551..1820be8e5 100644 --- a/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php @@ -46,7 +46,7 @@ public function testMethodCalls($className, $instance, $method, $params, $expect $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ - $proxy = new $proxyName(); + $proxy = $proxyName::staticProxyConstructor(); $this->assertSame(null, call_user_func_array(array($proxy, $method), $params)); } @@ -58,7 +58,7 @@ public function testMethodCallsAfterUnSerialization($className, $instance, $meth { $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ - $proxy = unserialize(serialize(new $proxyName())); + $proxy = unserialize(serialize($proxyName::staticProxyConstructor())); $this->assertSame(null, call_user_func_array(array($proxy, $method), $params)); } @@ -71,7 +71,7 @@ public function testMethodCallsAfterCloning($className, $instance, $method, $par $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ - $proxy = new $proxyName(); + $proxy = $proxyName::staticProxyConstructor(); $cloned = clone $proxy; $this->assertSame(null, call_user_func_array(array($cloned, $method), $params)); diff --git a/tests/ProxyManagerTest/Functional/RemoteObjectFunctionalTest.php b/tests/ProxyManagerTest/Functional/RemoteObjectFunctionalTest.php index b5d9c956b..7f6464c30 100644 --- a/tests/ProxyManagerTest/Functional/RemoteObjectFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/RemoteObjectFunctionalTest.php @@ -110,7 +110,7 @@ public function testXmlRpcMethodCalls($instanceOrClassname, $method, $params, $e $proxyName = $this->generateProxy($instanceOrClassname); /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */ - $proxy = new $proxyName($this->getXmlRpcAdapter($expectedValue, $method, $params)); + $proxy = $proxyName::staticProxyConstructor($this->getXmlRpcAdapter($expectedValue, $method, $params)); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); } @@ -123,7 +123,7 @@ public function testJsonRpcMethodCalls($instanceOrClassname, $method, $params, $ $proxyName = $this->generateProxy($instanceOrClassname); /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */ - $proxy = new $proxyName($this->getJsonRpcAdapter($expectedValue, $method, $params)); + $proxy = $proxyName::staticProxyConstructor($this->getJsonRpcAdapter($expectedValue, $method, $params)); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); } @@ -136,7 +136,7 @@ public function testJsonRpcPropertyReadAccess($instanceOrClassname, $publicPrope $proxyName = $this->generateProxy($instanceOrClassname); /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */ - $proxy = new $proxyName( + $proxy = $proxyName::staticProxyConstructor( $this->getJsonRpcAdapter($propertyValue, '__get', array($publicProperty)) ); diff --git a/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php b/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php index f09ccd1c8..973aed1ab 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php @@ -66,7 +66,7 @@ public function testGeneratesValidCode($className) $this->assertTrue($generatedReflection->implementsInterface($interface)); } - $proxyGenerated = new $generatedClassName(); + $proxyGenerated = $generatedClassName::staticProxyConstructor(); foreach ($generatedReflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { $this->assertNull($proxyGenerated->$property); From 9b61125fa57c81ae9626c8a09d9ed69d7640e07a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:49:31 +0200 Subject: [PATCH 42/99] Removing last leftovers of direct proxy constructor calls --- .../LazyLoadingValueHolderFunctionalTest.php | 10 ++++++---- .../Functional/NullObjectFunctionalTest.php | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php index a5305b736..3efb05ae9 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php @@ -369,15 +369,17 @@ public function getPropertyAccessProxies() return array( array( $instance1, - new $proxyName1($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance1)), + $proxyName1::staticProxyConstructor( + $this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance1) + ), 'publicProperty', 'publicPropertyDefault', ), array( $instance2, - unserialize( - serialize(new $proxyName2($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance2))) - ), + unserialize(serialize($proxyName2::staticProxyConstructor( + $this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance2) + ))), 'publicProperty', 'publicPropertyDefault', ), diff --git a/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php b/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php index 1820be8e5..edea5bbd4 100644 --- a/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php @@ -208,13 +208,13 @@ public function getPropertyAccessProxies() return array( array( $instance1, - new $proxyName1($instance1), + $proxyName1::staticProxyConstructor($instance1), 'publicProperty', 'publicPropertyDefault', ), array( $instance2, - unserialize(serialize(new $proxyName2($instance2))), + unserialize(serialize($proxyName2::staticProxyConstructor($instance2))), 'publicProperty', 'publicPropertyDefault', ), From 70d2b47f36e01d73912481272a321ac5987806ac Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 27 Sep 2014 21:51:27 +0200 Subject: [PATCH 43/99] Removing old constructor override --- src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php | 1 - .../ProxyGenerator/LazyLoadingValueHolderGenerator.php | 1 - src/ProxyManager/ProxyGenerator/NullObjectGenerator.php | 1 - src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php | 2 -- 4 files changed, 5 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php index b13b50c4f..1002b0513 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php @@ -97,7 +97,6 @@ function (ReflectionMethod $method) use ($initializer, $init) { ), array( $init, - new Constructor($originalClass, $initializer), new StaticProxyConstructor($originalClass, $initializer), new MagicGet($originalClass, $initializer, $init, $publicProperties), new MagicSet($originalClass, $initializer, $init, $publicProperties), diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php index 3fb3f1385..ac36979a8 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php @@ -95,7 +95,6 @@ function (ReflectionMethod $method) use ($initializer, $valueHolder) { ProxiedMethodsFilter::getProxiedMethods($originalClass) ), array( - new Constructor($originalClass, $initializer), new StaticProxyConstructor($originalClass, $initializer), new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties), diff --git a/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php b/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php index 242b2749b..3673fe648 100644 --- a/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php +++ b/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php @@ -61,7 +61,6 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe ); } - ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, new Constructor($originalClass)); ClassGeneratorUtils::addMethodIfNotFinal( $originalClass, $classGenerator, diff --git a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php index 06965250c..4e4cc3586 100644 --- a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php +++ b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php @@ -18,7 +18,6 @@ namespace ProxyManager\ProxyGenerator; -use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor; use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty; use ProxyManager\Generator\Util\ClassGeneratorUtils; @@ -83,7 +82,6 @@ function (ReflectionMethod $method) use ($adapter, $originalClass) { ) ), array( - new Constructor($originalClass, $adapter), new StaticProxyConstructor($originalClass, $adapter), new MagicGet($originalClass, $adapter), new MagicSet($originalClass, $adapter), From d6c00b30a4d26ac8624ce06cfe5c888a59a44c78 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 28 Sep 2014 15:33:13 +0200 Subject: [PATCH 44/99] PHP 5.6 supports reflection-based proxy instantiation for internal classes. May allow 5.5 as well, but messy for now. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c5d20622..3d0bc9b56 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": ">=5.3.3", + "php": "~5.6", "zendframework/zend-code": ">2.2.5,<3.0" }, "require-dev": { From b727fdd29122bf0d5e4c4ed46820485411390131 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 13:27:08 +0200 Subject: [PATCH 45/99] No need to extend from anything in the remote object factory tests --- tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php b/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php index 046bde584..0382a12f4 100644 --- a/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php +++ b/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php @@ -144,8 +144,7 @@ function (ClassGenerator $targetClass) use ($proxyClassName) { $this->returnCallback( function () use ($proxyClassName) { eval( - 'class ' . $proxyClassName - . ' extends stdClass {' + 'class ' . $proxyClassName . ' {' . 'public static function staticProxyConstructor() { return new static(); }' . '}' ); @@ -172,7 +171,6 @@ function () use ($proxyClassName) { $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface'); $factory = new RemoteObjectFactory($adapter, $this->config); - /* @var $proxy \stdClass */ $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter); $this->assertInstanceOf($proxyClassName, $proxy); From 3234e828bffda7577799c5ad16f349eeaaa2956b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 13:36:41 +0200 Subject: [PATCH 46/99] Optimized imports (duplicate imports were causing fatals) --- .../ProxyGenerator/LazyLoadingValueHolderGenerator.php | 3 --- src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php | 1 - 2 files changed, 4 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php index ac36979a8..041321645 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php @@ -39,9 +39,6 @@ use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer; use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty; use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty; -use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; -use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; -use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue; use ReflectionClass; use ReflectionMethod; use Zend\Code\Generator\ClassGenerator; diff --git a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php index 4e4cc3586..6e1fb27a6 100644 --- a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php +++ b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php @@ -27,7 +27,6 @@ use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset; -use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; use ReflectionClass; use ReflectionMethod; From 34a7c0a63ce04b38458b9354a85204d9f4c945b9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 13:37:31 +0200 Subject: [PATCH 47/99] Using static constructor where available --- .../Functional/LazyLoadingValueHolderFunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php index 3efb05ae9..ac92fe0b7 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php @@ -230,7 +230,7 @@ public function testWillAllowMultipleProxyInitialization() }; /* @var $proxy BaseClass */ - $proxy = new $proxyClass($initializer); + $proxy = $proxyClass::staticProxyConstructor($initializer); $this->assertSame('1', $proxy->publicProperty); $this->assertSame('2', $proxy->publicProperty); From ad747c872ab8cf8235e036a023addddf0d629bf5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 13:38:01 +0200 Subject: [PATCH 48/99] Simplified test code (avoiding unused assignment) --- .../Functional/LazyLoadingValueHolderFunctionalTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php index ac92fe0b7..1853eb8fd 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php @@ -223,14 +223,13 @@ public function testWillAllowMultipleProxyInitialization() { $proxyClass = $this->generateProxy('ProxyManagerTestAsset\\BaseClass'); $counter = 0; - $initializer = function (& $wrappedInstance) use (& $counter) { + + /* @var $proxy BaseClass */ + $proxy = $proxyClass::staticProxyConstructor(function (& $wrappedInstance) use (& $counter) { $wrappedInstance = new BaseClass(); $wrappedInstance->publicProperty = (string) ($counter += 1); - }; - - /* @var $proxy BaseClass */ - $proxy = $proxyClass::staticProxyConstructor($initializer); + }); $this->assertSame('1', $proxy->publicProperty); $this->assertSame('2', $proxy->publicProperty); From ca8bac48ad104cbae043d48a5fa01ae5a7d7deae Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 14:10:43 +0200 Subject: [PATCH 49/99] Fixed line length overflow (limit is 120 chars) --- .../Functional/LazyLoadingValueHolderFunctionalTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php index 1853eb8fd..6137ddb06 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php @@ -66,7 +66,9 @@ public function testMethodCallsAfterUnSerialization($className, $instance, $meth $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ - $proxy = unserialize(serialize($proxyName::staticProxyConstructor($this->createInitializer($className, $instance)))); + $proxy = unserialize(serialize($proxyName::staticProxyConstructor( + $this->createInitializer($className, $instance) + ))); $this->assertTrue($proxy->isProxyInitialized()); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); From 7edac82ba3f03975612e4c524379b03a4900a8a1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 14:11:11 +0200 Subject: [PATCH 50/99] Fixed line length overflow (limit is 120 chars) --- .../Functional/LazyLoadingGhostFunctionalTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php index 3118350b8..c0a9fda91 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php @@ -68,7 +68,9 @@ public function testMethodCallsAfterUnSerialization($className, $instance, $meth $proxyName = $this->generateProxy($className); /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ - $proxy = unserialize(serialize($proxyName::staticProxyConstructor($this->createInitializer($className, $instance)))); + $proxy = unserialize(serialize($proxyName::staticProxyConstructor( + $this->createInitializer($className, $instance) + ))); $this->assertTrue($proxy->isProxyInitialized()); $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); From dab3e3a2750d3585c39416ad195ac47a09cf55bc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 14:12:58 +0200 Subject: [PATCH 51/99] Loosen requirement for PHP versions: 5.4 is enough to have some syntax improvements and `ReflectionClass#newInstanceWithoutConstructor()` --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3d0bc9b56..0431488c5 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": "~5.6", + "php": "~5.4", "zendframework/zend-code": ">2.2.5,<3.0" }, "require-dev": { @@ -28,6 +28,7 @@ "squizlabs/php_codesniffer": "1.5.*" }, "suggest": { + "php": ">5.6 if you work with internal PHP classes, as reflection instantiation does not work with older PHP versions", "zendframework/zend-stdlib": "To use the hydrator proxy", "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects", "zendframework/zend-xmlrpc": "To have the XmlRpc adapter (Remote Object feature)", From 3e9188639ec28639082d04b1814f988386cd4b48 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 14:13:16 +0200 Subject: [PATCH 52/99] Skipping PHP 5.3 builds --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f42dac82..bbc0e4b81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - 5.3.3 - - 5.3 - 5.4 - 5.5 - 5.6 From b5c43dea1b4b03213c347ebdd8f975cf0add9ec8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 14:24:41 +0200 Subject: [PATCH 53/99] Fixed breakages in the test suite - was using static constructor on non-proxied classes --- .../Functional/LazyLoadingGhostPerformanceTest.php | 4 ++-- .../Functional/LazyLoadingValueHolderPerformanceTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php index 1dafff9c0..dd4dce3c5 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php @@ -58,7 +58,7 @@ public function testProxyInstantiationPerformance( $instances = array(); /* @var $proxies \ProxyManager\Proxy\GhostObjectInterface[] */ $proxies = array(); - $realInstance = $className::staticProxyConstructor(); + $realInstance = new $className(); $initializer = function ( GhostObjectInterface $proxy, $method, @@ -80,7 +80,7 @@ public function testProxyInstantiationPerformance( $this->startCapturing(); for ($i = 0; $i < $iterations; $i += 1) { - $instances[] = $className::staticProxyConstructor(); + $instances[] = new $className(); } $baseProfile = $this->endCapturing( diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php index 4f6d30d7f..43ac4e658 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php @@ -61,7 +61,7 @@ public function testProxyInstantiationPerformance($className, array $methods, ar & $initializer ) use ($className) { $initializer = null; - $valueHolder = $className::staticProxyConstructor(); + $valueHolder = new $className(); return true; }; @@ -69,7 +69,7 @@ public function testProxyInstantiationPerformance($className, array $methods, ar $this->startCapturing(); for ($i = 0; $i < $iterations; $i += 1) { - $instances[] = $className::staticProxyConstructor(); + $instances[] = new $className(); } $baseProfile = $this->endCapturing( From c4ba60816150caa3d9643dbde44c652d530127b3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 14:30:27 +0200 Subject: [PATCH 54/99] Skipping tests about internal PHP classes when in PHP < 5.6 --- .../lazy-loading-value-holder-internal-php-classes.phpt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/language-feature-scripts/lazy-loading-value-holder-internal-php-classes.phpt b/tests/language-feature-scripts/lazy-loading-value-holder-internal-php-classes.phpt index 2a5a77707..75a078d61 100644 --- a/tests/language-feature-scripts/lazy-loading-value-holder-internal-php-classes.phpt +++ b/tests/language-feature-scripts/lazy-loading-value-holder-internal-php-classes.phpt @@ -1,5 +1,11 @@ --TEST-- Verifies that lazy loading value holder factory can generate proxy for PHP core classes. +--SKIPIF-- + --FILE-- Date: Wed, 1 Oct 2014 16:39:56 +0200 Subject: [PATCH 55/99] Simplified static proxy constructor (avoiding unused params --- .../StaticProxyConstructor.php | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index c692bb762..6c5050bae 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -34,12 +34,11 @@ class StaticProxyConstructor extends MethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass */ - public function __construct( - ReflectionClass $originalClass, - PropertyGenerator $prefixInterceptors, - PropertyGenerator $suffixInterceptors - ) { + public function __construct(ReflectionClass $originalClass) + { parent::__construct('staticProxyConstructor', array(), static::FLAG_PUBLIC | static::FLAG_STATIC); $localizedObject = new ParameterGenerator('localizedObject'); @@ -56,30 +55,6 @@ public function __construct( $this->setParameter($prefix); $this->setParameter($suffix); - $localizedProperties = array(); - $instanceGenerator = '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' - . "\n\n"; - - foreach ($originalClass->getProperties() as $originalProperty) { - if ((PHP_VERSION_ID < 50400 || (defined('HHVM_VERSION'))) && $originalProperty->isPrivate()) { - // @codeCoverageIgnoreStart - throw UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty($originalProperty); - // @codeCoverageIgnoreEnd - } - - $propertyName = $originalProperty->getName(); - - if ($originalProperty->isPrivate()) { - $localizedProperties[] = "\\Closure::bind(function () use (\$localizedObject, \$instance) {\n " - . '$instance->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";\n" - . '}, $instance, ' . var_export($originalProperty->getDeclaringClass()->getName(), true) - . ')->__invoke();'; - } else { - $localizedProperties[] = '$instance->' . $propertyName - . ' = & $localizedObject->' . $propertyName . ";"; - } - } - $this->setDocblock( "Constructor to setup interceptors\n\n" . "@param \\" . $originalClass->getName() . " \$localizedObject\n" @@ -88,7 +63,7 @@ public function __construct( . "@return self" ); $this->setBody( - $instanceGenerator + '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . '$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors);' . "\n\n" . 'return $instance;' ); From b67197fe0a8a490d157d6880339219635ab2804a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 16:55:38 +0200 Subject: [PATCH 56/99] Implemented missing docblock params --- .../AccessInterceptor/MethodGenerator/MagicWakeup.php | 2 ++ .../MethodGenerator/SetMethodPrefixInterceptor.php | 2 ++ .../MethodGenerator/SetMethodSuffixInterceptor.php | 2 ++ .../MethodGenerator/BindProxyProperties.php | 4 ++++ .../MethodGenerator/Constructor.php | 4 ++++ .../MethodGenerator/MagicClone.php | 4 ++++ .../MethodGenerator/MagicSleep.php | 4 ++++ .../AccessInterceptorScopeLocalizerGenerator.php | 1 - .../MethodGenerator/Constructor.php | 5 +++++ .../MethodGenerator/MagicClone.php | 5 +++++ .../MethodGenerator/MagicGet.php | 6 ++++++ .../MethodGenerator/MagicIsset.php | 5 +++++ .../MethodGenerator/MagicSet.php | 5 +++++ .../MethodGenerator/MagicUnset.php | 5 +++++ .../MethodGenerator/StaticProxyConstructor.php | 5 +++++ .../LazyLoading/MethodGenerator/Constructor.php | 3 +++ .../LazyLoading/MethodGenerator/StaticProxyConstructor.php | 3 +++ .../LazyLoadingGhost/MethodGenerator/CallInitializer.php | 4 ++++ .../MethodGenerator/GetProxyInitializer.php | 2 ++ .../LazyLoadingGhost/MethodGenerator/InitializeProxy.php | 3 +++ .../LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php | 2 ++ .../LazyLoadingGhost/MethodGenerator/MagicClone.php | 4 ++++ .../LazyLoadingGhost/MethodGenerator/MagicSleep.php | 4 ++++ .../MethodGenerator/SetProxyInitializer.php | 2 ++ .../MethodGenerator/GetProxyInitializer.php | 2 ++ .../MethodGenerator/InitializeProxy.php | 3 +++ .../MethodGenerator/IsProxyInitialized.php | 2 ++ .../LazyLoadingValueHolder/MethodGenerator/MagicClone.php | 4 ++++ .../LazyLoadingValueHolder/MethodGenerator/MagicGet.php | 5 +++++ .../LazyLoadingValueHolder/MethodGenerator/MagicIsset.php | 5 +++++ .../LazyLoadingValueHolder/MethodGenerator/MagicSet.php | 5 +++++ .../LazyLoadingValueHolder/MethodGenerator/MagicSleep.php | 4 ++++ .../LazyLoadingValueHolder/MethodGenerator/MagicUnset.php | 5 +++++ .../MethodGenerator/SetProxyInitializer.php | 2 ++ .../MethodGenerator/GetWrappedValueHolderValue.php | 2 ++ .../ValueHolder/MethodGenerator/MagicSleep.php | 3 +++ 36 files changed, 127 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeup.php b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeup.php index 5b7c19d15..f30e8e4e1 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeup.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeup.php @@ -32,6 +32,8 @@ class MagicWakeup extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass */ public function __construct(ReflectionClass $originalClass) { diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php index 85ba61359..f547f9de9 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php @@ -33,6 +33,8 @@ class SetMethodPrefixInterceptor extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $prefixInterceptor */ public function __construct(PropertyGenerator $prefixInterceptor) { diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php index 74cf81f23..0138ce0bd 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php @@ -33,6 +33,8 @@ class SetMethodSuffixInterceptor extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $suffixInterceptor */ public function __construct(PropertyGenerator $suffixInterceptor) { diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php index 60146d202..644061073 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php @@ -34,6 +34,10 @@ class BindProxyProperties extends MethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Constructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Constructor.php index 3770a16f3..9301a8dc9 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Constructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Constructor.php @@ -34,6 +34,10 @@ class Constructor extends MethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicClone.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicClone.php index 98e9b19aa..062b6c369 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicClone.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicClone.php @@ -33,6 +33,10 @@ class MagicClone extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleep.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleep.php index 3ea4a2589..89fc8e8b5 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleep.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleep.php @@ -33,6 +33,10 @@ class MagicSleep extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php index bc95a254b..afc3aab7b 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php @@ -82,7 +82,6 @@ function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptor ) ), array( - new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors), new StaticProxyConstructor($originalClass, $prefixInterceptors, $suffixInterceptors), new BindProxyProperties($originalClass, $prefixInterceptors, $suffixInterceptors), new SetMethodPrefixInterceptor($prefixInterceptors), diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php index 925ee6b51..b6e79ee34 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php @@ -34,6 +34,11 @@ class Constructor extends MethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolder + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicClone.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicClone.php index 764ba77fa..878c8a967 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicClone.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicClone.php @@ -32,6 +32,11 @@ class MagicClone extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolderProperty + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGet.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGet.php index 80962811e..04e9fef99 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGet.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGet.php @@ -36,6 +36,12 @@ class MagicGet extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolder + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIsset.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIsset.php index 2647b3529..f51a02e3c 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIsset.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIsset.php @@ -36,6 +36,11 @@ class MagicIsset extends MagicMethodGenerator { /** * Constructor + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolder + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSet.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSet.php index b443b770c..e8ad4e60c 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSet.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSet.php @@ -36,6 +36,11 @@ class MagicSet extends MagicMethodGenerator { /** * Constructor + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolder + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php index bdf3a1aa0..85fcdfa4e 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php @@ -36,6 +36,11 @@ class MagicUnset extends MagicMethodGenerator { /** * Constructor + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolder + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index fcab09102..c1900b52e 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -34,6 +34,11 @@ class StaticProxyConstructor extends MethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolder + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/Constructor.php b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/Constructor.php index 224370b33..2d996b5e2 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/Constructor.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/Constructor.php @@ -34,6 +34,9 @@ class Constructor extends MethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty */ public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php index 15fe018c4..2e491f1c2 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php @@ -34,6 +34,9 @@ class StaticProxyConstructor extends MethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty */ public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php index 36f2794fd..3ac217090 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php @@ -34,6 +34,10 @@ class CallInitializer extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $publicPropsDefaults + * @param PropertyGenerator $initTracker */ public function __construct( PropertyGenerator $initializerProperty, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializer.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializer.php index 5b1d75a4f..9cd523359 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializer.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializer.php @@ -32,6 +32,8 @@ class GetProxyInitializer extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty */ public function __construct(PropertyGenerator $initializerProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxy.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxy.php index 90723c31c..819f3f050 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxy.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxy.php @@ -33,6 +33,9 @@ class InitializeProxy extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty + * @param ZendMethodGenerator $callInitializer */ public function __construct(PropertyGenerator $initializerProperty, ZendMethodGenerator $callInitializer) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php index 110ef3173..cbb904b33 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php @@ -32,6 +32,8 @@ class IsProxyInitialized extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty */ public function __construct(PropertyGenerator $initializerProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicClone.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicClone.php index 34d999b7b..83a843a1c 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicClone.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicClone.php @@ -33,6 +33,10 @@ class MagicClone extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param MethodGenerator $callInitializer */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleep.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleep.php index a8036b2dd..0dcde1b08 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleep.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleep.php @@ -33,6 +33,10 @@ class MagicSleep extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param MethodGenerator $callInitializer */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php index 30e37bbb7..cbaf72bd7 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php @@ -33,6 +33,8 @@ class SetProxyInitializer extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty */ public function __construct(PropertyGenerator $initializerProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializer.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializer.php index 3dd085484..51f25764f 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializer.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializer.php @@ -32,6 +32,8 @@ class GetProxyInitializer extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty */ public function __construct(PropertyGenerator $initializerProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxy.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxy.php index 4c358b100..c5a0e6530 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxy.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxy.php @@ -32,6 +32,9 @@ class InitializeProxy extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty */ public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitialized.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitialized.php index 34fdd0bd8..f9ef07ee9 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitialized.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitialized.php @@ -32,6 +32,8 @@ class IsProxyInitialized extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $valueHolderProperty */ public function __construct(PropertyGenerator $valueHolderProperty) { diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php index d62c46ab1..0440b0fbd 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php @@ -32,6 +32,10 @@ class MagicClone extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php index 43b3ec51a..84f6ee4c2 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php @@ -35,6 +35,11 @@ class MagicGet extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIsset.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIsset.php index 11607a4ce..90357ee2c 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIsset.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIsset.php @@ -35,6 +35,11 @@ class MagicIsset extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSet.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSet.php index 453031917..e0b2226fd 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSet.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSet.php @@ -35,6 +35,11 @@ class MagicSet extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php index 20051c8f2..2c2e9438f 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php @@ -32,6 +32,10 @@ class MagicSleep extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnset.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnset.php index 0c339541f..51400bb1d 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnset.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnset.php @@ -35,6 +35,11 @@ class MagicUnset extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty + * @param PublicPropertiesMap $publicProperties */ public function __construct( ReflectionClass $originalClass, diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php index db3400f5b..2c84304a1 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php @@ -33,6 +33,8 @@ class SetProxyInitializer extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $initializerProperty */ public function __construct(PropertyGenerator $initializerProperty) { diff --git a/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValue.php b/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValue.php index 7db81d375..4e0220467 100644 --- a/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValue.php +++ b/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValue.php @@ -32,6 +32,8 @@ class GetWrappedValueHolderValue extends MethodGenerator { /** * Constructor + * + * @param PropertyGenerator $valueHolderProperty */ public function __construct(PropertyGenerator $valueHolderProperty) { diff --git a/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleep.php b/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleep.php index 17aa0fd63..71a6f3149 100644 --- a/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleep.php +++ b/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleep.php @@ -32,6 +32,9 @@ class MagicSleep extends MagicMethodGenerator { /** * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $valueHolderProperty */ public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolderProperty) { From b5ab074b603ccf602742ea9f976ffa46ae62b1e3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:00:04 +0200 Subject: [PATCH 57/99] Removed unused imports --- .../MethodGenerator/StaticProxyConstructor.php | 2 -- .../ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php | 1 - .../ProxyGenerator/AccessInterceptorValueHolderGenerator.php | 1 - 3 files changed, 4 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index 6c5050bae..cbc2cf79f 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -18,11 +18,9 @@ namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator; -use ProxyManager\Exception\UnsupportedProxiedClassException; use ProxyManager\Generator\MethodGenerator; use ProxyManager\Generator\ParameterGenerator; use ReflectionClass; -use Zend\Code\Generator\PropertyGenerator; /** * The `staticProxyConstructor` implementation for an access interceptor scope localizer proxy diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php index afc3aab7b..56a45273e 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php @@ -23,7 +23,6 @@ use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\BindProxyProperties; -use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet; diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php index 62f10503b..3ad355a98 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php @@ -24,7 +24,6 @@ use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors; -use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet; From 7b7ff4a45e266503f04370a09259f99f51ab88f3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:23:17 +0200 Subject: [PATCH 58/99] Minor performance optimization: avoiding spawning a reflection class instance for each instantiated object --- .../MethodGenerator/StaticProxyConstructor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php index cbc2cf79f..faeb2ffc6 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructor.php @@ -61,7 +61,9 @@ public function __construct(ReflectionClass $originalClass) . "@return self" ); $this->setBody( - '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" + 'static $reflection;' . "\n\n" + . '$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);' . "\n" + . '$instance = $reflection->newInstanceWithoutConstructor();' . "\n\n" . '$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors);' . "\n\n" . 'return $instance;' ); From 85b5b19018472be3cf6f6f0d3bc2fb6ae9223deb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:25:35 +0200 Subject: [PATCH 59/99] Minor performance optimization: avoiding spawning a reflection class instance for each instantiated object --- .../MethodGenerator/StaticProxyConstructor.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php index c1900b52e..3739ec4ab 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructor.php @@ -61,10 +61,8 @@ public function __construct( $this->setParameter($suffix); /* @var $publicProperties \ReflectionProperty[] */ - $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); - $unsetProperties = array(); - $instanceGenerator = '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' - . "\n\n"; + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $unsetProperties = array(); foreach ($publicProperties as $publicProperty) { $unsetProperties[] = '$instance->' . $publicProperty->getName(); @@ -78,7 +76,9 @@ public function __construct( . "@return self" ); $this->setBody( - $instanceGenerator + 'static $reflection;' . "\n\n" + . '$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);' . "\n" + . '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') . '$instance->' . $valueHolder->getName() . " = \$wrappedObject;\n" . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" From f8e4156e96880aaa33e4faa3615bf44e78ba9014 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:26:16 +0200 Subject: [PATCH 60/99] Minor performance optimization: avoiding spawning a reflection class instance for each instantiated object --- .../LazyLoading/MethodGenerator/StaticProxyConstructor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php index 2e491f1c2..4c8cd3fe9 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructor.php @@ -54,7 +54,9 @@ public function __construct(ReflectionClass $originalClass, PropertyGenerator $i $this->setDocblock("Constructor for lazy initialization\n\n@param \\Closure|null \$initializer"); $this->setBody( - '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" + 'static $reflection;' . "\n\n" + . '$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);' . "\n" + . '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') . '$instance->' . $initializerProperty->getName() . ' = $initializer;' . "\n\n" . 'return $instance;' From 7ce16a09638fb26dd3578128b6022713ac8296ad Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:33:24 +0200 Subject: [PATCH 61/99] Minor performance optimization: avoiding spawning a reflection class instance for each instantiated object --- .../NullObject/MethodGenerator/StaticProxyConstructor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php index 18b032447..6acd437bf 100644 --- a/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php @@ -49,7 +49,9 @@ public function __construct(ReflectionClass $originalClass) $this->setDocblock("Constructor for null object initialization"); $this->setBody( - '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" + 'static $reflection;' . "\n\n" + . '$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);' . "\n" + . '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . ($nullableProperties ? implode("\n", $nullableProperties) . "\n\n" : '') . 'return $instance;' ); From 8bd50f3c91149ae26979104e57dd6195a8c200a1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:36:38 +0200 Subject: [PATCH 62/99] Minor performance optimization: avoiding spawning a reflection class instance for each instantiated object --- .../RemoteObject/MethodGenerator/StaticProxyConstructor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php b/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php index 0b7369274..2b363f5ef 100644 --- a/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php +++ b/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructor.php @@ -55,7 +55,9 @@ public function __construct(ReflectionClass $originalClass, PropertyGenerator $a . '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \$adapter' ); - $body = '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" + $body = 'static $reflection;' . "\n\n" + . '$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);' . "\n" + . '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . '$instance->' . $adapterName . ' = $' . $adapterName . ';'; foreach ($originalClass->getProperties() as $property) { From 1031dea3d047e20601c2c847062bd4c021312008 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:55:14 +0200 Subject: [PATCH 63/99] Coverage for the static proxy constructor implementation --- .../StaticProxyConstructorTest.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/StaticProxyConstructorTest.php diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/StaticProxyConstructorTest.php new file mode 100644 index 000000000..446baad28 --- /dev/null +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/StaticProxyConstructorTest.php @@ -0,0 +1,88 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor + * @group Coverage + */ +class StaticProxyConstructorTest extends PHPUnit_Framework_TestCase +{ + private $prefixInterceptors; + private $suffixInterceptors; + public function setUp() + { + $this->prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $this->suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $this->prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $this->suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + } + + public function testSignature() + { + $method = new StaticProxyConstructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithProtectedProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + $this->assertSame('staticProxyConstructor', $method->getName()); + + $parameters = $method->getParameters(); + + $this->assertCount(3, $parameters); + + $this->assertSame( + 'ProxyManagerTestAsset\\ClassWithProtectedProperties', + $parameters['localizedObject']->getType() + ); + $this->assertSame('array', $parameters['prefixInterceptors']->getType()); + $this->assertSame('array', $parameters['suffixInterceptors']->getType()); + } + + public function testBodyStructure() + { + $method = new StaticProxyConstructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = $reflection->newInstanceWithoutConstructor(); + +$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors); + +return $instance;', + $method->getBody() + ); + } +} From 11a215d9a973aa40ef867dfc61e6963ce7c7a02a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 17:55:40 +0200 Subject: [PATCH 64/99] Correct location for the `StaticProxyConstructorTest` --- .../{ => MethodGenerator}/StaticProxyConstructorTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/{ => MethodGenerator}/StaticProxyConstructorTest.php (100%) diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructorTest.php similarity index 100% rename from tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/StaticProxyConstructorTest.php rename to tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/StaticProxyConstructorTest.php From 4d9a980861bea56865911e76caf5a1111cf3d466 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:06:20 +0200 Subject: [PATCH 65/99] Coverage for the `BindProxyProperties` implementation --- .../BindProxyPropertiesTest.php | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php new file mode 100644 index 000000000..c493e6d25 --- /dev/null +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php @@ -0,0 +1,210 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\BindProxyProperties + * @group Coverage + */ +class BindProxyPropertiesTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + private $prefixInterceptors; + + /** + * @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + private $suffixInterceptors; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $this->suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $this->prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $this->suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + } + + public function testSignature() + { + $method = new BindProxyProperties( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithProtectedProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + $this->assertSame('bindProxyProperties', $method->getName()); + $this->assertSame('private', $method->getVisibility()); + $this->assertFalse($method->isStatic()); + + $parameters = $method->getParameters(); + + $this->assertCount(3, $parameters); + + $this->assertSame( + 'ProxyManagerTestAsset\\ClassWithProtectedProperties', + $parameters['localizedObject']->getType() + ); + $this->assertSame('array', $parameters['prefixInterceptors']->getType()); + $this->assertSame('array', $parameters['suffixInterceptors']->getType()); + } + + public function testBodyStructure() + { + $method = new BindProxyProperties( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + + $this->assertSame( + '$this->property0 = & $localizedObject->property0; + +$this->property1 = & $localizedObject->property1; + +$this->property2 = & $localizedObject->property2; + +$this->property3 = & $localizedObject->property3; + +$this->property4 = & $localizedObject->property4; + +$this->property5 = & $localizedObject->property5; + +$this->property6 = & $localizedObject->property6; + +$this->property7 = & $localizedObject->property7; + +$this->property8 = & $localizedObject->property8; + +$this->property9 = & $localizedObject->property9; + +$this->pre = $prefixInterceptors; +$this->post = $suffixInterceptors;', + $method->getBody() + ); + } + + public function testBodyStructureWithProtectedProperties() + { + $method = new BindProxyProperties( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithProtectedProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + + $this->assertSame( + '$this->property0 = & $localizedObject->property0; + +$this->property1 = & $localizedObject->property1; + +$this->property2 = & $localizedObject->property2; + +$this->property3 = & $localizedObject->property3; + +$this->property4 = & $localizedObject->property4; + +$this->property5 = & $localizedObject->property5; + +$this->property6 = & $localizedObject->property6; + +$this->property7 = & $localizedObject->property7; + +$this->property8 = & $localizedObject->property8; + +$this->property9 = & $localizedObject->property9; + +$this->pre = $prefixInterceptors; +$this->post = $suffixInterceptors;', + $method->getBody() + ); + } + + public function testBodyStructureWithPrivateProperties() + { + if (! method_exists('Closure', 'bind')) { + $this->setExpectedException('ProxyManager\Exception\UnsupportedProxiedClassException'); + } + + $method = new BindProxyProperties( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPrivateProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + + $this->assertSame( + '\Closure::bind(function () use ($localizedObject) { + $this->property0 = & $localizedObject->property0; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property1 = & $localizedObject->property1; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property2 = & $localizedObject->property2; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property3 = & $localizedObject->property3; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property4 = & $localizedObject->property4; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property5 = & $localizedObject->property5; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property6 = & $localizedObject->property6; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property7 = & $localizedObject->property7; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property8 = & $localizedObject->property8; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property9 = & $localizedObject->property9; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +$this->pre = $prefixInterceptors; +$this->post = $suffixInterceptors;', + $method->getBody() + ); + } +} From 32b8743b01bb3c98f066ac1ecd5fa4bbe39b1876 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:06:49 +0200 Subject: [PATCH 66/99] Removing unused import --- .../MethodGenerator/BindProxyPropertiesTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php index c493e6d25..6f06604d1 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyPropertiesTest.php @@ -20,7 +20,6 @@ use PHPUnit_Framework_TestCase; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\BindProxyProperties; -use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor; use ReflectionClass; /** From a4ad8561deea7fa4cedecc0543a2575abbeeff9f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:14:20 +0200 Subject: [PATCH 67/99] Coverage for the static proxy constructor implementation --- .../StaticProxyConstructorTest.php | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php new file mode 100644 index 000000000..0b444e2d8 --- /dev/null +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php @@ -0,0 +1,97 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\StaticProxyConstructor + * @group Coverage + */ +class StaticProxyConstructorTest extends PHPUnit_Framework_TestCase +{ + public function testBodyStructure() + { + /* @var $initializer \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $constructor = new StaticProxyConstructor( + new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ), + $initializer + ); + + $this->assertSame('staticProxyConstructor', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor(); + +unset($instance->bar, $instance->baz); + +$instance->foo = $initializer; + +return $instance;', + $constructor->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor::__construct + */ + public function testBodyStructureWithoutPublicProperties() + { + /* @var $initializer \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $constructor = new StaticProxyConstructor( + new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'), + $initializer + ); + + $this->assertSame('staticProxyConstructor', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor(); + +$instance->foo = $initializer; + +return $instance;', + $constructor->getBody() + ); + } +} From 7aebe266efd33345dd5a76fc31d6376ed9bb14af Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:30:43 +0200 Subject: [PATCH 68/99] Coverage for the static proxy constructor implementation --- .../StaticProxyConstructorTest.php | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php new file mode 100644 index 000000000..36588baf5 --- /dev/null +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php @@ -0,0 +1,114 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\StaticProxyConstructor + * @group Coverage + */ +class StaticProxyConstructorTest extends PHPUnit_Framework_TestCase +{ + public function testBodyStructure() + { + /* @var $valueHolder \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + /* @var $prefixInterceptors \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + /* @var $suffixInterceptors \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $constructor = new StaticProxyConstructor( + new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ), + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('staticProxyConstructor', $constructor->getName()); + $this->assertCount(3, $constructor->getParameters()); + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor(); + +unset($instance->bar, $instance->baz); + +$instance->foo = $wrappedObject; +$instance->pre = $prefixInterceptors; +$instance->post = $suffixInterceptors; + +return $instance;', + $constructor->getBody() + ); + } + + public function testBodyStructureWithoutPublicProperties() + { + /* @var $valueHolder \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + /* @var $prefixInterceptors \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + /* @var $suffixInterceptors \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $constructor = new StaticProxyConstructor( + new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'), + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('staticProxyConstructor', $constructor->getName()); + $this->assertCount(3, $constructor->getParameters()); + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor(); + +$instance->foo = $wrappedObject; +$instance->pre = $prefixInterceptors; +$instance->post = $suffixInterceptors; + +return $instance;', + $constructor->getBody() + ); + } +} From c3499f24079a9008ccca5d4d328b897773e6c8f2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:39:23 +0200 Subject: [PATCH 69/99] Coverage for the static proxy constructor implementation --- .../StaticProxyConstructorTest.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php diff --git a/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php new file mode 100644 index 000000000..a4b42a764 --- /dev/null +++ b/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php @@ -0,0 +1,79 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor + * @group Coverage + */ +class StaticProxyConstructorTest extends PHPUnit_Framework_TestCase +{ + public function testBodyStructure() + { + $constructor = new StaticProxyConstructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithMixedProperties') + ); + + $this->assertSame('staticProxyConstructor', $constructor->getName()); + $this->assertCount(0, $constructor->getParameters()); + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor(); + +$instance->publicProperty0 = null; +$instance->publicProperty1 = null; +$instance->publicProperty2 = null; + +return $instance;', + $constructor->getBody() + ); + } + + public function testBodyStructureWithoutPublicProperties() + { + $constructor = new StaticProxyConstructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPrivateProperties') + ); + + $this->assertSame('staticProxyConstructor', $constructor->getName()); + $this->assertCount(0, $constructor->getParameters()); + $body = $constructor->getBody(); + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor(); + +return $instance;', + $body + ); + } +} From 0a072818670bba54a762874eabc073060e1ac759 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:39:36 +0200 Subject: [PATCH 70/99] Removed unused import --- .../NullObject/MethodGenerator/StaticProxyConstructorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php index a4b42a764..85d8fb031 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructorTest.php @@ -19,7 +19,6 @@ namespace ProxyManagerTest\ProxyGenerator\NullObject\MethodGenerator; use PHPUnit_Framework_TestCase; -use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor; use ReflectionClass; From 2fe62b58f0856d1765a86a28389ae9ebcd508815 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:52:58 +0200 Subject: [PATCH 71/99] Coverage for the static proxy constructor implementation --- .../StaticProxyConstructorTest.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php diff --git a/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php new file mode 100644 index 000000000..241a7e37b --- /dev/null +++ b/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php @@ -0,0 +1,69 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor + * @group Coverage + */ +class StaticProxyConstructorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor::__construct + */ + public function testBodyStructure() + { + /* @var $adapter \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter')); + + $constructor = new StaticProxyConstructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithMixedProperties'), + $adapter + ); + + $this->assertSame('staticProxyConstructor', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame( + 'static $reflection; + +$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__); +$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor(); + +$instance->adapter = $adapter; +unset($instance->publicProperty0); +unset($instance->publicProperty1); +unset($instance->publicProperty2); + +return $instance;', + $constructor->getBody() + ); + } +} From 0cbebf32076d7a61f394dd6520833311a2e31704 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 18:53:12 +0200 Subject: [PATCH 72/99] Removed unused import --- .../MethodGenerator/StaticProxyConstructorTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php index 241a7e37b..a2c4e9697 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/StaticProxyConstructorTest.php @@ -19,7 +19,6 @@ namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator; use PHPUnit_Framework_TestCase; -use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor; use ReflectionClass; @@ -34,9 +33,6 @@ */ class StaticProxyConstructorTest extends PHPUnit_Framework_TestCase { - /** - * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor::__construct - */ public function testBodyStructure() { /* @var $adapter \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ From 78d228037ea5bce0400a07685e055449943127a3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 19:57:32 +0200 Subject: [PATCH 73/99] Adding test asset to verify that proxy constructors work as expected as of #115 and #175 --- .../ClassWithCounterConstructor.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php diff --git a/tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php b/tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php new file mode 100644 index 000000000..e90bc2cc6 --- /dev/null +++ b/tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class ClassWithCounterConstructor +{ + /** + * @var int + */ + public $amount = 0; + + /** + * @param int $increment + */ + public function __construct($increment) + { + $this->amount += $increment; + } +} From 59e1935c7d92e0b290d8649c42ee92fc26565b87 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 19:58:06 +0200 Subject: [PATCH 74/99] Adding test to verify that proxy constructors work like the proxied class' constructors as of #115 and #175 --- ...nterceptorScopeLocalizerFunctionalTest.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php index c59fb30e9..0b5d96a2b 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php @@ -25,6 +25,7 @@ use ProxyManager\Proxy\AccessInterceptorInterface; use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator; use ProxyManagerTestAsset\BaseClass; +use ProxyManagerTestAsset\ClassWithCounterConstructor; use ProxyManagerTestAsset\ClassWithPublicArrayProperty; use ProxyManagerTestAsset\ClassWithPublicProperties; use ProxyManagerTestAsset\ClassWithSelfHint; @@ -264,8 +265,7 @@ public function testWillNotModifyRetrievedPublicProperties() public function testWillModifyByRefRetrievedPublicProperties() { $instance = new ClassWithPublicProperties(); - $className = get_class($instance); - $proxyName = $this->generateProxy($className); + $proxyName = $this->generateProxy(get_class($instance)); /* @var $proxy ClassWithPublicProperties */ $proxy = $proxyName::staticProxyConstructor($instance); $variable = & $proxy->property0; @@ -278,6 +278,28 @@ public function testWillModifyByRefRetrievedPublicProperties() $this->assertProxySynchronized($instance, $proxy); } + /** + * @group 115 + * @group 175 + */ + public function testWillBehaveLikeObjectWithNormalConstructor() + { + $instance = new ClassWithCounterConstructor(10); + + $this->assertSame(10, $instance->amount, 'Verifying that test asset works as expected'); + + $proxyName = $this->generateProxy(get_class($instance)); + + /* @var $proxy ClassWithCounterConstructor */ + $proxy = new $proxyName(15); + + $this->assertSame(15, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + + $proxy->__construct(5); + + $this->assertSame(20, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + } + /** * Generates a proxy for the given class name, and retrieves its class name * From 7f13fdf070c2dddb3b9555d1d06bc99eb3cfc237 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 19:58:52 +0200 Subject: [PATCH 75/99] More checks on the test asset being used --- .../AccessInterceptorScopeLocalizerFunctionalTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php index 0b5d96a2b..efea587b9 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php @@ -288,6 +288,10 @@ public function testWillBehaveLikeObjectWithNormalConstructor() $this->assertSame(10, $instance->amount, 'Verifying that test asset works as expected'); + $instance->__construct(5); + + $this->assertSame(13, $instance->amount, 'Verifying that test asset works as expected'); + $proxyName = $this->generateProxy(get_class($instance)); /* @var $proxy ClassWithCounterConstructor */ From b9c6e9fafbee60587e586a52047cc0bf9ba476a8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 20:00:56 +0200 Subject: [PATCH 76/99] Typo fix (counter expectation was incorrect) --- .../AccessInterceptorScopeLocalizerFunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php index efea587b9..6af1bb8e4 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php @@ -288,7 +288,7 @@ public function testWillBehaveLikeObjectWithNormalConstructor() $this->assertSame(10, $instance->amount, 'Verifying that test asset works as expected'); - $instance->__construct(5); + $instance->__construct(3); $this->assertSame(13, $instance->amount, 'Verifying that test asset works as expected'); From eb9de784f932f0dcb64183e1f87df580b8585931 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 20:05:59 +0200 Subject: [PATCH 77/99] Adding getter for `amount` (to be proxied) --- .../ProxyManagerTestAsset/ClassWithCounterConstructor.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php b/tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php index e90bc2cc6..eedc31492 100644 --- a/tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php +++ b/tests/ProxyManagerTestAsset/ClassWithCounterConstructor.php @@ -39,4 +39,12 @@ public function __construct($increment) { $this->amount += $increment; } + + /** + * @return int + */ + public function getAmount() + { + return $this->amount; + } } From 11802d0b8674c92c46a15768ce6fd52388092ac0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 20:11:00 +0200 Subject: [PATCH 78/99] Testing getter logic on the access interceptor scope localizer logic --- .../AccessInterceptorScopeLocalizerFunctionalTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php index 6af1bb8e4..0aa9a488b 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php @@ -287,10 +287,10 @@ public function testWillBehaveLikeObjectWithNormalConstructor() $instance = new ClassWithCounterConstructor(10); $this->assertSame(10, $instance->amount, 'Verifying that test asset works as expected'); - + $this->assertSame(10, $instance->getAmount(), 'Verifying that test asset works as expected'); $instance->__construct(3); - $this->assertSame(13, $instance->amount, 'Verifying that test asset works as expected'); + $this->assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected'); $proxyName = $this->generateProxy(get_class($instance)); @@ -298,10 +298,10 @@ public function testWillBehaveLikeObjectWithNormalConstructor() $proxy = new $proxyName(15); $this->assertSame(15, $proxy->amount, 'Verifying that the proxy constructor works as expected'); - + $this->assertSame(15, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); $proxy->__construct(5); - $this->assertSame(20, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + $this->assertSame(20, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); } /** From 76c716cb769693ca9ef14a4cfb0e7122a1ccc957 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 20:28:27 +0200 Subject: [PATCH 79/99] Expecting access interceptor value holder to behave as if the constructor was the one of the original class --- ...ssInterceptorValueHolderFunctionalTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php index eca9a55c1..46625fd9b 100644 --- a/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php @@ -22,6 +22,7 @@ use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator; use ProxyManagerTestAsset\BaseClass; +use ProxyManagerTestAsset\ClassWithCounterConstructor; use ProxyManagerTestAsset\ClassWithPublicArrayProperty; use ProxyManagerTestAsset\ClassWithPublicProperties; use ProxyManagerTestAsset\ClassWithSelfHint; @@ -256,6 +257,32 @@ public function testWillModifyByRefRetrievedPublicProperties() $this->assertSame('foo', $proxy->property0); } + /** + * @group 115 + * @group 175 + */ + public function testWillBehaveLikeObjectWithNormalConstructor() + { + $instance = new ClassWithCounterConstructor(10); + + $this->assertSame(10, $instance->amount, 'Verifying that test asset works as expected'); + $this->assertSame(10, $instance->getAmount(), 'Verifying that test asset works as expected'); + $instance->__construct(3); + $this->assertSame(13, $instance->amount, 'Verifying that test asset works as expected'); + $this->assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected'); + + $proxyName = $this->generateProxy(get_class($instance)); + + /* @var $proxy ClassWithCounterConstructor */ + $proxy = new $proxyName(15); + + $this->assertSame(15, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + $this->assertSame(15, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); + $proxy->__construct(5); + $this->assertSame(20, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + $this->assertSame(20, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); + } + /** * Generates a proxy for the given class name, and retrieves its class name * From 85741f67e20a8e4056aabe68766a29048053928e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:39:18 +0200 Subject: [PATCH 80/99] Adding test asset with a PHP4-style constructors --- .../ClassWithPhp4Constructor.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php diff --git a/tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php b/tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php new file mode 100644 index 000000000..d4d19d2d0 --- /dev/null +++ b/tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class ClassWithPhp4Constructor +{ + /** + * @var mixed + */ + private $first; + + /** + * @var array + */ + private $second; + + /** + * @var ClassWithPhp4Constructor|null + */ + private $third; + + /** + * @param mixed $first + * @param array $second + * @param ClassWithPhp4Constructor|null $third + */ + public function ClassWithPhp4Constructor($first, array $second, ClassWithPhp4Constructor $third = null) + { + $this->first = $first; + $this->second = $second; + $this->third = $third; + } +} From 233b2e2e1baae5beb166695cb85e6a34dff80104 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:46:17 +0200 Subject: [PATCH 81/99] Removing invalid test asset - PHP4 constructors don't work with namespaced code (which is GOOD!) --- .../ClassWithPhp4Constructor.php | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php diff --git a/tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php b/tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php deleted file mode 100644 index d4d19d2d0..000000000 --- a/tests/ProxyManagerTestAsset/ClassWithPhp4Constructor.php +++ /dev/null @@ -1,55 +0,0 @@ - - * @license MIT - */ -class ClassWithPhp4Constructor -{ - /** - * @var mixed - */ - private $first; - - /** - * @var array - */ - private $second; - - /** - * @var ClassWithPhp4Constructor|null - */ - private $third; - - /** - * @param mixed $first - * @param array $second - * @param ClassWithPhp4Constructor|null $third - */ - public function ClassWithPhp4Constructor($first, array $second, ClassWithPhp4Constructor $third = null) - { - $this->first = $first; - $this->second = $second; - $this->third = $third; - } -} From 596c71dad7d37a171a4d697c2590e4e4b5fef0cd Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:49:40 +0200 Subject: [PATCH 82/99] Implementing codegen assertions for the access interceptor value holder constructor --- .../MethodGenerator/ConstructorTest.php | 94 ++++++++++++++----- 1 file changed, 71 insertions(+), 23 deletions(-) diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php index 97f717574..397777498 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php @@ -33,53 +33,101 @@ class ConstructorTest extends PHPUnit_Framework_TestCase { /** - * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor::__construct + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor */ public function testBodyStructure() { - $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); - $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); - $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); - $reflection = new ReflectionClass( - 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' - ); + /* @var $valueHolder \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); - $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); - $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); - $constructor = new Constructor($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors); + $constructor = Constructor::generateMethod( + new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ), + $valueHolder + ); $this->assertSame('__construct', $constructor->getName()); - $this->assertCount(3, $constructor->getParameters()); + $this->assertCount(0, $constructor->getParameters()); $this->assertSame( - "unset(\$this->bar, \$this->baz);\n\n\$this->foo = \$wrappedObject;\n\$this->pre = \$prefixInterceptors;" - . "\n\$this->post = \$suffixInterceptors;", + 'static $reflection; + +if (! $this->foo) { + $reflection = $reflection ?: new \ReflectionClass(\'ProxyManagerTestAsset\\\\ProxyGenerator\\\\LazyLoading\\\\' + . 'MethodGenerator\\\\ClassWithTwoPublicProperties\'); + $this->foo = $reflection->newInstanceWithoutConstructor(); + + unset($this->bar); + unset($this->baz); +} + +$this->foo->__construct();', $constructor->getBody() ); } /** - * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor::__construct + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor */ public function testBodyStructureWithoutPublicProperties() { - $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); - $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); - $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); - $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + /* @var $valueHolder \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); - $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); - $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); - $constructor = new Constructor($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors); + $constructor = Constructor::generateMethod( + new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'), + $valueHolder + ); $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(0, $constructor->getParameters()); + $this->assertSame( + 'static $reflection; + +if (! $this->foo) { + $reflection = $reflection ?: new \ReflectionClass(\'ProxyManagerTestAsset\\\\EmptyClass\'); + $this->foo = $reflection->newInstanceWithoutConstructor(); +} + +$this->foo->__construct();', + $constructor->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor + */ + public function testBodyStructureWithPhp4StyleConstructor() + { + $className = uniqid('ClassWithPhp4Constructor'); + + eval('class ' . $className . '{ public function ' . $className . '($first, $second, $third) {}}'); + + /* @var $valueHolder \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $constructor = Constructor::generateMethod( + new ReflectionClass($className), + $valueHolder + ); + + $this->assertSame($className, $constructor->getName()); $this->assertCount(3, $constructor->getParameters()); $this->assertSame( - "\$this->foo = \$wrappedObject;\n\$this->pre = \$prefixInterceptors;" - . "\n\$this->post = \$suffixInterceptors;", + 'static $reflection; + +if (! $this->foo) { + $reflection = $reflection ?: new \ReflectionClass(\'' . $className . '\'); + $this->foo = $reflection->newInstanceWithoutConstructor(); +} + +$this->foo->' . $className . '($first, $second, $third);', $constructor->getBody() ); } From 78a944fcec949e4a828f71d93d8fc690742b3980 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:50:09 +0200 Subject: [PATCH 83/99] Reducing coverage annotations clutter --- .../MethodGenerator/ConstructorTest.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php index 397777498..ed5618417 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php @@ -28,13 +28,11 @@ * @author Marco Pivetta * @license MIT * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor * @group Coverage */ class ConstructorTest extends PHPUnit_Framework_TestCase { - /** - * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor - */ public function testBodyStructure() { /* @var $valueHolder \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ @@ -68,9 +66,6 @@ public function testBodyStructure() ); } - /** - * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor - */ public function testBodyStructureWithoutPublicProperties() { /* @var $valueHolder \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ @@ -98,9 +93,6 @@ public function testBodyStructureWithoutPublicProperties() ); } - /** - * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor - */ public function testBodyStructureWithPhp4StyleConstructor() { $className = uniqid('ClassWithPhp4Constructor'); From fdcb2f4419816a6e4d084481d8c3f0d4192b9f79 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:50:36 +0200 Subject: [PATCH 84/99] Implementing constructor generator for access interceptor value holders - respectful of parent constructor signature/functionality --- .../MethodGenerator/Constructor.php | 108 ++++++++++++------ 1 file changed, 73 insertions(+), 35 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php index b6e79ee34..620e69679 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php @@ -23,6 +23,7 @@ use ReflectionClass; use ReflectionProperty; use Zend\Code\Generator\PropertyGenerator; +use Zend\Code\Reflection\MethodReflection; /** * The `__construct` implementation for lazy loading proxies @@ -37,48 +38,85 @@ class Constructor extends MethodGenerator * * @param ReflectionClass $originalClass * @param PropertyGenerator $valueHolder - * @param PropertyGenerator $prefixInterceptors - * @param PropertyGenerator $suffixInterceptors + * + * @return MethodGenerator */ - public function __construct( - ReflectionClass $originalClass, - PropertyGenerator $valueHolder, - PropertyGenerator $prefixInterceptors, - PropertyGenerator $suffixInterceptors - ) { - parent::__construct('__construct'); + public static function generateMethod(ReflectionClass $originalClass, PropertyGenerator $valueHolder) + { + $originalConstructor = self::getConstructor($originalClass); - $prefix = new ParameterGenerator('prefixInterceptors'); - $suffix = new ParameterGenerator('suffixInterceptors'); + $constructor = $originalConstructor + ? self::fromReflection($originalConstructor) + : new self('__construct'); - $prefix->setDefaultValue(array()); - $suffix->setDefaultValue(array()); - $prefix->setType('array'); - $suffix->setType('array'); + $constructor->setDocblock('{@inheritDoc}'); + $constructor->setBody( + 'static $reflection;' . "\n\n" + . 'if (! $this->' . $valueHolder->getName() . ') {' . "\n" + . ' $reflection = $reflection ?: new \ReflectionClass(' + . var_export($originalClass->getName(), true) + . ");\n" + . ' $this->' . $valueHolder->getName() . ' = $reflection->newInstanceWithoutConstructor();' . "\n" + . self::getUnsetPropertiesString($originalClass) + . "}\n\n" + . '$this->' . $valueHolder->getName() . '->' . $constructor->getName() . '(' + . implode( + ', ', + array_map( + function (ParameterGenerator $parameter) { + return '$' . $parameter->getName(); + }, + $constructor->getParameters() + ) + ) + . ');' + ); - $this->setParameter(new ParameterGenerator('wrappedObject')); - $this->setParameter($prefix); - $this->setParameter($suffix); + return $constructor; + } - /* @var $publicProperties \ReflectionProperty[] */ - $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); - $unsetProperties = array(); + /** + * @param ReflectionClass $class + * + * @return string + */ + private static function getUnsetPropertiesString(ReflectionClass $class) + { + $unsetProperties = implode( + "\n ", + array_map( + function (ReflectionProperty $unsetProperty) { + return 'unset($this->' . $unsetProperty->getName() . ');'; + }, + $class->getProperties(ReflectionProperty::IS_PUBLIC) + ) + ); - foreach ($publicProperties as $publicProperty) { - $unsetProperties[] = '$this->' . $publicProperty->getName(); - } + return $unsetProperties ? "\n " . $unsetProperties . "\n" : ''; + } - $this->setDocblock( - "@override constructor to setup interceptors\n\n" - . "@param \\" . $originalClass->getName() . " \$wrappedObject\n" - . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" - . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" - ); - $this->setBody( - ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') - . '$this->' . $valueHolder->getName() . " = \$wrappedObject;\n" - . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" - . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + /** + * @param ReflectionClass $class + * + * @return MethodReflection|null + */ + private static function getConstructor(ReflectionClass $class) + { + $constructors = array_map( + function (\ReflectionMethod $method) { + return new MethodReflection( + $method->getDeclaringClass()->getName(), + $method->getName() + ); + }, + array_filter( + $class->getMethods(), + function (\ReflectionMethod $method) { + return $method->isConstructor(); + } + ) ); + + return reset($constructors) ?: null; } } From cdcf9e9d0ecd74d31de7ea3b61be0a19d80a49b2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:51:04 +0200 Subject: [PATCH 85/99] Using the newly implemented access interceptor value holder constructor generator to respect LSP in proxy constructors --- .../ProxyGenerator/AccessInterceptorValueHolderGenerator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php index 3ad355a98..62f10503b 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php @@ -24,6 +24,7 @@ use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors; +use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet; From 86a8bfa97071dcd8a7b461444dc19bf133a214fd Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:54:52 +0200 Subject: [PATCH 86/99] Implementing tests to cover #115 and #175 in lazy loading ghost logic --- .../LazyLoadingGhostFunctionalTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php index c0a9fda91..ac74a6dc3 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php @@ -26,6 +26,7 @@ use ProxyManager\Proxy\GhostObjectInterface; use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator; use ProxyManagerTestAsset\BaseClass; +use ProxyManagerTestAsset\ClassWithCounterConstructor; use ProxyManagerTestAsset\ClassWithPublicArrayProperty; use ProxyManagerTestAsset\ClassWithPublicProperties; use ProxyManagerTestAsset\ClassWithProtectedProperties; @@ -298,6 +299,32 @@ public function testPrivatePropertyDefaultWillBePreserved() $this->assertSame('property0', $reflectionProperty->getValue($proxy)); } + /** + * @group 115 + * @group 175 + */ + public function testWillBehaveLikeObjectWithNormalConstructor() + { + $instance = new ClassWithCounterConstructor(10); + + $this->assertSame(10, $instance->amount, 'Verifying that test asset works as expected'); + $this->assertSame(10, $instance->getAmount(), 'Verifying that test asset works as expected'); + $instance->__construct(3); + $this->assertSame(13, $instance->amount, 'Verifying that test asset works as expected'); + $this->assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected'); + + $proxyName = $this->generateProxy(get_class($instance)); + + /* @var $proxy ClassWithCounterConstructor */ + $proxy = new $proxyName(15); + + $this->assertSame(15, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + $this->assertSame(15, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); + $proxy->__construct(5); + $this->assertSame(20, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + $this->assertSame(20, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); + } + /** * Generates a proxy for the given class name, and retrieves its class name * From 0eaf4052c8a59df5f75ff8a9c8ba7714a832e0b5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 21:56:03 +0200 Subject: [PATCH 87/99] Implementing tests to cover #115 and #175 in lazy loading value holder (failing) --- .../LazyLoadingValueHolderFunctionalTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php index 6137ddb06..84ef043d9 100644 --- a/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php @@ -26,6 +26,7 @@ use ProxyManager\Proxy\VirtualProxyInterface; use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator; use ProxyManagerTestAsset\BaseClass; +use ProxyManagerTestAsset\ClassWithCounterConstructor; use ProxyManagerTestAsset\ClassWithPublicArrayProperty; use ProxyManagerTestAsset\ClassWithPublicProperties; use ProxyManagerTestAsset\ClassWithSelfHint; @@ -238,6 +239,32 @@ public function testWillAllowMultipleProxyInitialization() $this->assertSame('3', $proxy->publicProperty); } + /** + * @group 115 + * @group 175 + */ + public function testWillBehaveLikeObjectWithNormalConstructor() + { + $instance = new ClassWithCounterConstructor(10); + + $this->assertSame(10, $instance->amount, 'Verifying that test asset works as expected'); + $this->assertSame(10, $instance->getAmount(), 'Verifying that test asset works as expected'); + $instance->__construct(3); + $this->assertSame(13, $instance->amount, 'Verifying that test asset works as expected'); + $this->assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected'); + + $proxyName = $this->generateProxy(get_class($instance)); + + /* @var $proxy ClassWithCounterConstructor */ + $proxy = new $proxyName(15); + + $this->assertSame(15, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + $this->assertSame(15, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); + $proxy->__construct(5); + $this->assertSame(20, $proxy->amount, 'Verifying that the proxy constructor works as expected'); + $this->assertSame(20, $proxy->getAmount(), 'Verifying that the proxy constructor works as expected'); + } + /** * Generates a proxy for the given class name, and retrieves its class name * From 52f0e75746dd902914fa083757a3135a4c44ef91 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:12:32 +0200 Subject: [PATCH 88/99] Restoring location of incorrectly moved files --- .../LazyLoading/MethodGenerator/ConstructorTest.php | 0 .../LazyLoading/MethodGenerator/StaticProxyConstructorTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/ProxyManagerTest/ProxyGenerator/{AccessInterceptorValueHolder => }/LazyLoading/MethodGenerator/ConstructorTest.php (100%) rename tests/ProxyManagerTest/ProxyGenerator/{AccessInterceptorValueHolder => }/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php (100%) diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/ConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/LazyLoading/MethodGenerator/ConstructorTest.php similarity index 100% rename from tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/ConstructorTest.php rename to tests/ProxyManagerTest/ProxyGenerator/LazyLoading/MethodGenerator/ConstructorTest.php diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php similarity index 100% rename from tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php rename to tests/ProxyManagerTest/ProxyGenerator/LazyLoading/MethodGenerator/StaticProxyConstructorTest.php From 6366b003c89dde3698c94dffd719cfd8dad98c62 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:15:59 +0200 Subject: [PATCH 89/99] Moved constructor generator into th more generic `ProxyManager\ProxyGenerator\ValueHolder` namespace, which is more suited for all value holders --- .../AccessInterceptorValueHolderGenerator.php | 2 +- .../ProxyGenerator/LazyLoadingValueHolderGenerator.php | 3 ++- .../MethodGenerator/Constructor.php | 2 +- .../MethodGenerator/ConstructorTest.php | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) rename src/ProxyManager/ProxyGenerator/{AccessInterceptorValueHolder => ValueHolder}/MethodGenerator/Constructor.php (97%) rename tests/ProxyManagerTest/ProxyGenerator/{AccessInterceptorValueHolder => ValueHolder}/MethodGenerator/ConstructorTest.php (92%) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php index 62f10503b..4990430ab 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php @@ -24,7 +24,6 @@ use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors; use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors; -use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet; @@ -36,6 +35,7 @@ use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty; use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; +use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue; use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\MagicSleep; use ReflectionClass; diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php index 041321645..4de06dd94 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php @@ -21,11 +21,11 @@ use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\StaticProxyConstructor; use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; +use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue; use ProxyManager\Generator\Util\ClassGeneratorUtils; use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; -use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer; use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy; use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized; @@ -93,6 +93,7 @@ function (ReflectionMethod $method) use ($initializer, $valueHolder) { ), array( new StaticProxyConstructor($originalClass, $initializer), + Constructor::generateMethod($originalClass, $valueHolder), new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties), diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php b/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/Constructor.php similarity index 97% rename from src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php rename to src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/Constructor.php index 620e69679..be1c3414d 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php +++ b/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/Constructor.php @@ -16,7 +16,7 @@ * and is licensed under the MIT license. */ -namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator; +namespace ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator; use ProxyManager\Generator\MethodGenerator; use ProxyManager\Generator\ParameterGenerator; diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/ConstructorTest.php similarity index 92% rename from tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php rename to tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/ConstructorTest.php index ed5618417..fca72a52c 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/ConstructorTest.php @@ -16,19 +16,19 @@ * and is licensed under the MIT license. */ -namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator; +namespace ProxyManagerTest\ProxyGenerator\ValueHolder\MethodGenerator; use PHPUnit_Framework_TestCase; -use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor; +use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\Constructor; use ReflectionClass; /** - * Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor} + * Tests for {@see \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\Constructor} * * @author Marco Pivetta * @license MIT * - * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor + * @covers \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\Constructor * @group Coverage */ class ConstructorTest extends PHPUnit_Framework_TestCase From e8ae065142b8d46ac1cd37f9d9b218d8f7217ef4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:39:20 +0200 Subject: [PATCH 90/99] PHP/HHVM compat should be checked via `method_exists()`, not via version checks --- .../MethodGenerator/BindProxyProperties.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php index 644061073..c18984d62 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/BindProxyProperties.php @@ -63,7 +63,7 @@ public function __construct( $localizedProperties = array(); foreach ($originalClass->getProperties() as $originalProperty) { - if ((PHP_VERSION_ID < 50400 || (defined('HHVM_VERSION'))) && $originalProperty->isPrivate()) { + if ((! method_exists('Closure', 'bind')) && $originalProperty->isPrivate()) { // @codeCoverageIgnoreStart throw UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty($originalProperty); // @codeCoverageIgnoreEnd From 05c9b17302f465ea8bc9c4fd7e27896b642c0992 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:48:14 +0200 Subject: [PATCH 91/99] CS fix - whitespace removal --- tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php b/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php index 95ffbdd84..29dac2c3c 100644 --- a/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php +++ b/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php @@ -81,7 +81,6 @@ public function testAddSignature() ->with(array('foo' => 'bar')) ->will($this->returnValue('PropertyName')); - $this->classSignatureGenerator->addSignature($classGenerator, array('foo' => 'bar')); } } From 3b996abf8f509594bcaae6d3e557640ac1190884 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:48:53 +0200 Subject: [PATCH 92/99] Removed unused import --- .../MethodGenerator/StaticProxyConstructorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php index 36588baf5..e1336754e 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/StaticProxyConstructorTest.php @@ -19,7 +19,6 @@ namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator; use PHPUnit_Framework_TestCase; -use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\StaticProxyConstructor; use ReflectionClass; From 62812b79496f461b7f4d459194c1d7db4fe01c87 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:49:21 +0200 Subject: [PATCH 93/99] CS fix - docblock alignment --- .../LazyLoadingValueHolder/MethodGenerator/MagicSleep.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php index 2c2e9438f..6933027c6 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php @@ -33,7 +33,7 @@ class MagicSleep extends MagicMethodGenerator /** * Constructor * - * @param ReflectionClass $originalClass + * @param ReflectionClass $originalClass * @param PropertyGenerator $initializerProperty * @param PropertyGenerator $valueHolderProperty */ From 57f78dbd8902f0fa7c87a500e5e5093ac29fd1d7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:49:48 +0200 Subject: [PATCH 94/99] CS fix - docblock alignment --- .../LazyLoadingValueHolder/MethodGenerator/MagicGet.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php index 84f6ee4c2..f0612e31d 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php @@ -36,9 +36,9 @@ class MagicGet extends MagicMethodGenerator /** * Constructor * - * @param ReflectionClass $originalClass - * @param PropertyGenerator $initializerProperty - * @param PropertyGenerator $valueHolderProperty + * @param ReflectionClass $originalClass + * @param PropertyGenerator $initializerProperty + * @param PropertyGenerator $valueHolderProperty * @param PublicPropertiesMap $publicProperties */ public function __construct( From 89d0519db5ca727db7019a2bd6eef37d2ed55182 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:50:01 +0200 Subject: [PATCH 95/99] CS fix - docblock alignment --- .../LazyLoadingValueHolder/MethodGenerator/MagicClone.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php index 0440b0fbd..4c3d9431f 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php @@ -33,7 +33,7 @@ class MagicClone extends MagicMethodGenerator /** * Constructor * - * @param ReflectionClass $originalClass + * @param ReflectionClass $originalClass * @param PropertyGenerator $initializerProperty * @param PropertyGenerator $valueHolderProperty */ From 0284096f25495174bb4a68120cb41d352019a9de Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 1 Oct 2014 22:50:21 +0200 Subject: [PATCH 96/99] CS fix - docblock alignment --- .../AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php index 85fcdfa4e..35a586f0a 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php @@ -38,7 +38,7 @@ class MagicUnset extends MagicMethodGenerator * Constructor * @param ReflectionClass $originalClass * @param PropertyGenerator $valueHolder - * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $prefixInterceptors * @param PropertyGenerator $suffixInterceptors * @param PublicPropertiesMap $publicProperties */ From 10d21fa86383293440c71cd75e2e12fc2b53cd9f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 14 Dec 2014 02:45:53 +0100 Subject: [PATCH 97/99] Importing used classes, optimizing imports --- src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php index 6e1fb27a6..ea61eb145 100644 --- a/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php +++ b/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php @@ -18,15 +18,15 @@ namespace ProxyManager\ProxyGenerator; -use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor; -use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty; use ProxyManager\Generator\Util\ClassGeneratorUtils; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; -use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet; use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset; +use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod; +use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor; +use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; use ReflectionClass; use ReflectionMethod; From cc610f3971ac956283bf400b21fdcbafd05c1974 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 14 Dec 2014 02:52:47 +0100 Subject: [PATCH 98/99] Add overriding constructor to the generated value holder proxy in order to initialize some proxy properties all the time --- .../ProxyGenerator/AccessInterceptorValueHolderGenerator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php index 4990430ab..40561391d 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php @@ -97,6 +97,7 @@ function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptor ProxiedMethodsFilter::getProxiedMethods($originalClass) ), array( + Constructor::generateMethod($originalClass, $valueHolder), new StaticProxyConstructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), new GetWrappedValueHolderValue($valueHolder), new SetMethodPrefixInterceptor($prefixInterceptors), From 15fcde73595df591548f7ed1a3da6a0753c83835 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 14 Dec 2014 02:56:03 +0100 Subject: [PATCH 99/99] `ClassGeneratorUtilsTest` is part of coverage tests --- .../ProxyManagerTest/Generator/Util/ClassGeneratorUtilsTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ProxyManagerTest/Generator/Util/ClassGeneratorUtilsTest.php b/tests/ProxyManagerTest/Generator/Util/ClassGeneratorUtilsTest.php index cf5254655..a8a752f57 100644 --- a/tests/ProxyManagerTest/Generator/Util/ClassGeneratorUtilsTest.php +++ b/tests/ProxyManagerTest/Generator/Util/ClassGeneratorUtilsTest.php @@ -29,6 +29,8 @@ * @license MIT * * @covers ProxyManager\Generator\Util\ClassGeneratorUtils + * + * @group Coverage */ class ClassGeneratorUtilsTest extends PHPUnit_Framework_TestCase {