/** * Constructor * * Create array of dispatchable methods, each a * {@link Zend\Server\Reflection\ReflectionMethod}. Sets reflection object property. * * @param PhpReflectionClass $reflection * @param string $namespace * @param mixed $argv */ public function __construct(PhpReflectionClass $reflection, $namespace = null, $argv = false) { $this->reflection = $reflection; $this->setNamespace($namespace); foreach ($reflection->getMethods() as $method) { // Don't aggregate magic methods if ('__' == substr($method->getName(), 0, 2)) { continue; } if ($method->isPublic()) { // Get signatures and description $this->methods[] = new ReflectionMethod($this, $method, $this->getNamespace(), $argv); } } }
/** * Wakeup from serialization * * Reflection needs explicit instantiation to work correctly. Re-instantiate * reflection object on wakeup. * * @return void */ public function __wakeup() { if ($this->reflection instanceof PhpReflectionMethod) { $class = new PhpReflectionClass($this->class); $this->reflection = new PhpReflectionMethod($class->newInstance(), $this->getName()); } else { $this->reflection = new PhpReflectionFunction($this->getName()); } }
/** * Build XML service description from reflection class * * @param \Zend\Server\Reflection\ReflectionClass $refclass * @param DOMElement $target target XML element * @return void */ protected function _addService(ServerReflectionClass $refclass, \DOMElement $target) { foreach ($refclass->getMethods() as $method) { if (!$method->isPublic() || $method->isConstructor() || '__' == substr($method->name, 0, 2)) { continue; } foreach ($method->getPrototypes() as $proto) { $op = $this->_xml->createElement('operation'); $op->setAttribute('name', $method->getName()); $rettype = $this->_registerType($proto->getReturnType()); $op->setAttribute('returnType', $rettype); foreach ($proto->getParameters() as $param) { $arg = $this->_xml->createElement('argument'); $arg->setAttribute('name', $param->getName()); $type = $param->getType(); if ($type == 'mixed' && ($pclass = $param->getClass())) { $type = $pclass->getName(); } $ptype = $this->_registerType($type); $arg->setAttribute('type', $ptype); if ($param->isDefaultValueAvailable()) { $arg->setAttribute('defaultvalue', $param->getDefaultValue()); } $op->appendChild($arg); } $target->appendChild($op); } } }
/** * namespace test */ public function testGetNamespace() { $r = new Reflection\ReflectionClass(new \ReflectionClass('\\Zend\\Server\\Reflection')); $this->assertEquals('', $r->getNamespace()); $r->setNamespace('namespace'); $this->assertEquals('namespace', $r->getNamespace()); }
/** * @param $object * @param $methodName * @param array $parameters * @return mixed */ protected function overrideMethod(&$object, $methodName, array $parameters = []) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); return $method->invokeArgs($object, $parameters); }
public function testGetEventManagerByDefault() { $server = new Server($this->getApplicationServiceLocator(), []); $ref_server = new \ReflectionClass('JRpc\\Json\\Server\\Server'); $ref_events = $ref_server->getProperty('events'); $ref_events->setAccessible(true); $out = $server->getEventManager(); $this->assertInstanceOf('Zend\\EventManager\\EventManagerInterface', $out); $this->assertEquals($out, $ref_events->getValue($server)); }