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


PHP DocBlock::hasTag方法代码示例

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


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

示例1: testTagCaseSensitivity

    public function testTagCaseSensitivity()
    {
        $fixture = <<<DOCBLOCK
/**
 * This is a short description.
 *
 * This is a long description.
 *
 * @method null something()
 * @Method({"GET", "POST"})
 */
DOCBLOCK;
        $object = new DocBlock($fixture);
        $this->assertEquals('This is a short description.', $object->getShortDescription());
        $this->assertEquals('This is a long description.', $object->getLongDescription()->getContents());
        $tags = $object->getTags();
        $this->assertCount(2, $tags);
        $this->assertTrue($object->hasTag('method'));
        $this->assertTrue($object->hasTag('Method'));
        $this->assertInstanceOf(__NAMESPACE__ . '\\DocBlock\\Tag\\MethodTag', $tags[0]);
        $this->assertInstanceOf(__NAMESPACE__ . '\\DocBlock\\Tag', $tags[1]);
        $this->assertNotInstanceOf(__NAMESPACE__ . '\\DocBlock\\Tag\\MethodTag', $tags[1]);
    }
开发者ID:ecmattos,项目名称:codemat,代码行数:23,代码来源:DocBlockTest.php

示例2: _doHydrate

 /**
  * @param MessageInterface $object
  * @param array $data
  *
  * @return MessageInterface
  */
 private function _doHydrate(MessageInterface $object, $data)
 {
     $reflected = new \ReflectionClass($object);
     if ($object instanceof MessageCollectionInterface && $object instanceof ArrayCollectionInterface) {
         foreach ($data->{$object->getDataMemberName()} as $singleData) {
             $class = $object->createChildClass();
             $object->add($this->_doHydrate($class, $singleData));
         }
     }
     foreach ($data as $key => $value) {
         if ($reflected->hasProperty($key)) {
             $property = $reflected->getProperty($key);
             $setter = $this->generateSetter($key);
             $doc = new DocBlock($property);
             if ($doc->hasTag('var')) {
                 $tags = $doc->getTagsByName('var');
                 if (count($tags) !== 1) {
                     throw new RuntimeException('Property "' . $property->getName() . '" of class ' . $property->getDeclaringClass() . 'has more @var tags. Only one is allowed.');
                 }
                 $type = $tags[0]->getType();
                 switch (true) {
                     /**
                      * Internal type Enum
                      */
                     /*case $type === '\\Enum':
                       $getter = $this->generateGetter($key);
                       $object->{$getter}()->setValue($value);
                       break;*/
                     /**
                      * All basic types
                      */
                     case in_array(strtolower($type), $this->basicTypes, false):
                         $object->{$setter}($value);
                         break;
                         /**
                          * Object types - special cases first
                          */
                     /**
                      * Object types - special cases first
                      */
                     case $type === '\\DateTime':
                         $class = new \DateTime($value);
                         $object->{$setter}($class);
                         break;
                     case $type === '\\DateTimeZone':
                         if (empty($value)) {
                             continue;
                         }
                         $class = new \DateTimeZone($value);
                         $object->{$setter}($class);
                         break;
                     case !is_array($value) && class_exists($type, true):
                         $class = new $type($value);
                         $object->{$setter}($class);
                         break;
                         /**
                          * Try to find class and hydrate object
                          */
                     /**
                      * Try to find class and hydrate object
                      */
                     default:
                         $possibleClassNames = [];
                         $possibleClassNames[] = $this->baseNS . $type;
                         $possibleClassNames[] = $reflected->getNamespaceName() . $type;
                         $possibleClassNames[] = $type;
                         foreach ($possibleClassNames as $className) {
                             if (class_exists($className, true)) {
                                 $class = new $className();
                                 $hydrated = $this->_doHydrate($class, $value);
                                 $object->{$setter}($hydrated);
                                 continue 2;
                             }
                         }
                         /**
                          * Class not found, we use raw $value.
                          */
                         $object->{$setter}($value);
                         break;
                 }
             }
         } elseif ($key === '_links') {
             foreach ($value as $link) {
                 $object->addMethod($link->method, $link->rel, $link->href);
             }
         }
     }
     return $object;
 }
开发者ID:vojtabiberle,项目名称:mailchimp-api-v3,代码行数:95,代码来源:JsonHydrator.php

示例3: testExceptionIsThrownIfNameForCheckingTagsIsNotString

 /**
  * @covers ::__construct
  * @covers ::hasTag
  * @uses \phpDocumentor\Reflection\DocBlock\Description
  * @expectedException \InvalidArgumentException
  */
 public function testExceptionIsThrownIfNameForCheckingTagsIsNotString()
 {
     $fixture = new DocBlock();
     $fixture->hasTag([]);
 }
