当前位置: 首页>>代码示例>>PHP>>正文


PHP DocBlock::getTags方法代码示例

本文整理汇总了PHP中phpDocumentor\Reflection\DocBlock::getTags方法的典型用法代码示例。如果您正苦于以下问题:PHP DocBlock::getTags方法的具体用法?PHP DocBlock::getTags怎么用?PHP DocBlock::getTags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在phpDocumentor\Reflection\DocBlock的用法示例。


在下文中一共展示了DocBlock::getTags方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createPhpDocs

 /**
  * @param string $class
  * @return string
  */
 protected function createPhpDocs($class)
 {
     $reflection = new \ReflectionClass($class);
     $namespace = $reflection->getNamespaceName();
     $classname = $reflection->getShortName();
     $originalDoc = $reflection->getDocComment();
     if ($this->reset) {
         $phpdoc = new DocBlock('', new Context($namespace));
     } else {
         $phpdoc = new DocBlock($reflection, new Context($namespace));
     }
     if (!$phpdoc->getText()) {
         $phpdoc->setText($class);
     }
     $properties = array();
     $methods = array();
     foreach ($phpdoc->getTags() as $tag) {
         $name = $tag->getName();
         if ($name == "property" || $name == "property-read" || $name == "property-write") {
             $properties[] = $tag->getVariableName();
         } elseif ($name == "method") {
             $methods[] = $tag->getMethodName();
         }
     }
     foreach ($this->properties as $name => $property) {
         $name = "\${$name}";
         if (in_array($name, $properties)) {
             continue;
         }
         if ($property['read'] && $property['write']) {
             $attr = 'property';
         } elseif ($property['write']) {
             $attr = 'property-write';
         } else {
             $attr = 'property-read';
         }
         $tag = Tag::createInstance("@{$attr} {$property['type']} {$name} {$property['comment']}", $phpdoc);
         $phpdoc->appendTag($tag);
     }
     foreach ($this->methods as $name => $method) {
         if (in_array($name, $methods)) {
             continue;
         }
         $arguments = implode(', ', $method['arguments']);
         $tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments})", $phpdoc);
         $phpdoc->appendTag($tag);
     }
     $serializer = new DocBlockSerializer();
     $serializer->getDocComment($phpdoc);
     $docComment = $serializer->getDocComment($phpdoc);
     if ($this->write) {
         $filename = $reflection->getFileName();
         $contents = \File::get($filename);
         if ($originalDoc) {
             $contents = str_replace($originalDoc, $docComment, $contents);
         } else {
             $needle = "class {$classname}";
             $replace = "{$docComment}\nclass {$classname}";
             $pos = strpos($contents, $needle);
             if ($pos !== false) {
                 $contents = substr_replace($contents, $replace, $pos, strlen($needle));
             }
         }
         if (\File::put($filename, $contents)) {
             $this->info('Written new phpDocBlock to ' . $filename);
         }
     }
     $output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} {}\n}\n\n";
     return $output;
 }
开发者ID:pacho104,项目名称:redbpim,代码行数:74,代码来源:ModelsCommand.php

示例2: getExistingTags

 /**
  * @return DocBlock\Tag[]
  */
 public function getExistingTags()
 {
     $existing = $this->getExistingDocBlock();
     $docBlock = $this->removeOldStyleDocBlock($existing);
     $docBlock = new DocBlock($docBlock);
     return $docBlock->getTags();
 }
开发者ID:axyr,项目名称:silverstripe-ideannotator,代码行数:10,代码来源:DocBlockGenerator.php

示例3: parseDoc

 /**
  * Parses doc comment and populates comment entity
  *
  * @param string $text
  */
 protected function parseDoc(Comment $comment, $text)
 {
     $context = $this->getContext();
     try {
         $block = new DocBlock($text, $context);
         foreach ($block->getTags() as $tag) {
             switch ($tag->getName()) {
                 case "param":
                     $comment->addVar($this->createMethodParam($tag));
                     break;
                 case "var":
                     $comment->addVar($this->createVar($tag));
                     break;
                 case "return":
                     $comment->setReturn($this->getFQCN($tag->getType()));
                     break;
                 case "property":
                     $comment->addProperty($this->createProperty($tag));
                     break;
                 case "inheritdoc":
                     $comment->markInheritDoc();
                     break;
             }
         }
     } catch (\Exception $e) {
     }
 }
