Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Assoa\Parser;
- use PhpParser\Node;
- use PhpParser\Node\Stmt\Class_;
- use Assoa\Commands\BuilderCommand;
- use PhpParser\NodeVisitorAbstract;
- use Assoa\Parser\INodeVisitorFactory;
- use PhpParser\Node\Stmt\ClassMethod;
- class ProxyNodeVisitorFactory implements INodeVisitorFactory
- {
- public static function get(...$args)
- {
- $className = $args[0];
- $commands = $args[1];
- $visitor = new class($className, $commands) extends NodeVisitorAbstract
- {
- protected $parsingTargetClass = false;
- protected $isFinalClass = false;
- public function __construct($className, $commands)
- {
- $this->commands = $commands;
- $this->className = $className;
- }
- public function enterNode(Node $node)
- {
- if (($node instanceof ClassMethod) && $node->isPublic() && $this->parsingTargetClass === true) {on
- if ($node->isFinal()) {
- throw new InvalidArgumentException("A final class cannot be proxied");
- }
- if($node->name == "__construct"){
- $this->commands['constructor']->execute($node);
- } else {
- $this->commands['method']->execute($node);
- }
- } elseif (($node instanceof Class_) && ($node->name == $this->className)) {
- $this->parsingTargetClass = true;
- }
- }
- public function leaveNode(Node $node)
- {
- if ($node instanceof Class_) {
- // If the node is a class node
- if ($node->name == $this->className) {
- $this->commands['class']->execute();
- $this->parsingTargetClass = false;
- }
- }
- }
- };
- return $visitor;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement