/** * @group ZF2-110 */ public function testDocBlockScannerParsesTagsWithNoValuesProperly() { $docComment = <<<EOB /** * @mytag */ EOB; $tokenScanner = new DocBlockScanner($docComment); $tags = $tokenScanner->getTags(); $this->assertCount(1, $tags); $this->assertArrayHasKey('name', $tags[0]); $this->assertEquals('@mytag', $tags[0]['name']); $this->assertArrayHasKey('value', $tags[0]); $this->assertEquals('', $tags[0]['value']); }
public function testDocBlockScannerDescriptions() { $docComment = <<<EOB /** * Short Description * * Long Description * continued in the second line */ EOB; $tokenScanner = new DocBlockScanner($docComment); $this->assertEquals('Short Description', $tokenScanner->getShortDescription()); $this->assertEquals('Long Description continued in the second line', $tokenScanner->getLongDescription()); // windows-style line separators $docComment = str_replace("\n", "\r\n", $docComment); $tokenScanner = new DocBlockScanner($docComment); $this->assertEquals('Short Description', $tokenScanner->getShortDescription()); $this->assertEquals('Long Description continued in the second line', $tokenScanner->getLongDescription()); }
/** * Parse the DocBlock * * @return void */ protected function reflect() { if ($this->isReflected) { return; } $docComment = $this->docComment; // localize variable // create a clean docComment $this->cleanDocComment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $docComment); $this->cleanDocComment = ltrim($this->cleanDocComment, "\r\n"); // @todo should be changed to remove first and last empty line $scanner = new DocBlockScanner($docComment); $this->shortDescription = ltrim($scanner->getShortDescription()); $this->longDescription = ltrim($scanner->getLongDescription()); foreach ($scanner->getTags() as $tag) { $this->tags[] = $this->tagManager->createTag(ltrim($tag['name'], '@'), ltrim($tag['value'])); } $this->isReflected = true; }
/** * 检索指定目录下的全部资源到数据库中 */ private function addResource() { $this->_resource->remove(array()); $scaner = new DirectoryScanner(); $scaner->addDirectory(ROOT_PATH . '/module/Application/src/Application/Controller/'); $scaner->addDirectory(ROOT_PATH . '/module/Idatabase/src/Idatabase/Controller/'); foreach ($scaner->getClasses(true) as $classScanner) { $className = $classScanner->getName(); foreach ($classScanner->getMethods(true) as $method) { if ($this->endsWith($method->getName(), 'Action')) { $actionName = $method->getName(); $docComment = $method->getDocComment(); $docBlockScanner = new DocBlockScanner($docComment); $docAtName = $this->getDocNameValue($docBlockScanner->getTags()); // 写入数据库 $classInfo = $this->parseClassName($className); $this->_resource->insert(array('name' => $docAtName, 'alias' => $className . '\\' . $actionName, 'namespace' => $classInfo['namespace'], 'controller' => $classInfo['controller'], 'action' => $this->parseMethodName($actionName))); } } } }
/** * Parse the docblock * * @return void */ protected function reflect() { if ($this->isReflected) { return; } $docComment = $this->docComment; // localize variable // First remove doc block line starters $docComment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $docComment); $docComment = ltrim($docComment, "\r\n"); // @todo should be changed to remove first and last empty line $this->cleanDocComment = $docComment; $scanner = new DocBlockScanner($docComment, $this->annotationManager); $this->shortDescription = $scanner->getShortDescription(); $this->longDescription = $scanner->getLongDescription(); $this->tags = $scanner->getTags(); if ($this->annotationManager) { $this->annotations = $scanner->getAnnotations(); } $this->isReflected = true; }