开发者ID:nevernet,项目名称:padawan.php,代码行数:32,代码来源:CommentParser.php

示例4: populateTags

 /**
  * Extracts tags from docBlock and adds it to document.
  *
  * @param DocBlock $docBlock
  */
 public function populateTags(DocBlock $docBlock)
 {
     $tags = $docBlock->getTags();
     $offset = strlen(self::TAG_PREFIX);
     foreach ($tags as $tag) {
         $name = $tag->getName();
         if (strpos($name, self::TAG_PREFIX) === 0) {
             $key = substr($name, $offset);
             if (!isset($this->_tags)) {
                 $this->_tags[$key] = [];
             }
             $this->_tags[$key][] = $tag;
         }
     }
 }
开发者ID:thiagoarioli,项目名称:yii2-rest-doc-slade-version,代码行数:20,代码来源:Doc.php

示例5: enterNode

 public function enterNode(Node $node)
 {
     parent::enterNode($node);
     try {
         if ($doc = $node->getDocComment()) {
             $docBlock = new DocBlock($doc->getText());
             if ($tagNames = $this->collectTagNamesBy($docBlock->getTags())) {
                 $node->setAttribute(self::TAG_NAMES_ATTRIBUTE, $tagNames);
             }
         }
     } catch (\Exception $e) {
         $parseError = new Error($e->getMessage(), $node->getLine());
         $this->logger->warning($parseError->getMessage(), array($this->file));
     }
 }
开发者ID:EvKoh,项目名称:PhpDependencyAnalysis,代码行数:15,代码来源:NameResolver.php

示例6: assembleDocBlock

 /**
  * Assemble DocBlock.
  *
  * @param DocBlock|null      $docBlock
  * @param DescriptorAbstract $target
  *
  * @return void
  */
 protected function assembleDocBlock($docBlock, $target)
 {
     if (!$docBlock) {
         return;
     }
     $target->setSummary($docBlock->getShortDescription());
     $target->setDescription($docBlock->getLongDescription()->getContents());
     /** @var DocBlock\Tag $tag */
     foreach ($docBlock->getTags() as $tag) {
         $tagDescriptor = $this->builder->buildDescriptor($tag);
         // allow filtering of tags
         if (!$tagDescriptor) {
             continue;
         }
         $target->getTags()->get($tag->getName(), new Collection())->add($tagDescriptor);
     }
 }
开发者ID:crazycodr,项目名称:phpDocumentor2,代码行数:25,代码来源:AssemblerAbstract.php

示例7: createFromActionableMethod

 /**
  * Create arguments from your executeCommand method parameters
  *
  * @param \ReflectionClass $class
  *
  * @return bool|null
  */
 protected function createFromActionableMethod(\ReflectionClass $class)
 {
     if ($class->hasMethod('executeCommand')) {
         $methodName = 'executeCommand';
     } else {
         if ($class->hasMethod('process')) {
             $methodName = 'process';
         } else {
             return null;
         }
     }
     $method = $class->getMethod($methodName);
     $addedArguments = false;
     $propBlock = new DocBlock($method);
     $descriptions = [];
     foreach ($propBlock->getTags() as $tag) {
         if ($tag instanceof ParamTag) {
             $tagName = substr($tag->getVariableName(), 1);
             $descriptions[$tagName] = $tag->getDescription();
         }
     }
     foreach ($method->getParameters() as $paramNum => $parameter) {
         //Skip over the input and output args for executeCommand
         if ($paramNum < 2 && $methodName == 'executeCommand') {
             continue;
         }
         $mode = InputArgument::REQUIRED;
         $default = null;
         if ($parameter->isDefaultValueAvailable()) {
             $mode = InputArgument::OPTIONAL;
             $default = $parameter->getDefaultValue();
         }
         $description = '';
         if (isset($descriptions[$parameter->getName()])) {
             $description = $descriptions[$parameter->getName()];
         }
         $this->addArgument($parameter->getName(), $parameter->isArray() ? $mode | InputArgument::IS_ARRAY : $mode, $description, $default);
         $addedArguments = true;
     }
     return $addedArguments;
 }
