No Description

Namespace_.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Error;
  5. /**
  6. * @property null|Node\Name $name Name
  7. * @property Node[] $stmts Statements
  8. */
  9. class Namespace_ extends Node\Stmt
  10. {
  11. protected static $specialNames = array(
  12. 'self' => true,
  13. 'parent' => true,
  14. 'static' => true,
  15. );
  16. /**
  17. * Constructs a namespace node.
  18. *
  19. * @param null|Node\Name $name Name
  20. * @param Node[] $stmts Statements
  21. * @param array $attributes Additional attributes
  22. */
  23. public function __construct(Node\Name $name = null, $stmts = array(), array $attributes = array()) {
  24. parent::__construct(
  25. array(
  26. 'name' => $name,
  27. 'stmts' => $stmts,
  28. ),
  29. $attributes
  30. );
  31. if (isset(self::$specialNames[(string) $this->name])) {
  32. throw new Error(sprintf('Cannot use \'%s\' as namespace name', $this->name));
  33. }
  34. if (null !== $this->stmts) {
  35. foreach ($this->stmts as $stmt) {
  36. if ($stmt instanceof self) {
  37. throw new Error('Namespace declarations cannot be nested', $stmt->getLine());
  38. }
  39. }
  40. }
  41. }
  42. }