1: | <?php declare(strict_types=1); |
2: | |
3: | namespace PhpParser\Builder; |
4: | |
5: | use PhpParser\Builder; |
6: | use PhpParser\BuilderHelpers; |
7: | use PhpParser\Node; |
8: | use PhpParser\Node\Stmt; |
9: | |
10: | class Use_ implements Builder { |
11: | protected Node\Name $name; |
12: | |
13: | protected int $type; |
14: | protected ?string $alias = null; |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | public function __construct($name, int $type) { |
23: | $this->name = BuilderHelpers::normalizeName($name); |
24: | $this->type = $type; |
25: | } |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | public function as(string $alias) { |
35: | $this->alias = $alias; |
36: | return $this; |
37: | } |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | public function getNode(): Node { |
45: | return new Stmt\Use_([ |
46: | new Node\UseItem($this->name, $this->alias) |
47: | ], $this->type); |
48: | } |
49: | } |
50: | |