Interface_.php 1.6 KB

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