[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Scanner/ -> ConstantScanner.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\Scanner;
  11  
  12  use Zend\Code\Annotation;
  13  use Zend\Code\Exception;
  14  use Zend\Code\NameInformation;
  15  
  16  class ConstantScanner implements ScannerInterface
  17  {
  18      /**
  19       * @var bool
  20       */
  21      protected $isScanned = false;
  22  
  23      /**
  24       * @var array
  25       */
  26      protected $tokens;
  27  
  28      /**
  29       * @var NameInformation
  30       */
  31      protected $nameInformation;
  32  
  33      /**
  34       * @var string
  35       */
  36      protected $class;
  37  
  38      /**
  39       * @var ClassScanner
  40       */
  41      protected $scannerClass;
  42  
  43      /**
  44       * @var int
  45       */
  46      protected $lineStart;
  47  
  48      /**
  49       * @var string
  50       */
  51      protected $docComment;
  52  
  53      /**
  54       * @var string
  55       */
  56      protected $name;
  57  
  58      /**
  59       * @var string
  60       */
  61      protected $value;
  62  
  63      /**
  64       * Constructor
  65       *
  66       * @param array $constantTokens
  67       * @param NameInformation $nameInformation
  68       */
  69      public function __construct(array $constantTokens, NameInformation $nameInformation = null)
  70      {
  71          $this->tokens = $constantTokens;
  72          $this->nameInformation = $nameInformation;
  73      }
  74  
  75      /**
  76       * @param string $class
  77       */
  78      public function setClass($class)
  79      {
  80          $this->class = $class;
  81      }
  82  
  83      /**
  84       * @param ClassScanner $scannerClass
  85       */
  86      public function setScannerClass(ClassScanner $scannerClass)
  87      {
  88          $this->scannerClass = $scannerClass;
  89      }
  90  
  91      /**
  92       * @return ClassScanner
  93       */
  94      public function getClassScanner()
  95      {
  96          return $this->scannerClass;
  97      }
  98  
  99      /**
 100       * @return string
 101       */
 102      public function getName()
 103      {
 104          $this->scan();
 105          return $this->name;
 106      }
 107  
 108      /**
 109       * @return string
 110       */
 111      public function getValue()
 112      {
 113          $this->scan();
 114          return $this->value;
 115      }
 116  
 117      /**
 118       * @return string
 119       */
 120      public function getDocComment()
 121      {
 122          $this->scan();
 123          return $this->docComment;
 124      }
 125  
 126      /**
 127       * @param Annotation\AnnotationManager $annotationManager
 128       * @return AnnotationScanner
 129       */
 130      public function getAnnotations(Annotation\AnnotationManager $annotationManager)
 131      {
 132          if (($docComment = $this->getDocComment()) == '') {
 133              return false;
 134          }
 135  
 136          return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation);
 137      }
 138  
 139      /**
 140       * @return string
 141       */
 142      public function __toString()
 143      {
 144          $this->scan();
 145          return var_export($this, true);
 146      }
 147  
 148      /**
 149       * Scan tokens
 150       *
 151       * @throws Exception\RuntimeException
 152       */
 153      protected function scan()
 154      {
 155          if ($this->isScanned) {
 156              return;
 157          }
 158  
 159          if (!$this->tokens) {
 160              throw new Exception\RuntimeException('No tokens were provided');
 161          }
 162  
 163          /**
 164           * Variables & Setup
 165           */
 166          $tokens = &$this->tokens;
 167  
 168          reset($tokens);
 169  
 170          SCANNER_TOP:
 171  
 172          $token = current($tokens);
 173  
 174          if (!is_string($token)) {
 175              list($tokenType, $tokenContent, $tokenLine) = $token;
 176  
 177              switch ($tokenType) {
 178                  case T_DOC_COMMENT:
 179                      if ($this->docComment === null && $this->name === null) {
 180                          $this->docComment = $tokenContent;
 181                      }
 182                      goto SCANNER_CONTINUE;
 183                      // fall-through
 184  
 185                  case T_STRING:
 186                      $string = (is_string($token)) ? $token : $tokenContent;
 187  
 188                      if (null === $this->name) {
 189                          $this->name = $string;
 190                      } else {
 191                          if ('self' == strtolower($string)) {
 192                              list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens);
 193  
 194                              if ('::' == $tokenNextContent) {
 195                                  list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens);
 196  
 197                                  if ($this->getClassScanner()->getConstant($tokenNextContent)) {
 198                                      $this->value = $this->getClassScanner()->getConstant($tokenNextContent)->getValue();
 199                                  }
 200                              }
 201                          }
 202                      }
 203  
 204                      goto SCANNER_CONTINUE;
 205                      // fall-through
 206  
 207                  case T_CONSTANT_ENCAPSED_STRING:
 208                  case T_DNUMBER:
 209                  case T_LNUMBER:
 210                      $string = (is_string($token)) ? $token : $tokenContent;
 211  
 212                      if (substr($string, 0, 1) === '"' || substr($string, 0, 1) === "'") {
 213                          $this->value = substr($string, 1, -1); // Remove quotes
 214                      } else {
 215                          $this->value = $string;
 216                      }
 217                      goto SCANNER_CONTINUE;
 218                      // fall-trough
 219  
 220                  default:
 221                      goto SCANNER_CONTINUE;
 222              }
 223          }
 224  
 225          SCANNER_CONTINUE:
 226  
 227          if (next($this->tokens) === false) {
 228              goto SCANNER_END;
 229          }
 230          goto SCANNER_TOP;
 231  
 232          SCANNER_END:
 233  
 234          $this->isScanned = true;
 235      }
 236  }


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