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
ComponentBuilder.php
112 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Setting; |
| 6 | |
| 7 | use AC\Expression\Specification; |
| 8 | use AC\Formatter; |
| 9 | use AC\FormatterCollection; |
| 10 | use AC\Setting\Control\Input; |
| 11 | |
| 12 | final class ComponentBuilder |
| 13 | { |
| 14 | private ?string $label = null; |
| 15 | |
| 16 | private ?string $description = null; |
| 17 | |
| 18 | private ?Input $input = null; |
| 19 | |
| 20 | private ?Specification $conditions = null; |
| 21 | |
| 22 | private ?FormatterCollection $formatters = null; |
| 23 | |
| 24 | private ?Children $children = null; |
| 25 | |
| 26 | private ?AttributeCollection $attributes = null; |
| 27 | |
| 28 | private ?string $type = null; |
| 29 | |
| 30 | public function set_label(string $label): self |
| 31 | { |
| 32 | $this->label = $label; |
| 33 | |
| 34 | return $this; |
| 35 | } |
| 36 | |
| 37 | public function set_description(string $description): self |
| 38 | { |
| 39 | $this->description = $description; |
| 40 | |
| 41 | return $this; |
| 42 | } |
| 43 | |
| 44 | public function set_input(Input $input): self |
| 45 | { |
| 46 | $this->input = $input; |
| 47 | |
| 48 | return $this; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Null conveniently allowed to pass on |
| 53 | */ |
| 54 | public function set_conditions(Specification $conditions): self |
| 55 | { |
| 56 | $this->conditions = $conditions; |
| 57 | |
| 58 | return $this; |
| 59 | } |
| 60 | |
| 61 | public function set_formatters(FormatterCollection $formatters): self |
| 62 | { |
| 63 | $this->formatters = $formatters; |
| 64 | |
| 65 | return $this; |
| 66 | } |
| 67 | |
| 68 | public function set_formatter(Formatter $formatter): self |
| 69 | { |
| 70 | $formatters = new FormatterCollection(); |
| 71 | $formatters->add($formatter); |
| 72 | |
| 73 | return $this->set_formatters($formatters); |
| 74 | } |
| 75 | |
| 76 | public function set_children(Children $children): self |
| 77 | { |
| 78 | $this->children = $children; |
| 79 | |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | public function set_attributes(AttributeCollection $attributes): self |
| 84 | { |
| 85 | $this->attributes = $attributes; |
| 86 | |
| 87 | return $this; |
| 88 | } |
| 89 | |
| 90 | public function set_type(string $type): self |
| 91 | { |
| 92 | $this->type = $type; |
| 93 | |
| 94 | return $this; |
| 95 | } |
| 96 | |
| 97 | public function build(): Component |
| 98 | { |
| 99 | return new Component( |
| 100 | $this->label, |
| 101 | $this->description, |
| 102 | $this->input, |
| 103 | $this->conditions, |
| 104 | $this->formatters, |
| 105 | $this->children, |
| 106 | $this->attributes, |
| 107 | $this->type |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | } |
| 112 |