UseUse.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Error;
  5. class UseUse extends Node\Stmt
  6. {
  7. /** @var int One of the Stmt\Use_::TYPE_* constants. Will only differ from TYPE_UNKNOWN for mixed group uses */
  8. public $type;
  9. /** @var Node\Name Namespace, class, function or constant to alias */
  10. public $name;
  11. /** @var string Alias */
  12. public $alias;
  13. /**
  14. * Constructs an alias (use) node.
  15. *
  16. * @param Node\Name $name Namespace/Class to alias
  17. * @param null|string $alias Alias
  18. * @param int $type Type of the use element (for mixed group use declarations only)
  19. * @param array $attributes Additional attributes
  20. */
  21. public function __construct(Node\Name $name, $alias = null, $type = Use_::TYPE_UNKNOWN, array $attributes = array()) {
  22. if (null === $alias) {
  23. $alias = $name->getLast();
  24. }
  25. if ('self' == strtolower($alias) || 'parent' == strtolower($alias)) {
  26. throw new Error(sprintf(
  27. 'Cannot use %s as %s because \'%2$s\' is a special class name',
  28. $name, $alias
  29. ));
  30. }
  31. parent::__construct($attributes);
  32. $this->type = $type;
  33. $this->name = $name;
  34. $this->alias = $alias;
  35. }
  36. public function getSubNodeNames() {
  37. return array('type', 'name', 'alias');
  38. }
  39. }