Exemplo n.º 1
0
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessageRegExp /@param annotation is incorrect for the parameter "name" \w+/
  */
 public function testGetParamType()
 {
     $class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
     $methodReflection = $class->getMethod('setName');
     $paramsReflection = $methodReflection->getParameters();
     $this->_typeProcessor->getParamType($paramsReflection[0]);
 }
Exemplo n.º 2
0
 /**
  * Retrieve method interface and documentation description.
  *
  * @param \Zend\Code\Reflection\MethodReflection $method
  * @return array
  * @throws \InvalidArgumentException
  */
 public function extractMethodData(\Zend\Code\Reflection\MethodReflection $method)
 {
     $methodData = ['documentation' => $this->extractMethodDescription($method), 'interface' => []];
     /** @var \Zend\Code\Reflection\ParameterReflection $parameter */
     foreach ($method->getParameters() as $parameter) {
         $parameterData = ['type' => $this->_typeProcessor->register($this->_typeProcessor->getParamType($parameter)), 'required' => !$parameter->isOptional(), 'documentation' => $this->_typeProcessor->getParamDescription($parameter)];
         if ($parameter->isOptional()) {
             $parameterData['default'] = $parameter->getDefaultValue();
         }
         $methodData['interface']['in']['parameters'][$parameter->getName()] = $parameterData;
     }
     $returnType = $this->_typeProcessor->getGetterReturnType($method);
     if ($returnType != 'void' && $returnType != 'null') {
         $methodData['interface']['out']['parameters']['result'] = ['type' => $this->_typeProcessor->register($returnType['type']), 'documentation' => $returnType['description'], 'required' => true];
     }
     return $methodData;
 }
Exemplo n.º 3
0
 /**
  * Retrieve requested service method params metadata.
  *
  * @param string $serviceClassName
  * @param string $serviceMethodName
  * @return array
  */
 public function getMethodParams($serviceClassName, $serviceMethodName)
 {
     $cacheId = self::SERVICE_METHOD_PARAMS_CACHE_PREFIX . hash('md5', $serviceClassName . $serviceMethodName);
     $params = $this->cache->load($cacheId);
     if ($params !== false) {
         return unserialize($params);
     }
     $serviceClass = new ClassReflection($serviceClassName);
     /** @var MethodReflection $serviceMethod */
     $serviceMethod = $serviceClass->getMethod($serviceMethodName);
     $params = [];
     /** @var ParameterReflection $paramReflection */
     foreach ($serviceMethod->getParameters() as $paramReflection) {
         $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable();
         $params[] = [self::METHOD_META_NAME => $paramReflection->getName(), self::METHOD_META_TYPE => $this->typeProcessor->getParamType($paramReflection), self::METHOD_META_HAS_DEFAULT_VALUE => $isDefaultValueAvailable, self::METHOD_META_DEFAULT_VALUE => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null];
     }
     $this->cache->save(serialize($params), $cacheId, [ReflectionCache::CACHE_TAG]);
     return $params;
 }
Exemplo n.º 4
0
 /**
  * Retrieve requested service method params metadata.
  *
  * @param string $serviceClassName
  * @param string $serviceMethodName
  * @return array
  */
 protected function getMethodParams($serviceClassName, $serviceMethodName)
 {
     $cacheId = self::CACHE_ID_PREFIX . hash('md5', $serviceClassName . $serviceMethodName);
     $params = $this->cache->load($cacheId);
     if ($params !== false) {
         return unserialize($params);
     }
     $serviceClass = new ClassReflection($serviceClassName);
     /** @var MethodReflection $serviceMethod */
     $serviceMethod = $serviceClass->getMethod($serviceMethodName);
     $params = [];
     /** @var ParameterReflection $paramReflection */
     foreach ($serviceMethod->getParameters() as $paramReflection) {
         $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable();
         $params[] = ['name' => $paramReflection->getName(), 'type' => $this->typeProcessor->getParamType($paramReflection), 'isDefaultValueAvailable' => $isDefaultValueAvailable, 'defaultValue' => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null];
     }
     $this->cache->save(serialize($params), $cacheId, [WebapiCache::CACHE_TAG]);
     return $params;
 }