Пример #1
0
 /**
  * Retrieve class full documentation description.
  *
  * @param string $className
  * @return string
  */
 public function extractClassDescription($className)
 {
     $classReflection = new \Zend\Code\Reflection\ClassReflection($className);
     $docBlock = $classReflection->getDocBlock();
     if (!$docBlock) {
         return '';
     }
     return $this->_typeProcessor->getDescription($docBlock);
 }
Пример #2
0
 /**
  * Analyze given type and return methods meta data (name, return type, description, etc.)
  *
  * @param string $type
  * @return \Praxigento\Core\Reflection\Data\Method[]
  */
 public function getMethods($type)
 {
     $result = [];
     $typeNorm = $this->_toolsType->normalizeType($type);
     /** @var \Zend\Code\Reflection\ClassReflection $reflection */
     $reflection = new \Zend\Code\Reflection\ClassReflection($typeNorm);
     /** @var \Zend\Code\Reflection\DocBlockReflection $docBlock */
     $docBlock = $reflection->getDocBlock();
     $annotatedMethods = $this->_processClassDocBlock($docBlock);
     /* process normal methods (not annotated) */
     $publicMethods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
     $generalMethods = $this->_processClassMethods($publicMethods);
     $merged = array_merge($generalMethods, $annotatedMethods);
     /* convert results to array form according Magento requirements to be saved in the cache */
     /** @var \Praxigento\Core\Reflection\Data\Method $item */
     foreach ($merged as $item) {
         $methodName = $item->getName();
         $entry = ['type' => $item->getType(), 'isRequired' => $item->getIsRequired(), 'description' => $item->getDescription(), 'parameterCount' => $item->getParameterCount()];
         $result[$methodName] = $entry;
     }
     return $result;
 }
 /**
  * Analyze $type and save type properties into the registry.
  *
  * @param string $type
  * @return \Praxigento\Core\Reflection\Data\Property[] array with type properties or empty array for simple types.
  */
 public function register($type)
 {
     $typeNorm = $this->_toolsType->normalizeType($type);
     $isSimple = $this->_typeProcessor->isTypeSimple($typeNorm);
     if (!isset($this->_registry[$typeNorm])) {
         if (!$isSimple) {
             /* analyze properties for complex type */
             $this->_registry[$typeNorm] = [];
             /* process annotated methods */
             /** @var \Zend\Code\Reflection\ClassReflection $reflection */
             $reflection = new \Zend\Code\Reflection\ClassReflection($typeNorm);
             $docBlock = $reflection->getDocBlock();
             if ($docBlock) {
                 $this->_processDocBlock($typeNorm, $docBlock);
             }
             /* process normal methods (not annotated) */
             $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
             $this->_processMethods($typeNorm, $methods);
         } else {
             /* this is simple type w/o props */
             $this->_registry[$typeNorm] = [];
         }
     }
     return $this->_registry[$typeNorm];
 }
Пример #4
0
 public function discover()
 {
     $annotationReader = $this->container->get('annotation_reader');
     /* @var $annotationReader \Doctrine\Common\Annotations\AnnotationReader */
     foreach ($this->services as $serviceName) {
         $service = $this->container->get($serviceName);
         $rService = new \Zend\Code\Reflection\ClassReflection($service);
         $jsonrpcMethods[$serviceName]['service'] = $serviceName;
         $jsonrpcMethods[$serviceName]['description'] = !$rService->getDocBlock() ?: $rService->getDocBlock()->getShortDescription();
         foreach ($rService->getMethods(\ReflectionMethod::IS_PUBLIC) as $rMethod) {
             if (strpos($rMethod->getName(), '__') !== 0) {
                 $currentMethod = [];
                 $_tagsParam = !$rMethod->getDocBlock() ? [] : $rMethod->getDocBlock()->getTags('param');
                 $_tagsReturn = !$rMethod->getDocBlock() ? null : $rMethod->getDocBlock()->getTag('return');
                 /* @var $_tagsParam ParamTag[] */
                 /* @var $_tagsReturn ReturnTag */
                 $currentMethod['method'] = "{$serviceName}:" . $rMethod->getName();
                 $currentMethod['description'] = !$rMethod->getDocBlock() ?: $rMethod->getDocBlock()->getShortDescription();
                 $currentMethod['parameters'] = [];
                 if (!empty($_tagsParam)) {
                     foreach ($_tagsParam as $_tagParam) {
                         if (strpos($_tagParam->getVariableName(), '$') === 0) {
                             $_name = substr($_tagParam->getVariableName(), 1);
                         } else {
                             $_name = $_tagParam->getVariableName();
                         }
                         $currentMethod['parameters'][$_name] = ['description' => $_tagParam->getDescription(), 'types' => count($_tagParam->getTypes()) == 1 ? $_tagParam->getTypes()[0] : $_tagParam->getTypes()];
                     }
                 }
                 foreach ($rMethod->getParameters() as $rParameter) {
                     if (!isset($currentMethod['parameters'][$rParameter->getName()])) {
                         $currentMethod['parameters'][$rParameter->getName()] = [];
                     }
                     $currentMethod['parameters'][$rParameter->getName()] = array_merge($currentMethod['parameters'][$rParameter->getName()], ['nullable' => $rParameter->allowsNull(), 'optional' => $rParameter->isOptional()]);
                     if ($rParameter->isDefaultValueAvailable()) {
                         $currentMethod['parameters'][$rParameter->getName()]['default'] = $rParameter->getDefaultValue();
                     }
                 }
                 if ($_tagsReturn) {
                     $currentMethod['return'] = ['description' => $_tagsReturn->getDescription(), 'types' => count($_tagsReturn->getTypes()) == 1 ? $_tagsReturn->getTypes()[0] : $_tagsReturn->getTypes()];
                 }
                 $jsonrpcMethods[$serviceName]['methods'][$rMethod->getName()] = $currentMethod;
             }
         }
     }
     return new Response(json_encode($jsonrpcMethods), 200, ['Content-Type' => 'application/json']);
 }