[ Index ]

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


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1