PluginProbe
WPIDE – File Manager & Code Editor / 3.1
WPIDE – File Manager & Code Editor v3.1
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
wpide / vendor / nikic / php-parser / lib / PhpParser / ParserFactory.php

ParserFactory.php in WPIDE – File Manager & Code Editor 3.1, at vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php

45 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace PhpParser;
4
5 class ParserFactory
6 {
7 const PREFER_PHP7 = 1;
8 const PREFER_PHP5 = 2;
9 const ONLY_PHP7 = 3;
10 const ONLY_PHP5 = 4;
11
12 /**
13 * Creates a Parser instance, according to the provided kind.
14 *
15 * @param int $kind One of ::PREFER_PHP7, ::PREFER_PHP5, ::ONLY_PHP7 or ::ONLY_PHP5
16 * @param Lexer|null $lexer Lexer to use. Defaults to emulative lexer when not specified
17 * @param array $parserOptions Parser options. See ParserAbstract::__construct() argument
18 *
19 * @return Parser The parser instance
20 */
21 public function create(int $kind, Lexer $lexer = null, array $parserOptions = []) : Parser {
22 if (null === $lexer) {
23 $lexer = new Lexer\Emulative();
24 }
25 switch ($kind) {
26 case self::PREFER_PHP7:
27 return new Parser\Multiple([
28 new Parser\Php7($lexer, $parserOptions), new Parser\Php5($lexer, $parserOptions)
29 ]);
30 case self::PREFER_PHP5:
31 return new Parser\Multiple([
32 new Parser\Php5($lexer, $parserOptions), new Parser\Php7($lexer, $parserOptions)
33 ]);
34 case self::ONLY_PHP7:
35 return new Parser\Php7($lexer, $parserOptions);
36 case self::ONLY_PHP5:
37 return new Parser\Php5($lexer, $parserOptions);
38 default:
39 throw new \LogicException(
40 'Kind must be one of ::PREFER_PHP7, ::PREFER_PHP5, ::ONLY_PHP7 or ::ONLY_PHP5'
41 );
42 }
43 }
44 }
45