Example #1
0
 private function detectTemplate()
 {
     foreach ($this->lexer->getTokens() as $token) {
         if (!is_array($token)) {
             continue;
         }
         $templateEndTokens = [T_ENDIF => 1, T_ENDFOREACH => 1, T_ENDFOR => 1, T_ENDWHILE => 1];
         if (!isset($templateEndTokens[$token[0]])) {
             continue;
         }
         if (Strings::startsWith($token[1], 'end')) {
             throw new TemplateSkippedException();
         }
     }
 }
Example #2
0
 /**
  * Retrieves the next token and determines the associated attributes and
  * returns the token id.
  *
  * @param string   $value
  * @param string[] $startAttributes
  * @param string[] $endAttributes
  *
  * @return int
  */
 public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null)
 {
     $tokenId = parent::getNextToken($value, $startAttributes, $endAttributes);
     if ($this->isTokenScalar($tokenId)) {
         // store original value because the value itself will be interpreted
         // by PHP_Parser and we want the unformatted value
         $endAttributes['originalValue'] = $value;
     }
     return $tokenId;
 }
Example #3
0
 public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null)
 {
     $tokenId = parent::getNextToken($value, $startAttributes, $endAttributes);
     if ($tokenId == Parser::T_CONSTANT_ENCAPSED_STRING || $tokenId == Parser::T_LNUMBER || $tokenId == Parser::T_DNUMBER) {
         // could also use $startAttributes, doesn't really matter here
         $endAttributes['originalValue'] = $value;
     }
     if ($tokenId == Parser::T_CONSTANT_ENCAPSED_STRING) {
         $endAttributes['isDoubleQuoted'] = $value[0] === '"';
     }
     if ($tokenId == Parser::T_END_HEREDOC) {
         $endAttributes['isHereDoc'] = true;
     }
     return $tokenId;
 }
Example #4
0
 public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null)
 {
     $token = parent::getNextToken($value, $startAttributes, $endAttributes);
     // replace new keywords by their respective tokens. This is not done
     // if we currently are in an object access (e.g. in $obj->namespace
     // "namespace" stays a T_STRING tokens and isn't converted to T_NAMESPACE)
     if (Parser::T_STRING === $token && !$this->inObjectAccess) {
         if (isset($this->newKeywords[strtolower($value)])) {
             return $this->newKeywords[strtolower($value)];
         }
         // keep track of whether we currently are in an object access (after ->)
     } elseif (Parser::T_OBJECT_OPERATOR === $token) {
         $this->inObjectAccess = true;
     } else {
         $this->inObjectAccess = false;
     }
     return $token;
 }