ComponentFactory
2 days ago
Control
2 days ago
Type
2 days ago
AttributeCollection.php
2 days ago
AttributeFactory.php
2 days ago
Children.php
2 days ago
Component.php
2 days ago
ComponentBuilder.php
2 days ago
ComponentCollection.php
2 days ago
ComponentFactory.php
2 days ago
ConditionalComponentFactory.php
2 days ago
ConditionalComponentFactoryCollection.php
2 days ago
Config.php
2 days ago
ConfigCollection.php
2 days ago
ConfigFactory.php
2 days ago
Context.php
2 days ago
Control.php
2 days ago
DefaultSettingsBuilder.php
2 days ago
Encoder.php
2 days ago
Formatter.php
2 days ago
FormatterCollection.php
2 days ago
Component.php
144 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Setting; |
| 6 | |
| 7 | use AC\Expression\NullSpecification; |
| 8 | use AC\Expression\Specification; |
| 9 | use AC\FormatterCollection; |
| 10 | use AC\Setting\Control\Input; |
| 11 | use InvalidArgumentException; |
| 12 | |
| 13 | class Component |
| 14 | { |
| 15 | private ?string $label; |
| 16 | |
| 17 | private ?string $description; |
| 18 | |
| 19 | private ?Input $input; |
| 20 | |
| 21 | private FormatterCollection $formatters; |
| 22 | |
| 23 | private ?Children $children; |
| 24 | |
| 25 | private $conditions; |
| 26 | |
| 27 | private AttributeCollection $attributes; |
| 28 | |
| 29 | private string $type; |
| 30 | |
| 31 | public function __construct( |
| 32 | ?string $label = null, |
| 33 | ?string $description = null, |
| 34 | ?Input $input = null, |
| 35 | ?Specification $conditions = null, |
| 36 | ?FormatterCollection $formatters = null, |
| 37 | ?Children $children = null, |
| 38 | ?AttributeCollection $attributes = null, |
| 39 | ?string $type = null |
| 40 | ) { |
| 41 | if ($conditions === null) { |
| 42 | $conditions = new NullSpecification(); |
| 43 | } |
| 44 | |
| 45 | if ($formatters === null) { |
| 46 | $formatters = new FormatterCollection(); |
| 47 | } |
| 48 | |
| 49 | if ($attributes === null) { |
| 50 | $attributes = new AttributeCollection(); |
| 51 | } |
| 52 | |
| 53 | if ($type === null) { |
| 54 | $type = 'default'; |
| 55 | } |
| 56 | |
| 57 | $this->label = $label; |
| 58 | $this->description = $description; |
| 59 | $this->input = $input; |
| 60 | $this->formatters = $formatters; |
| 61 | $this->children = $children; |
| 62 | $this->conditions = $conditions; |
| 63 | $this->attributes = $attributes; |
| 64 | $this->type = $type; |
| 65 | } |
| 66 | |
| 67 | public function has_label(): bool |
| 68 | { |
| 69 | return $this->label !== null; |
| 70 | } |
| 71 | |
| 72 | public function get_label(): string |
| 73 | { |
| 74 | if ($this->label === null) { |
| 75 | throw new InvalidArgumentException('No label provided.'); |
| 76 | } |
| 77 | |
| 78 | return $this->label; |
| 79 | } |
| 80 | |
| 81 | public function has_description(): bool |
| 82 | { |
| 83 | return $this->description !== null; |
| 84 | } |
| 85 | |
| 86 | public function get_description(): string |
| 87 | { |
| 88 | if ($this->description === null) { |
| 89 | throw new InvalidArgumentException('No description provided'); |
| 90 | } |
| 91 | |
| 92 | return $this->description; |
| 93 | } |
| 94 | |
| 95 | public function has_input(): bool |
| 96 | { |
| 97 | return $this->input !== null; |
| 98 | } |
| 99 | |
| 100 | public function get_input(): Input |
| 101 | { |
| 102 | if ($this->input === null) { |
| 103 | throw new InvalidArgumentException('No input provided.'); |
| 104 | } |
| 105 | |
| 106 | return $this->input; |
| 107 | } |
| 108 | |
| 109 | public function get_formatters(): FormatterCollection |
| 110 | { |
| 111 | return $this->formatters; |
| 112 | } |
| 113 | |
| 114 | public function has_children(): bool |
| 115 | { |
| 116 | return $this->children !== null; |
| 117 | } |
| 118 | |
| 119 | public function get_children(): Children |
| 120 | { |
| 121 | if ($this->children === null) { |
| 122 | throw new InvalidArgumentException('No children provided.'); |
| 123 | } |
| 124 | |
| 125 | return $this->children; |
| 126 | } |
| 127 | |
| 128 | public function get_conditions(): Specification |
| 129 | { |
| 130 | return $this->conditions; |
| 131 | } |
| 132 | |
| 133 | public function get_attributes(): AttributeCollection |
| 134 | { |
| 135 | return $this->attributes; |
| 136 | } |
| 137 | |
| 138 | public function get_type(): string |
| 139 | { |
| 140 | return $this->type; |
| 141 | } |
| 142 | |
| 143 | } |
| 144 |