/**
  * If $constant is the start of the constant defining $key, updat its value to $value
  *
  * @param Collection $tokens
  * @param Token $constant
  * @param string $key
  * @param mixed $value
  */
 private function handleConstant(Collection $tokens, Token $constant, $key, $value)
 {
     $lineEnd = false;
     $found = false;
     $index = $constant->getIndex();
     $tokens->rewind();
     while ($lineEnd === false && ($constantToken = $tokens->getNext($index))) {
         if ($constantToken->getValue() === ';') {
             $lineEnd = true;
         }
         if ($constantToken->getType() === T_STRING && $constantToken->getValue() === $key) {
             $found = true;
         } elseif ($found === true) {
             $this->attemptUpdate($constantToken, $value);
         }
         $index++;
     }
 }
Exemplo n.º 2
0
 /**
  * @param Token $tokenStart
  * @param Token $tokenEnd
  * @return Collection
  */
 public function extractByTokens(Token $tokenStart, Token $tokenEnd)
 {
     $collection = new Collection();
     $startIndex = $tokenStart->getIndex();
     $endIndex = $tokenEnd->getIndex();
     foreach ($this->getItems() as $token) {
         if ($token->getIndex() >= $startIndex and $token->getIndex() <= $endIndex) {
             $collection->append($token);
         }
     }
     return $collection;
 }
Exemplo n.º 3
0
 /**
  * Move to specific position
  *
  * @param Token $token
  * @return Token|null
  */
 public function moveToToken(Token $token)
 {
     if (!$token->isValid()) {
         $this->setValid(false);
         return new Token();
     }
     $tokenIndex = $token->getIndex();
     foreach ($this->collection as $index => $collectionToken) {
         if ($collectionToken->getIndex() == $tokenIndex) {
             $this->setPosition($index);
             return $collectionToken;
         }
     }
     $this->setValid(false);
     return new Token();
 }