开发者ID:jaapio,项目名称:ReflectionDocBlock,代码行数:11,代码来源:DocBlockTest.php

示例4: isValidNode

 protected function isValidNode(DocBlock $docblock)
 {
     return $docblock->hasTag('api-template') == false && $docblock->hasTag('api-group') == true && $docblock->hasTag('api-method') == true && $docblock->hasTag('api-uri') == true;
 }
开发者ID:stratedge,项目名称:inspection,代码行数:4,代码来源:Parse.php

示例5: beforeTraverse

 public function beforeTraverse(array $nodes)
 {
     $node = null;
     $key = 0;
     foreach ($nodes as $k => $n) {
         if (!$n instanceof PHPParser_Node_Stmt_InlineHTML) {
             $node = $n;
             $key = $k;
             break;
         }
     }
     if ($node) {
         $comments = (array) $node->getAttribute('comments');
         // remove non-DocBlock comments
         $comments = array_values(array_filter($comments, function ($comment) {
             return $comment instanceof PHPParser_Comment_Doc;
         }));
         if (!empty($comments)) {
             try {
                 $docblock = new DocBlock((string) $comments[0], null, new Location($comments[0]->getLine()));
                 // the first DocBlock in a file documents the file if
                 // * it precedes another DocBlock or
                 // * it contains a @package tag and doesn't precede a class
                 //   declaration or
                 // * it precedes a non-documentable element (thus no include,
                 //   require, class, function, define, const)
                 if (count($comments) > 1 || !$node instanceof PHPParser_Node_Stmt_Class && !$node instanceof PHPParser_Node_Stmt_Interface && $docblock->hasTag('package') || !$this->isNodeDocumentable($node)) {
                     $this->doc_block = $docblock;
                     // remove the file level DocBlock from the node's comments
                     array_shift($comments);
                 }
             } catch (Exception $e) {
                 $this->log($e->getMessage(), Log::CRIT);
             }
         }
         // always update the comments attribute so that standard comments
         // do not stop DocBlock from being attached to an element
         $node->setAttribute('comments', $comments);
         $nodes[$key] = $node;
     }
     Dispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', PostDocBlockExtractionEvent::createInstance($this)->setDocblock($this->doc_block));
     return $nodes;
 }
开发者ID:CobaltBlueDW,项目名称:oddsandends,代码行数:43,代码来源:FileReflector.php

示例6: store_class_constant

 public function store_class_constant(Node\Stmt\Class_ $class, Node\Stmt\ClassConst $constant)
 {
     if ($comments = $constant->getAttribute('comments')) {
         $phpdoc = new DocBlock($comments[0]->getText());
         $description = $phpdoc->getShortDescription();
         // short circuit @ignore functions
         if ($phpdoc->hasTag('ignore')) {
             return;
         }
     } else {
         $description = '';
     }
     $this->store_model('class_constants', array('constant' => $constant->consts[0]->name, 'class' => $class->name, 'namespace' => !empty($class->namespacedName) ? implode('\\', array_slice($class->namespacedName->parts, 0, -1)) : '', 'file' => $this->_current_file, 'line' => $constant->getLine(), 'type' => $this->get_type_for_node($constant->consts[0]->value), 'description' => $description));
 }
开发者ID:joehoyle,项目名称:atom-experimental-php-autocomplete,代码行数:14,代码来源:DB.php

示例7: createOptionsFromPublic

 /**
  * Create options and arguments from the public properties on your command
  *
  * @param \ReflectionClass $class
  * @param                  $argsAdded
  *
  * @return null
  */
 protected function createOptionsFromPublic(\ReflectionClass $class, $argsAdded)
 {
     $properties = $class->getProperties(\ReflectionProperty::IS_PUBLIC);
     if (empty($properties)) {
         return null;
     }
     foreach ($properties as $property) {
         $propBlock = new DocBlock($property);
         $short = null;
         $description = $propBlock->getShortDescription();
         $mode = InputOption::VALUE_OPTIONAL;
         if ($propBlock->hasTag('short')) {
             $short = head($propBlock->getTagsByName('short'))->getDescription();
         }
         if ($propBlock->hasTag('description')) {
             $description = head($propBlock->getTagsByName('description'))->getDescription();
         }
         if ($propBlock->hasTag('valuerequired')) {
             $mode = InputOption::VALUE_REQUIRED;
         }
         if ($propBlock->hasTag('flag')) {
             $mode = InputOption::VALUE_NONE;
         }
         $this->addOption($property->getName(), $short, $mode, $description, $property->getValue($this));
     }
 }
开发者ID:cubex,项目名称:framework,代码行数:34,代码来源:ConsoleCommand.php


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