RewriteClassNameVisitor.php 956 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Watcher\Ast;
  12. use PhpParser\Node;
  13. use PhpParser\NodeVisitorAbstract;
  14. class RewriteClassNameVisitor extends NodeVisitorAbstract
  15. {
  16. public function __construct(protected Metadata $metadata)
  17. {
  18. }
  19. public function leaveNode(Node $node)
  20. {
  21. switch ($node) {
  22. case $node instanceof Node\Stmt\Namespace_:
  23. $this->metadata->namespace = $node->name->toCodeString();
  24. return $node;
  25. case $node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Enum_:
  26. $className = $node->name->name;
  27. $this->metadata->className = $className;
  28. return $node;
  29. }
  30. return null;
  31. }
  32. }