[ Index ]

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


Generated: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1