开发者ID:cubex,项目名称:framework,代码行数:48,代码来源:ConsoleCommand.php

示例8: parse

 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;
 }
开发者ID:kpocha,项目名称:Sami,代码行数:22,代码来源:DocBlockParser.php

示例9: fetchMethod

 public function fetchMethod($className, $method)
 {
     $phpdoc = new DocBlock($method->getDocComment());
     $call = array();
     $params = array();
     $return = null;
     // build the call example string
     foreach ($method->getParameters() as $param) {
         if ($param->isOptional()) {
             try {
                 $value = var_export($param->getDefaultValue(), true);
                 $value = str_replace(PHP_EOL, '', $value);
                 $value = str_replace('NULL', 'null', $value);
                 $value = str_replace('array ()', 'array()', $value);
                 $call[] = '$' . $param->getName() . ' = ' . $value;
             } catch (Exception $e) {
                 $call[] = '$' . $param->getName();
             }
         } else {
             $call[] = '$' . $param->getName();
         }
     }
     // get all parameter docs
     foreach ($phpdoc->getTags() as $tag) {
         switch ($tag->getName()) {
             case 'param':
                 $params[] = array('name' => $tag->getVariableName(), 'type' => $tag->getType(), 'text' => $tag->getDescription());
                 break;
             case 'return':
                 $return = array('type' => $tag->getType(), 'text' => $tag->getDescription());
                 break;
         }
     }
     // a::first
     $methodName = strtolower($className) . '::' . $method->getName();
     $methodSlug = str::slug($method->getName());
     // build the full method array
     return array('name' => $methodName, 'slug' => $methodSlug, 'excerpt' => str_replace(PHP_EOL, ' ', $phpdoc->getShortDescription()), 'call' => $methodName . '(' . implode(', ', $call) . ')', 'return' => $return, 'params' => $params);
 }
开发者ID:mzur,项目名称:getkirby.com,代码行数:39,代码来源:documentor.php

示例10: processMethod

 /**
  * @param array $options
  * @param array $method
  * @param string $className
  * @param string $file
  *
  * @return Result
  */
 private function processMethod(array $options, array $method, $className, $file)
 {
     $result = new Result();
     if ($method['docblock'] === null) {
         if ($options['missing_docblock'] !== null) {
             $result->addIssue($this->issueFactory->createIssueForMissingDocblock($options, $method, $className, $file));
         }
         return $result;
     }
     $docBlock = new DocBlock($method['docblock']);
     $tagsInDocblock = $docBlock->getTags();
     $signature = new FunctionSignature($method['signature']);
     if ($options['type_missmatch'] !== null) {
         foreach ($this->differ->inDocBlockAndSignature($tagsInDocblock, $signature) as $params) {
             /** @var DocBlock\Tag\ParamTag $docBlockParam */
             $docBlockParam = $params[0];
             /** @var FunctionParameter $functionParameter */
             $functionParameter = $params[1];
             if (!$this->differ->equalTypes($functionParameter, $docBlockParam)) {
                 if (!$functionParameter->type) {
                     $result->addIssue($this->issueFactory->createIssueForMissingTypeInSignature($options, $method, $className, $file, $functionParameter));
                 } elseif (!$docBlockParam->getType()) {
                     $result->addIssue($this->issueFactory->createIssueForMissingTypeInDocBlock($options, $method, $className, $file, $docBlockParam));
                 } else {
                     $result->addIssue($this->issueFactory->createIssueForMismatchingTypes($options, $method, $className, $file, $functionParameter, $docBlockParam));
                 }
             }
         }
     }
     if ($options['obsolete_variable'] !== null) {
         foreach ($this->differ->inDocblockOnly($tagsInDocblock, $signature) as $param) {
             $result->addIssue($this->issueFactory->createIssueForObsoleteVariable($options, $method, $className, $file, $param->getContent()));
         }
     }
     if ($options['missing_variable'] !== null) {
         foreach ($this->differ->inSignatureOnly($tagsInDocblock, $signature) as $param) {
             $result->addIssue($this->issueFactory->createIssueForMissingVariable($options, $method, $className, $file, $param));
         }
     }
     return $result;
 }
