No Description

Interface_.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Error;
  5. /**
  6. * @property string $name Name
  7. * @property Node\Name[] $extends Extended interfaces
  8. * @property Node[] $stmts Statements
  9. */
  10. class Interface_ extends Node\Stmt
  11. {
  12. protected static $specialNames = array(
  13. 'self' => true,
  14. 'parent' => true,
  15. 'static' => true,
  16. );
  17. /**
  18. * Constructs a class node.
  19. *
  20. * @param string $name Name
  21. * @param array $subNodes Array of the following optional subnodes:
  22. * 'extends' => array(): Name of extended interfaces
  23. * 'stmts' => array(): Statements
  24. * @param array $attributes Additional attributes
  25. */
  26. public function __construct($name, array $subNodes = array(), array $attributes = array()) {
  27. parent::__construct(
  28. array(
  29. 'name' => $name,
  30. 'extends' => isset($subNodes['extends']) ? $subNodes['extends'] : array(),
  31. 'stmts' => isset($subNodes['stmts']) ? $subNodes['stmts'] : array(),
  32. ),
  33. $attributes
  34. );
  35. if (isset(self::$specialNames[(string) $this->name])) {
  36. throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name));
  37. }
  38. foreach ($this->extends as $interface) {
  39. if (isset(self::$specialNames[(string) $interface])) {
  40. throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface));
  41. }
  42. }
  43. }
  44. }