1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | namespace PhpParser\Builder; |
6: | |
7: | use PhpParser; |
8: | use PhpParser\BuilderHelpers; |
9: | use PhpParser\Node; |
10: | use PhpParser\Node\Identifier; |
11: | use PhpParser\Node\Stmt; |
12: | |
13: | class EnumCase implements PhpParser\Builder { |
14: | |
15: | protected $name; |
16: | protected ?Node\Expr $value = null; |
17: | |
18: | protected array $attributes = []; |
19: | |
20: | |
21: | protected array $attributeGroups = []; |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | public function __construct($name) { |
29: | $this->name = $name; |
30: | } |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | public function setValue($value) { |
40: | $this->value = BuilderHelpers::normalizeValue($value); |
41: | |
42: | return $this; |
43: | } |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | public function setDocComment($docComment) { |
53: | $this->attributes = [ |
54: | 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] |
55: | ]; |
56: | |
57: | return $this; |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | public function addAttribute($attribute) { |
68: | $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
69: | |
70: | return $this; |
71: | } |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | public function getNode(): PhpParser\Node { |
79: | return new Stmt\EnumCase( |
80: | $this->name, |
81: | $this->value, |
82: | $this->attributeGroups, |
83: | $this->attributes |
84: | ); |
85: | } |
86: | } |
87: | |