开发者ID:simpspector,项目名称:analyser,代码行数:49,代码来源:DocBlockGadget.php

示例11: buildDefinition

 /**
  * Builds the Input Definition based upon Api Method Parameters.
  *
  * @param \ReflectionMethod $method
  * @param string            $token
  *
  * @return InputDefinition
  */
 private function buildDefinition(\ReflectionMethod $method, DocBlock $docBlock, $token = null)
 {
     $definition = new InputDefinition();
     foreach ($docBlock->getTags() as $tag) {
         if ($tag instanceof DocBlock\Tags\Param) {
             $tagsDescription[$tag->getVariableName()] = $tag->getDescription()->render();
         }
     }
     foreach ($method->getParameters() as $parameter) {
         if ($parameter->isDefaultValueAvailable()) {
             //option
             $definition->addOption(new InputOption($parameter->getName(), null, InputOption::VALUE_REQUIRED, $tagsDescription[$parameter->getName()], $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null));
         } else {
             //argument
             $definition->addArgument(new InputArgument($parameter->getName(), InputArgument::REQUIRED, $tagsDescription[$parameter->getName()], null));
         }
     }
     $definition->addOption(new InputOption('token', null, InputOption::VALUE_REQUIRED, 'Auth token to use', $token));
     $definition->addOption(new InputOption('debug', null, InputOption::VALUE_NONE, 'Display raw response'));
     return $definition;
 }
开发者ID:radutopala,项目名称:skype-bot-php,代码行数:29,代码来源:CommandFactory.php

示例12: testParseMultilineTagWithLineBreaks

    /**
     * @depends testConstructWithTagsOnly
     * @covers \phpDocumentor\Reflection\DocBlock::parseTags
     * 
     * @return void
     */
    public function testParseMultilineTagWithLineBreaks()
    {
        $fixture = <<<DOCBLOCK
/**
 * @return void Content on
 *     multiple lines.
 *
 *     One more, after the break.
 */
DOCBLOCK;
        $object = new DocBlock($fixture);
        $this->assertCount(1, $object->getTags());
    }
开发者ID:hilmysyarif,项目名称:l4-bootstrap-admin,代码行数:19,代码来源:DocBlockTest.php

示例13: getTagAnnotations

 /**
  * Gets all Tag Annotations in a DocBlock.
  * @param Reflector $reflector Supporting the getDocComment method.
  * @return Tag[]
  * @todo Perhaps try to recognize a Tag as an Annotation and ignore it?
  */
 protected function getTagAnnotations(Reflector $reflector)
 {
     $context = $this->getContextFromReflector($reflector);
     $docBlock = new DocBlock($reflector, $context);
     $tags = $docBlock->getTags();
     $tagAnnotations = array();
     foreach ($tags as $tag) {
         /* @var $tag Tag */
         $tagAnnotation = $this->createTagAnnotation($tag);
         if ($tagAnnotation) {
             $tagAnnotations[] = $tagAnnotation;
         }
     }
     return $tagAnnotations;
 }
开发者ID:bvarent,项目名称:doc-block-tags,代码行数:21,代码来源:TagReader.php

