getNextToken() public method

The available attributes are determined by the 'usedAttributes' option, which can be specified in the constructor. The following attributes are supported: * 'comments' => Array of PhpParser\Comment or PhpParser\Comment\Doc instances, representing all comments that occurred between the previous non-discarded token and the current one. * 'startLine' => Line in which the node starts. * 'endLine' => Line in which the node ends. * 'startTokenPos' => Offset into the token array of the first token in the node. * 'endTokenPos' => Offset into the token array of the last token in the node. * 'startFilePos' => Offset into the code string of the first character that is part of the node. * 'endFilePos' => Offset into the code string of the last character that is part of the node.
public getNextToken ( mixed &$value = null, mixed &$startAttributes = null, mixed &$endAttributes = null ) : integer
$value mixed Variable to store token content in
$startAttributes mixed Variable to store start attributes in
$endAttributes mixed Variable to store end attributes in
return integer Token id
示例#1
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;
 }
示例#2
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;
 }
示例#3
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;
 }