Interface.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @property string $name Name
  4. * @property PHPParser_Node_Name[] $extends Extended interfaces
  5. * @property PHPParser_Node[] $stmts Statements
  6. */
  7. class PHPParser_Node_Stmt_Interface extends PHPParser_Node_Stmt
  8. {
  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(
  25. $subNodes + array(
  26. 'extends' => array(),
  27. 'stmts' => array(),
  28. ),
  29. $attributes
  30. );
  31. $this->name = $name;
  32. if (isset(self::$specialNames[(string) $this->name])) {
  33. throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $this->name));
  34. }
  35. foreach ($this->extends as $interface) {
  36. if (isset(self::$specialNames[(string) $interface])) {
  37. throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface));
  38. }
  39. }
  40. }
  41. }