PhpParser\Lexer::__construct PHP Method

__construct() public method

Creates a Lexer.
public __construct ( array $options = [] )
$options array Options array. Currently only the 'usedAttributes' option is supported, which is an array of attributes to add to the AST nodes. Possible attributes are: 'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos', 'startFilePos', 'endFilePos'. The option defaults to the first three. For more info see getNextToken() docs.
    public function __construct(array $options = array())
    {
        // map from internal tokens to PhpParser tokens
        $this->tokenMap = $this->createTokenMap();
        // map of tokens to drop while lexing (the map is only used for isset lookup,
        // that's why the value is simply set to 1; the value is never actually used.)
        $this->dropTokens = array_fill_keys(array(T_WHITESPACE, T_OPEN_TAG, T_COMMENT, T_DOC_COMMENT), 1);
        // the usedAttributes member is a map of the used attribute names to a dummy
        // value (here "true")
        $options += array('usedAttributes' => array('comments', 'startLine', 'endLine'));
        $this->usedAttributes = array_fill_keys($options['usedAttributes'], true);
    }

Usage Example

示例#1
0
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     $newKeywordsPerVersion = array(self::PHP_5_5 => array('finally' => Parser::T_FINALLY, 'yield' => Parser::T_YIELD), self::PHP_5_4 => array('callable' => Parser::T_CALLABLE, 'insteadof' => Parser::T_INSTEADOF, 'trait' => Parser::T_TRAIT, '__trait__' => Parser::T_TRAIT_C));
     $this->newKeywords = array();
     foreach ($newKeywordsPerVersion as $version => $newKeywords) {
         if (version_compare(PHP_VERSION, $version, '>=')) {
             break;
         }
         $this->newKeywords += $newKeywords;
     }
     if (version_compare(PHP_VERSION, self::PHP_5_6, '<')) {
         $this->tokenMap[self::T_ELLIPSIS] = Parser::T_ELLIPSIS;
         $this->tokenMap[self::T_POW] = Parser::T_POW;
         $this->tokenMap[self::T_POW_EQUAL] = Parser::T_POW_EQUAL;
     }
 }
All Usage Examples Of PhpParser\Lexer::__construct