Пример #1
0
 /**
  * Reads out configuration options from the doc comment of a class.
  * @param  ReflectionClass $class The class to examine.
  * @return array Like the output from getOptions()
  */
 protected function getOptionsFromClass(ReflectionClass $class)
 {
     $constructor = $class->getConstructor();
     $docComment = $constructor->getDocComment();
     if ($docComment !== false) {
         $filter = new TrueFilter();
         $parser = new DocBlockParser();
         $context = new ParserContext($filter, $parser, 'pretty printer');
         $context->enterNamespace('OOUI');
         $doc = $parser->parse($docComment, $context);
         $paramInfo = $doc->getTag('param');
         $output = array();
         foreach ($paramInfo as $param) {
             $matches = array();
             if (preg_match('/^config\\[\'([^\'\\]]+)\'\\]$/', $param[1], $matches)) {
                 $types = array_map(function ($type) {
                     return $type[0] . ($type[1] ? '[]' : '');
                 }, $param[0]);
                 $output[$matches[1]] = array('name' => $matches[1], 'types' => $types, 'description' => $param[2], 'class' => $class->getName());
             }
         }
     } else {
         $output = array();
     }
     $parentClass = $class->getParentClass();
     if ($parentClass) {
         $output = array_merge($this->getOptionsFromClass($parentClass), $output);
     }
     return $output;
 }
 /**
  * 
  * @param GenerationContext $context
  * @param \Nucleus\IService\CommandLine\Consolable $annotation
  */
 public function generate(GenerationContext $context, $annotation)
 {
     $docParser = new DocBlockParser();
     $serviceName = $context->getServiceName();
     $methodName = $context->getParsingContextName();
     $definition = $context->getContainerBuilder()->getDefinition($serviceName);
     $shortDesc = 'N/A';
     $reflectedMethod = new \ReflectionMethod($definition->getClass(), $methodName);
     $methodComment = $reflectedMethod->getDocComment();
     if ($methodComment !== false) {
         $docMethod = $docParser->parse($methodComment);
         $shortDesc = $docMethod->getShortDesc();
     }
     $paramsArray = array();
     $paramArrayComments = self::extractParamDocComment($docMethod->getTag('param'));
     foreach ($reflectedMethod->getParameters() as $reflectionParameter) {
         $paramComment = 'N/A';
         if (isset($paramArrayComments[$reflectionParameter->getName()])) {
             $paramComment = $paramArrayComments[$reflectionParameter->getName()]['comment'];
         }
         $paramsArray[$reflectionParameter->getName()]['optional'] = false;
         if ($reflectionParameter->isDefaultValueAvailable()) {
             $paramsArray[$reflectionParameter->getName()]['optional'] = true;
         }
         $paramsArray[$reflectionParameter->getName()]['comment'] = $paramComment;
     }
     if (!empty($annotation->name)) {
         $name = $annotation->name;
     } else {
         $name = $serviceName . ':' . $methodName;
     }
     $context->getContainerBuilder()->getDefinition("console")->addMethodCall("addCommand", array("applicatiomName" => $name, "serviceName" => $serviceName, "methodName" => $methodName, "shortDesc" => $shortDesc, "paramsMethod" => $paramsArray));
 }
Пример #3
0
 /**
  * @dataProvider getParseTests
  */
 public function testParse($comment, $expected)
 {
     $parser = new DocBlockParser();
     $this->assertEquals($this->createDocblock($expected), $parser->parse($comment, $this->getContextMock()));
 }
Пример #4
0
Файл: Php.php Проект: layla/cody
 protected function parseDocBlock($comment)
 {
     $parser = new DocBlockParser();
     return $parser->parse($comment);
 }