菜谱项目

ClassLike.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. abstract class ClassLike extends Node\Stmt {
  5. /** @var string|null Name */
  6. public $name;
  7. /** @var Node[] Statements */
  8. public $stmts;
  9. /**
  10. * Gets all methods defined directly in this class/interface/trait
  11. *
  12. * @return ClassMethod[]
  13. */
  14. public function getMethods() {
  15. $methods = array();
  16. foreach ($this->stmts as $stmt) {
  17. if ($stmt instanceof ClassMethod) {
  18. $methods[] = $stmt;
  19. }
  20. }
  21. return $methods;
  22. }
  23. /**
  24. * Gets method with the given name defined directly in this class/interface/trait.
  25. *
  26. * @param string $name Name of the method (compared case-insensitively)
  27. *
  28. * @return ClassMethod|null Method node or null if the method does not exist
  29. */
  30. public function getMethod($name) {
  31. $lowerName = strtolower($name);
  32. foreach ($this->stmts as $stmt) {
  33. if ($stmt instanceof ClassMethod && $lowerName === strtolower($stmt->name)) {
  34. return $stmt;
  35. }
  36. }
  37. return null;
  38. }
  39. }