/** * 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; }
public function parse($comment, ParserContext $context) { $docBlock = null; $errorMessage = ''; try { $docBlockContext = new DocBlock\Context($context->getNamespace(), $context->getAliases() ?: array()); $docBlock = new DocBlock((string) $comment, $docBlockContext); } catch (\Exception $e) { $errorMessage = $e->getMessage(); } $result = new DocBlockNode(); if ($errorMessage) { $result->addError($errorMessage); return $result; } $result->setShortDesc($docBlock->getShortDescription()); $result->setLongDesc((string) $docBlock->getLongDescription()); foreach ($docBlock->getTags() as $tag) { $result->addTag($tag->getName(), $this->parseTag($tag)); } return $result; }
public function testLeaveClassBeforeEnter() { $filter = new TrueFilter(); $docBlockParser = new DocBlockParser(); $prettyPrinter = new PrettyPrinter(); $context = new ParserContext($filter, $docBlockParser, $prettyPrinter); $class = new ClassReflection('C1', 1); $context->enterFile(null, null); // Leave a class before entering it $context->leaveClass(); // Genuinely enter and leave a class $context->enterClass($class); $context->leaveClass(); $classes = $context->leaveFile(); $this->assertContainsOnlyInstancesOf('Sami\\Reflection\\ClassReflection', $classes); }