Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setOverwriteExistingMethods($flag)
* @param array|\Zend\Server\Method\Definition $method
* @param null|string $name
* @return \Zend\Server\Definition
* @throws \Zend\Server\Exception\ExceptionInterface if duplicate or invalid method provided
* @throws \Zend\Server\Exception\InvalidArgumentException if duplicate or invalid method provided
*/
public function addMethod($method, $name = null)
{
Expand Down Expand Up @@ -235,7 +235,7 @@ public function next()
*/
public function rewind()
{
return reset($this->methods);
reset($this->methods);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Reflection
* method name (used for the signature key). Primarily to avoid collisions,
* also for XmlRpc namespacing
* @return \Zend\Server\Reflection\ReflectionClass
* @throws \Zend\Server\Reflection\Exception\ExceptionInterface
* @throws \Zend\Server\Reflection\Exception\InvalidArgumentException
*/
public static function reflectClass($class, $argv = false, $namespace = '')
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public static function reflectClass($class, $argv = false, $namespace = '')
* function name (used for the signature key). Primarily to avoid
* collisions, also for XmlRpc namespacing
* @return \Zend\Server\Reflection\ReflectionFunction
* @throws \Zend\Server\Reflection\Exception\ExceptionInterface
* @throws \Zend\Server\Reflection\Exception\InvalidArgumentException
*/
public static function reflectFunction($function, $argv = false, $namespace = '')
{
Expand Down
31 changes: 14 additions & 17 deletions src/Reflection/AbstractFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -27,7 +32,7 @@
abstract class AbstractFunction
{
/**
* @var ReflectionFunction
* @var ReflectionFunctionAbstract
*/
protected $reflection;

Expand Down Expand Up @@ -79,22 +84,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
Expand All @@ -108,7 +105,7 @@ public function __construct(\Reflector $r, $namespace = null, $argv = array())
}

// If method call, need to store some info on the class
if ($r instanceof \ReflectionMethod) {
if ($r instanceof PhpReflectionMethod) {
$this->class = $r->getDeclaringClass()->getName();
}

Expand Down Expand Up @@ -448,7 +445,7 @@ public function getDescription()
* Retrieve all prototypes as array of
* {@link \Zend\Server\Reflection\Prototype}s
*
* @return array
* @return Prototype[]
*/
public function getPrototypes()
{
Expand All @@ -475,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());
}
}
}
22 changes: 9 additions & 13 deletions src/Reflection/Prototype.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,23 @@
*/
class Prototype
{
/** @var ReflectionParameter[] */
protected $params;

/**
* Constructor
*
* @param ReflectionReturnValue $return
* @param array $params
* @param ReflectionParameter[] $params
* @throws Exception\InvalidArgumentException
*/
public function __construct(ReflectionReturnValue $return, $params = null)
public function __construct(ReflectionReturnValue $return, array $params = array())
{
$this->return = $return;

if (!is_array($params) && (null !== $params)) {
throw new Exception\InvalidArgumentException('Invalid parameters');
}

if (is_array($params)) {
foreach ($params as $param) {
if (!$param instanceof ReflectionParameter) {
throw new Exception\InvalidArgumentException('One or more params are invalid');
}
foreach ($params as $param) {
if (!$param instanceof ReflectionParameter) {
throw new Exception\InvalidArgumentException('One or more params are invalid');
}
}

Expand All @@ -60,7 +57,6 @@ public function getReturnType()
/**
* Retrieve the return value object
*
* @access public
* @return \Zend\Server\Reflection\ReflectionReturnValue
*/
public function getReturnValue()
Expand All @@ -71,7 +67,7 @@ public function getReturnValue()
/**
* Retrieve method parameters
*
* @return array Array of {@link \Zend\Server\Reflection\ReflectionParameter}s
* @return ReflectionParameter[] Array of {@link \Zend\Server\Reflection\ReflectionParameter}s
*/
public function getParameters()
{
Expand Down
10 changes: 6 additions & 4 deletions src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Zend\Server\Reflection;

use ReflectionClass as PhpReflectionClass;

/**
* Class/Object reflection
*
Expand Down Expand Up @@ -43,7 +45,7 @@ class ReflectionClass

/**
* ReflectionClass object
* @var ReflectionClass
* @var PhpReflectionClass
*/
protected $reflection;

Expand All @@ -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);
Expand Down Expand Up @@ -176,6 +178,6 @@ public function setNamespace($namespace)
*/
public function __wakeup()
{
$this->reflection = new \ReflectionClass($this->getName());
$this->reflection = new PhpReflectionClass($this->getName());
}
}
2 changes: 1 addition & 1 deletion src/Reflection/ReflectionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class ReflectionParameter
{
/**
* @var ReflectionParameter
* @var \ReflectionParameter
*/
protected $reflection;

Expand Down
2 changes: 1 addition & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function fault($fault = null, $code = 404);
/**
* Handle a request
*
* Requests may be passed in, or the server may automagically determine the
* Requests may be passed in, or the server may automatically determine the
* request based on defaults. Dispatches server request to appropriate
* method and returns a response
*
Expand Down
6 changes: 0 additions & 6 deletions test/Reflection/PrototypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ public function testConstructionThrowsExceptionOnInvalidParam()
$r1 = new Reflection\Prototype($this->_r->getReturnValue(), $this->_parametersRaw);
}

public function testConstructionThrowsExceptionOnInvalidParamType()
{
$this->setExpectedException('Zend\Server\Reflection\Exception\InvalidArgumentException', 'Invalid parameters');
$r1 = new Reflection\Prototype($this->_r->getReturnValue(), 'string');
}

/**
* getReturnType() test
*
Expand Down
10 changes: 0 additions & 10 deletions test/Reflection/ReflectionFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit bcb55be

Please # to comment.