示例14: processFile

 /**
  * Process an individual file
  * 
  * @param   string  $file  File path
  * @return  array   Processed endpoints
  */
 private function processFile($file)
 {
     // var to hold output
     $output = array();
     require_once $file;
     $className = $this->parseClassFromFile($file);
     $component = $this->parseClassFromFile($file, true)['component'];
     $version = $this->parseClassFromFile($file, true)['version'];
     // Push file to files array
     $this->output['files'][] = $file;
     // Push version to versions array
     $this->output['versions']['available'][] = $version;
     if (!class_exists($className)) {
         return $output;
     }
     $classReflector = new ReflectionClass($className);
     foreach ($classReflector->getMethods() as $method) {
         // Create docblock object & make sure we have something
         $phpdoc = new DocBlock($method);
         // Skip methods we don't want processed
         if (substr($method->getName(), -4) != 'Task' || in_array($method->getName(), array('registerTask', 'unregisterTask', 'indexTask'))) {
             continue;
         }
         // Skip method in the parent class (already processed),
         if ($className != $method->getDeclaringClass()->getName()) {
             //continue;
         }
         // Skip if we dont have a short desc
         // but put in error
         if (!$phpdoc->getShortDescription()) {
             $this->output['errors'][] = sprintf('Missing docblock for method "%s" in "%s"', $method->getName(), $file);
             continue;
         }
         // Create endpoint data array
         $endpoint = array('name' => $phpdoc->getShortDescription(), 'description' => $phpdoc->getLongDescription()->getContents(), 'method' => '', 'uri' => '', 'parameters' => array(), '_metadata' => array('component' => $component, 'version' => $version, 'method' => $method->getName()));
         // Loop through each tag
         foreach ($phpdoc->getTags() as $tag) {
             $name = strtolower(str_replace('api', '', $tag->getName()));
             $content = $tag->getContent();
             // Handle parameters separately
             // json decode param input
             if ($name == 'parameter') {
                 $parameter = json_decode($content);
                 if (json_last_error() != JSON_ERROR_NONE) {
                     $this->output['errors'][] = sprintf('Unable to parse parameter info for method "%s" in "%s"', $method->getName(), $file);
                     continue;
                 }
                 $endpoint['parameters'][] = (array) $parameter;
                 continue;
             }
             if ($name == 'uri' && $method->getName() == 'indexTask') {
                 $content .= $component;
             }
             // Add data to endpoint data
             $endpoint[$name] = $content;
         }
         // Add endpoint to output
         // We always want indexTask to be first in the list
         if ($method->getName() == 'indexTask') {
             array_unshift($output, $endpoint);
         } else {
             $output[] = $endpoint;
         }
     }
     return $output;
 }
开发者ID:mined-gatech,项目名称:framework,代码行数:72,代码来源:Generator.php

示例15: getDocComment

 /**
  * Generate a DocBlock comment.
  *
  * @param DocBlock The DocBlock to serialize.
  *
  * @return string The serialized doc block.
  */
 public function getDocComment(DocBlock $docblock)
 {
     $indent = str_repeat($this->indentString, $this->indent);
     $firstIndent = $this->isFirstLineIndented ? $indent : '';
     $text = $docblock->getText();
     if ($this->lineLength) {
         //3 === strlen(' * ')
         $wrapLength = $this->lineLength - strlen($indent) - 3;
         $text = wordwrap($text, $wrapLength);
     }
     $text = str_replace("\n", "\n{$indent} * ", $text);
     $comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n";
     /** @var Tag $tag */
     foreach ($docblock->getTags() as $tag) {
         $tagText = (string) $tag;
         if ($this->lineLength) {
             $tagText = wordwrap($tagText, $wrapLength);
         }
         $tagText = str_replace("\n", "\n{$indent} * ", $tagText);
         $comment .= "{$indent} * {$tagText}\n";
     }
     $comment .= $indent . ' */';
     return $comment;
 }
开发者ID:cruni505,项目名称:prestomed,代码行数:31,代码来源:Serializer.php


注:本文中的phpDocumentor\Reflection\DocBlock::getTags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。