From 2be28f6d9f168278dab24f0a254b9964ca2c685c Mon Sep 17 00:00:00 2001 From: Maks3w Date: Sun, 28 Oct 2012 21:23:26 +0100 Subject: [PATCH 1/2] [Server] Remove code specific for PHP 5.1 --- src/Reflection/AbstractFunction.php | 14 +++----------- test/Reflection/ReflectionFunctionTest.php | 10 ---------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/Reflection/AbstractFunction.php b/src/Reflection/AbstractFunction.php index 66078019..aa8cfa44 100644 --- a/src/Reflection/AbstractFunction.php +++ b/src/Reflection/AbstractFunction.php @@ -27,7 +27,7 @@ abstract class AbstractFunction { /** - * @var ReflectionFunction + * @var \ReflectionFunctionAbstract */ protected $reflection; @@ -79,22 +79,14 @@ abstract class AbstractFunction /** * Constructor * - * @param \Reflector $r + * @param \ReflectionFunctionAbstract $r * @param null|string $namespace * @param null|array $argv * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ - public function __construct(\Reflector $r, $namespace = null, $argv = array()) + public function __construct(\ReflectionFunctionAbstract $r, $namespace = null, $argv = array()) { - // In PHP 5.1.x, ReflectionMethod extends ReflectionFunction. In 5.2.x, - // both extend ReflectionFunctionAbstract. So, we can't do normal type - // hinting in the prototype, but instead need to do some explicit - // testing here. - if ((!$r instanceof \ReflectionFunction) - && (!$r instanceof \ReflectionMethod)) { - throw new Exception\InvalidArgumentException('Invalid reflection class'); - } $this->reflection = $r; // Determine namespace diff --git a/test/Reflection/ReflectionFunctionTest.php b/test/Reflection/ReflectionFunctionTest.php index 30d3a136..17701ce2 100644 --- a/test/Reflection/ReflectionFunctionTest.php +++ b/test/Reflection/ReflectionFunctionTest.php @@ -41,16 +41,6 @@ public function test__construct() $this->assertTrue(0 < count($prototypes)); } - public function testConstructorThrowsExceptionOnNonFunction() - { - $function = new \ReflectionFunction('\ZendTest\Server\Reflection\function1'); - $r = new Reflection\ReflectionFunction($function); - $params = $r->getParameters(); - - $this->setExpectedException('Zend\Server\Reflection\Exception\InvalidArgumentException', 'Invalid reflection class'); - $r = new Reflection\ReflectionFunction($params[0]); - } - public function test__getSet() { $function = new \ReflectionFunction('\ZendTest\Server\Reflection\function1'); From 33f38e015f57e6fd67a4737bdb67e69de7119d5e Mon Sep 17 00:00:00 2001 From: Maks3w Date: Tue, 30 Oct 2012 22:37:33 +0100 Subject: [PATCH 2/2] Review Feedback --- src/Reflection/AbstractFunction.php | 21 +++++++++++++-------- src/Reflection/ReflectionClass.php | 10 ++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Reflection/AbstractFunction.php b/src/Reflection/AbstractFunction.php index aa8cfa44..423f0f3d 100644 --- a/src/Reflection/AbstractFunction.php +++ b/src/Reflection/AbstractFunction.php @@ -10,6 +10,11 @@ namespace Zend\Server\Reflection; +use ReflectionFunctionAbstract; +use ReflectionClass as PhpReflectionClass; +use ReflectionFunction as PhpReflectionFunction; +use ReflectionMethod as PhpReflectionMethod; + /** * Function/Method Reflection * @@ -27,7 +32,7 @@ abstract class AbstractFunction { /** - * @var \ReflectionFunctionAbstract + * @var ReflectionFunctionAbstract */ protected $reflection; @@ -79,13 +84,13 @@ abstract class AbstractFunction /** * Constructor * - * @param \ReflectionFunctionAbstract $r + * @param ReflectionFunctionAbstract $r * @param null|string $namespace * @param null|array $argv * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ - public function __construct(\ReflectionFunctionAbstract $r, $namespace = null, $argv = array()) + public function __construct(ReflectionFunctionAbstract $r, $namespace = null, $argv = array()) { $this->reflection = $r; @@ -100,7 +105,7 @@ public function __construct(\ReflectionFunctionAbstract $r, $namespace = null, $ } // If method call, need to store some info on the class - if ($r instanceof \ReflectionMethod) { + if ($r instanceof PhpReflectionMethod) { $this->class = $r->getDeclaringClass()->getName(); } @@ -467,11 +472,11 @@ public function getInvokeArguments() */ public function __wakeup() { - if ($this->reflection instanceof \ReflectionMethod) { - $class = new \ReflectionClass($this->class); - $this->reflection = new \ReflectionMethod($class->newInstance(), $this->getName()); + if ($this->reflection instanceof PhpReflectionMethod) { + $class = new PhpReflectionClass($this->class); + $this->reflection = new PhpReflectionMethod($class->newInstance(), $this->getName()); } else { - $this->reflection = new \ReflectionFunction($this->getName()); + $this->reflection = new PhpReflectionFunction($this->getName()); } } } diff --git a/src/Reflection/ReflectionClass.php b/src/Reflection/ReflectionClass.php index f7da7477..eb7b770d 100644 --- a/src/Reflection/ReflectionClass.php +++ b/src/Reflection/ReflectionClass.php @@ -10,6 +10,8 @@ namespace Zend\Server\Reflection; +use ReflectionClass as PhpReflectionClass; + /** * Class/Object reflection * @@ -43,7 +45,7 @@ class ReflectionClass /** * ReflectionClass object - * @var \ReflectionClass + * @var PhpReflectionClass */ protected $reflection; @@ -53,11 +55,11 @@ class ReflectionClass * Create array of dispatchable methods, each a * {@link Zend\Server\Reflection\ReflectionMethod}. Sets reflection object property. * - * @param \ReflectionClass $reflection + * @param PhpReflectionClass $reflection * @param string $namespace * @param mixed $argv */ - public function __construct(\ReflectionClass $reflection, $namespace = null, $argv = false) + public function __construct(PhpReflectionClass $reflection, $namespace = null, $argv = false) { $this->reflection = $reflection; $this->setNamespace($namespace); @@ -176,6 +178,6 @@ public function setNamespace($namespace) */ public function __wakeup() { - $this->reflection = new \ReflectionClass($this->getName()); + $this->reflection = new PhpReflectionClass($this->getName()); } }