PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.5.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.5.5
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Dependencies / PhpParser / ParserFactory.php

ParserFactory.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.5.5, at includes/Dependencies/PhpParser/ParserFactory.php

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