/** * Retrieve all optional parameters names. * * @param ReflectionMethod $methodReflection * @return array */ protected function _getOptionalParamNames(ReflectionMethod $methodReflection) { $optionalParamNames = array(); $methodInterfaces = $methodReflection->getPrototypes(); /** Take the fullest interface that includes optional parameters also. */ /** @var \Zend\Server\Reflection\Prototype $methodInterface */ $methodInterface = end($methodInterfaces); $methodParams = $methodInterface->getParameters(); /** @var ReflectionParameter $paramReflection */ foreach ($methodParams as $paramReflection) { if ($paramReflection->isOptional()) { $optionalParamNames[] = $paramReflection->getName(); } } return $optionalParamNames; }
/** * Retrieve method interface and documentation description. * * @param ReflectionMethod $method * @return array * @throws \InvalidArgumentException */ public function extractMethodData(ReflectionMethod $method) { $methodData = array('documentation' => $method->getDescription(), 'interface' => array()); $prototypes = $method->getPrototypes(); /** Take the fullest interface that also includes optional parameters. */ /** @var \Zend\Server\Reflection\Prototype $prototype */ $prototype = end($prototypes); /** @var \Zend\Server\Reflection\ReflectionParameter $parameter */ foreach ($prototype->getParameters() as $parameter) { $parameterData = array('type' => $this->_typeProcessor->process($parameter->getType()), 'required' => !$parameter->isOptional(), 'documentation' => $parameter->getDescription()); if ($parameter->isOptional()) { $parameterData['default'] = $parameter->getDefaultValue(); } $methodData['interface']['in']['parameters'][$parameter->getName()] = $parameterData; } if ($prototype->getReturnType() != 'void' && $prototype->getReturnType() != 'null') { $methodData['interface']['out']['parameters']['result'] = array('type' => $this->_typeProcessor->process($prototype->getReturnType()), 'documentation' => $prototype->getReturnValue()->getDescription(), 'required' => true); } return $methodData; }