PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.9
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.9
4.9.2 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 All 200 releases
betterdocs / includes / Dependencies / SuperClosure / Analyzer / Visitor / MagicConstantVisitor.php

MagicConstantVisitor.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.8.9, at includes/Dependencies/SuperClosure/Analyzer/Visitor/MagicConstantVisitor.php

51 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace WPDeveloper\BetterDocs\Dependencies\SuperClosure\Analyzer\Visitor;
2
3 use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node\Scalar\LNumber as NumberNode;
4 use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node\Scalar\String_ as StringNode;
5 use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node as AstNode;
6 use WPDeveloper\BetterDocs\Dependencies\PhpParser\NodeVisitorAbstract as NodeVisitor;
7
8 /**
9 * This is a visitor that resolves magic constants (e.g., __FILE__) to their
10 * intended values within a closure's AST.
11 *
12 * @internal
13 */
14 final class MagicConstantVisitor extends NodeVisitor
15 {
16 /**
17 * @var array
18 */
19 private $location;
20
21 /**
22 * @param array $location
23 */
24 public function __construct(array $location)
25 {
26 $this->location = $location;
27 }
28
29 public function leaveNode(AstNode $node)
30 {
31 switch ($node->getType()) {
32 case 'Scalar_MagicConst_Class' :
33 return new StringNode($this->location['class'] ?: '');
34 case 'Scalar_MagicConst_Dir' :
35 return new StringNode($this->location['directory'] ?: '');
36 case 'Scalar_MagicConst_File' :
37 return new StringNode($this->location['file'] ?: '');
38 case 'Scalar_MagicConst_Function' :
39 return new StringNode($this->location['function'] ?: '');
40 case 'Scalar_MagicConst_Line' :
41 return new NumberNode($node->getAttribute('startLine') ?: 0);
42 case 'Scalar_MagicConst_Method' :
43 return new StringNode($this->location['method'] ?: '');
44 case 'Scalar_MagicConst_Namespace' :
45 return new StringNode($this->location['namespace'] ?: '');
46 case 'Scalar_MagicConst_Trait' :
47 return new StringNode($this->location['trait'] ?: '');
48 }
49 }
50 }
51