Use_.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node\Stmt;
  4. use PhpParser\Node\UseItem;
  5. class Use_ extends Stmt {
  6. /**
  7. * Unknown type. Both Stmt\Use_ / Stmt\GroupUse and Stmt\UseUse have a $type property, one of them will always be
  8. * TYPE_UNKNOWN while the other has one of the three other possible types. For normal use statements the type on the
  9. * Stmt\UseUse is unknown. It's only the other way around for mixed group use declarations.
  10. */
  11. public const TYPE_UNKNOWN = 0;
  12. /** Class or namespace import */
  13. public const TYPE_NORMAL = 1;
  14. /** Function import */
  15. public const TYPE_FUNCTION = 2;
  16. /** Constant import */
  17. public const TYPE_CONSTANT = 3;
  18. /** @var self::TYPE_* Type of alias */
  19. public int $type;
  20. /** @var UseItem[] Aliases */
  21. public array $uses;
  22. /**
  23. * Constructs an alias (use) list node.
  24. *
  25. * @param UseItem[] $uses Aliases
  26. * @param Stmt\Use_::TYPE_* $type Type of alias
  27. * @param array<string, mixed> $attributes Additional attributes
  28. */
  29. public function __construct(array $uses, int $type = self::TYPE_NORMAL, array $attributes = []) {
  30. $this->attributes = $attributes;
  31. $this->type = $type;
  32. $this->uses = $uses;
  33. }
  34. public function getSubNodeNames(): array {
  35. return ['type', 'uses'];
  36. }
  37. public function getType(): string {
  38. return 'Stmt_Use';
  39. }
  40. }