public function testExtractMethodData() { $classReflection = new \Zend\Server\Reflection\ReflectionClass(new \ReflectionClass('\\Magento\\Webapi\\Test\\Unit\\Model\\Config\\TestServiceForClassReflector')); /** @var $methodReflection ReflectionMethod */ $methodReflection = $classReflection->getMethods()[0]; $methodData = $this->_classReflector->extractMethodData($methodReflection); $expectedResponse = $this->_getSampleReflectionData(); $this->assertEquals($expectedResponse, $methodData); }
/** * Reflect methods in given class and set retrieved data into reader. * * @param string $className * @param array $methods * @return array <pre>array( * $firstMethod => array( * 'documentation' => $methodDocumentation, * 'interface' => array( * 'in' => array( * 'parameters' => array( * $firstParameter => array( * 'type' => $type, * 'required' => $isRequired, * 'documentation' => $parameterDocumentation * ), * ... * ) * ), * 'out' => array( * 'parameters' => array( * $firstParameter => array( * 'type' => $type, * 'required' => $isRequired, * 'documentation' => $parameterDocumentation * ), * ... * ) * ) * ) * ), * ... * )</pre> */ public function reflectClassMethods($className, $methods) { $data = array(); $classReflection = new \Zend\Server\Reflection\ReflectionClass(new \ReflectionClass($className)); /** @var $methodReflection ReflectionMethod */ foreach ($classReflection->getMethods() as $methodReflection) { $methodName = $methodReflection->getName(); if (array_key_exists($methodName, $methods)) { $data[$methodName] = $this->extractMethodData($methodReflection); } } return $data; }
/** * Wakeup from serialization * * Reflection needs explicit instantiation to work correctly. Re-instantiate * reflection object on wakeup. * * @return void */ public function __wakeup() { $this->_classReflection = new ReflectionClass(new \ReflectionClass($this->_class), $this->getNamespace(), $this->getInvokeArguments()); $this->_reflection = new \ReflectionMethod($this->_classReflection->getName(), $this->getName()); }