[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

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


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