[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Generator/ -> TraitGenerator.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;
  11  
  12  use Zend\Code\Reflection\ClassReflection;
  13  
  14  use function str_replace;
  15  use function strtolower;
  16  
  17  class TraitGenerator extends ClassGenerator
  18  {
  19      const OBJECT_TYPE = 'trait';
  20  
  21      /**
  22       * Build a Code Generation Php Object from a Class Reflection
  23       *
  24       * @param  ClassReflection $classReflection
  25       * @return TraitGenerator
  26       */
  27      public static function fromReflection(ClassReflection $classReflection)
  28      {
  29          // class generator
  30          $cg = new static($classReflection->getName());
  31  
  32          $cg->setSourceContent($cg->getSourceContent());
  33          $cg->setSourceDirty(false);
  34  
  35          if ($classReflection->getDocComment() != '') {
  36              $cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock()));
  37          }
  38  
  39          // set the namespace
  40          if ($classReflection->inNamespace()) {
  41              $cg->setNamespaceName($classReflection->getNamespaceName());
  42          }
  43  
  44          $properties = [];
  45          foreach ($classReflection->getProperties() as $reflectionProperty) {
  46              if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
  47                  $properties[] = PropertyGenerator::fromReflection($reflectionProperty);
  48              }
  49          }
  50          $cg->addProperties($properties);
  51  
  52          $methods = [];
  53          foreach ($classReflection->getMethods() as $reflectionMethod) {
  54              $className = $cg->getNamespaceName()
  55                  ? $cg->getNamespaceName() . '\\' . $cg->getName()
  56                  : $cg->getName();
  57              if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
  58                  $methods[] = MethodGenerator::fromReflection($reflectionMethod);
  59              }
  60          }
  61          $cg->addMethods($methods);
  62  
  63          return $cg;
  64      }
  65  
  66      /**
  67       * Generate from array
  68       *
  69       * @configkey name           string        [required] Class Name
  70       * @configkey filegenerator  FileGenerator File generator that holds this class
  71       * @configkey namespacename  string        The namespace for this class
  72       * @configkey docblock       string        The docblock information
  73       * @configkey properties
  74       * @configkey methods
  75       *
  76       * @throws Exception\InvalidArgumentException
  77       * @param  array $array
  78       * @return TraitGenerator
  79       */
  80      public static function fromArray(array $array)
  81      {
  82          if (! isset($array['name'])) {
  83              throw new Exception\InvalidArgumentException(
  84                  'Class generator requires that a name is provided for this object'
  85              );
  86          }
  87  
  88          $cg = new static($array['name']);
  89          foreach ($array as $name => $value) {
  90              // normalize key
  91              switch (strtolower(str_replace(['.', '-', '_'], '', $name))) {
  92                  case 'containingfile':
  93                      $cg->setContainingFileGenerator($value);
  94                      break;
  95                  case 'namespacename':
  96                      $cg->setNamespaceName($value);
  97                      break;
  98                  case 'docblock':
  99                      $docBlock = $value instanceof DocBlockGenerator ? $value : DocBlockGenerator::fromArray($value);
 100                      $cg->setDocBlock($docBlock);
 101                      break;
 102                  case 'properties':
 103                      $cg->addProperties($value);
 104                      break;
 105                  case 'methods':
 106                      $cg->addMethods($value);
 107                      break;
 108              }
 109          }
 110  
 111          return $cg;
 112      }
 113  
 114      /**
 115       * @param  array|string $flags
 116       * @return self
 117       */
 118      public function setFlags($flags)
 119      {
 120          return $this;
 121      }
 122  
 123      /**
 124       * @param  string $flag
 125       * @return self
 126       */
 127      public function addFlag($flag)
 128      {
 129          return $this;
 130      }
 131  
 132      /**
 133       * @param  string $flag
 134       * @return self
 135       */
 136      public function removeFlag($flag)
 137      {
 138          return $this;
 139      }
 140  
 141      /**
 142       * @param  bool $isFinal
 143       * @return self
 144       */
 145      public function setFinal($isFinal)
 146      {
 147          return $this;
 148      }
 149  
 150      /**
 151       * @param  string $extendedClass
 152       * @return self
 153       */
 154      public function setExtendedClass($extendedClass)
 155      {
 156          return $this;
 157      }
 158  
 159      /**
 160       * @param  array $implementedInterfaces
 161       * @return self
 162       */
 163      public function setImplementedInterfaces(array $implementedInterfaces)
 164      {
 165          return $this;
 166      }
 167  
 168      /**
 169       * @param  bool $isAbstract
 170       * @return self
 171       */
 172      public function setAbstract($isAbstract)
 173      {
 174          return $this;
 175      }
 176  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1