[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Generator/DocBlock/ -> TagManager.php (source)

   1  <?php
   2  /**
   3   * Zend Framework (http://framework.zend.com/)
   4   *
   5   * @link      http://github.com/zendframework/zf2 for the canonical source repository
   6   * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
   7   * @license   http://framework.zend.com/license/new-bsd New BSD License
   8   */
   9  
  10  namespace Zend\Code\Generator\DocBlock;
  11  
  12  use Zend\Code\Generator\DocBlock\Tag\TagInterface;
  13  use Zend\Code\Generic\Prototype\PrototypeClassFactory;
  14  use Zend\Code\Reflection\DocBlock\Tag\TagInterface as ReflectionTagInterface;
  15  
  16  use function method_exists;
  17  use function substr;
  18  use function strpos;
  19  use function ucfirst;
  20  
  21  /**
  22   * This class is used in DocBlockGenerator and creates the needed
  23   * Tag classes depending on the tag. So for example an @author tag
  24   * will trigger the creation of an AuthorTag class.
  25   *
  26   * If none of the classes is applicable, the GenericTag class will be
  27   * created
  28   */
  29  class TagManager extends PrototypeClassFactory
  30  {
  31      /**
  32       * @return void
  33       */
  34      public function initializeDefaultTags()
  35      {
  36          $this->addPrototype(new Tag\ParamTag());
  37          $this->addPrototype(new Tag\ReturnTag());
  38          $this->addPrototype(new Tag\MethodTag());
  39          $this->addPrototype(new Tag\PropertyTag());
  40          $this->addPrototype(new Tag\AuthorTag());
  41          $this->addPrototype(new Tag\LicenseTag());
  42          $this->addPrototype(new Tag\ThrowsTag());
  43          $this->addPrototype(new Tag\VarTag());
  44          $this->setGenericPrototype(new Tag\GenericTag());
  45      }
  46  
  47      /**
  48       * @param ReflectionTagInterface $reflectionTag
  49       * @return TagInterface
  50       */
  51      public function createTagFromReflection(ReflectionTagInterface $reflectionTag)
  52      {
  53          $tagName = $reflectionTag->getName();
  54  
  55          /* @var TagInterface $newTag */
  56          $newTag = $this->getClonedPrototype($tagName);
  57  
  58          // transport any properties via accessors and mutators from reflection to codegen object
  59          $reflectionClass = new \ReflectionClass($reflectionTag);
  60          foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
  61              if (0 === strpos($method->getName(), 'get')) {
  62                  $propertyName = substr($method->getName(), 3);
  63                  if (method_exists($newTag, 'set' . $propertyName)) {
  64                      $newTag->{'set' . $propertyName}($reflectionTag->{'get' . $propertyName}());
  65                  }
  66              } elseif (0 === strpos($method->getName(), 'is')) {
  67                  $propertyName = ucfirst($method->getName());
  68                  if (method_exists($newTag, 'set' . $propertyName)) {
  69                      $newTag->{'set' . $propertyName}($reflectionTag->{$method->getName()}());
  70                  }
  71              }
  72          }
  73          return $newTag;
  74      }
  75  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1