DateFormat
2 days ago
FieldTypeConfigurator
2 days ago
Media
2 days ago
Post
2 days ago
Pro
2 days ago
ActionIcons.php
2 days ago
AttachmentDisplay.php
2 days ago
BaseComponentFactory.php
2 days ago
BeforeAfter.php
2 days ago
BooleanValues.php
2 days ago
CharacterLimit.php
2 days ago
ColumnInfo.php
2 days ago
CommentDisplay.php
2 days ago
CommentLink.php
2 days ago
CommentStatus.php
2 days ago
CustomField.php
2 days ago
CustomFieldFactory.php
2 days ago
DateFormat.php
2 days ago
DateSaveFormat.php
2 days ago
ExifData.php
2 days ago
FieldType.php
2 days ago
FieldTypeFactory.php
2 days ago
FieldTypeFactoryBuilder.php
2 days ago
FileDisplay.php
2 days ago
FileLink.php
2 days ago
FilePreviewSize.php
2 days ago
HiddenInput.php
2 days ago
HiddenLabel.php
2 days ago
ImageSize.php
2 days ago
ImageSizeBase.php
2 days ago
IncludeMissingSizes.php
2 days ago
InputNameAware.php
2 days ago
IsLink.php
2 days ago
IsLinkable.php
2 days ago
IsMultiple.php
2 days ago
Label.php
2 days ago
LinkLabel.php
2 days ago
LinkToMenu.php
2 days ago
LinkablePostProperty.php
2 days ago
MediaLink.php
2 days ago
Message.php
2 days ago
ModalDisplay.php
2 days ago
Name.php
2 days ago
NumberFormat.php
2 days ago
NumberOfItems.php
2 days ago
Password.php
2 days ago
PathScope.php
2 days ago
PostExtendedProperty.php
2 days ago
PostLink.php
2 days ago
PostProperty.php
2 days ago
PostStatus.php
2 days ago
PostStatusIcon.php
2 days ago
PostType.php
2 days ago
PostTypeFactory.php
2 days ago
RelatedUserMetaField.php
2 days ago
SelectOptions.php
2 days ago
Separator.php
2 days ago
SerializedArrayKeys.php
2 days ago
SerializedDisplay.php
2 days ago
StringLimit.php
2 days ago
Taxonomy.php
2 days ago
TaxonomyFactory.php
2 days ago
TermLink.php
2 days ago
TermProperty.php
2 days ago
UseIcon.php
2 days ago
UserLink.php
2 days ago
UserLinkFactory.php
2 days ago
UserProperty.php
2 days ago
VideoDisplay.php
2 days ago
Width.php
2 days ago
WordLimit.php
2 days ago
WordsPerMinute.php
2 days ago
BaseComponentFactory.php
134 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Setting\ComponentFactory; |
| 6 | |
| 7 | use AC\Expression\Specification; |
| 8 | use AC\FormatterCollection; |
| 9 | use AC\Setting\AttributeCollection; |
| 10 | use AC\Setting\Children; |
| 11 | use AC\Setting\Component; |
| 12 | use AC\Setting\ComponentBuilder; |
| 13 | use AC\Setting\ComponentCollection; |
| 14 | use AC\Setting\ComponentFactory; |
| 15 | use AC\Setting\Config; |
| 16 | use AC\Setting\Control\Input; |
| 17 | |
| 18 | abstract class BaseComponentFactory implements ComponentFactory |
| 19 | { |
| 20 | public function create(Config $config, ?Specification $conditions = null): Component |
| 21 | { |
| 22 | $builder = new ComponentBuilder(); |
| 23 | $formatters = new FormatterCollection(); |
| 24 | $attributes = new AttributeCollection(); |
| 25 | |
| 26 | if ($conditions !== null) { |
| 27 | $builder->set_conditions($conditions); |
| 28 | } |
| 29 | |
| 30 | $label = $this->get_label($config); |
| 31 | |
| 32 | if ($label !== null) { |
| 33 | $builder->set_label($label); |
| 34 | } |
| 35 | |
| 36 | $description = $this->get_description($config); |
| 37 | |
| 38 | if ($description !== null) { |
| 39 | $builder->set_description($description); |
| 40 | } |
| 41 | |
| 42 | $input = $this->get_input($config); |
| 43 | |
| 44 | if ($input !== null) { |
| 45 | $builder->set_input($input); |
| 46 | } |
| 47 | |
| 48 | $this->add_formatters($config, $formatters); |
| 49 | |
| 50 | $children = $this->get_children($config); |
| 51 | |
| 52 | if ($children !== null) { |
| 53 | $builder->set_children($children); |
| 54 | |
| 55 | $this->add_component_formatters( |
| 56 | $formatters, |
| 57 | $children->get_iterator(), |
| 58 | $input |
| 59 | ? (string)$input->get_value() |
| 60 | : null |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | $this->add_final_formatters($config, $formatters); |
| 65 | |
| 66 | $builder->set_formatters($formatters); |
| 67 | |
| 68 | $builder->set_attributes( |
| 69 | $this->get_attributes($config, $attributes) |
| 70 | ); |
| 71 | |
| 72 | $type = $this->get_type($config); |
| 73 | |
| 74 | if ($type !== null) { |
| 75 | $builder->set_type($type); |
| 76 | } |
| 77 | |
| 78 | return $builder->build(); |
| 79 | } |
| 80 | |
| 81 | protected function get_label(Config $config): ?string |
| 82 | { |
| 83 | return null; |
| 84 | } |
| 85 | |
| 86 | protected function get_description(Config $config): ?string |
| 87 | { |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | protected function get_input(Config $config): ?Input |
| 92 | { |
| 93 | return null; |
| 94 | } |
| 95 | |
| 96 | protected function add_component_formatters( |
| 97 | FormatterCollection $formatters, |
| 98 | ComponentCollection $components, |
| 99 | ?string $condition = null |
| 100 | ): void { |
| 101 | foreach ($components as $component) { |
| 102 | if ($component->get_conditions()->is_satisfied_by((string)$condition)) { |
| 103 | foreach ($component->get_formatters() as $formatter) { |
| 104 | $formatters->add($formatter); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | protected function add_formatters(Config $config, FormatterCollection $formatters): void |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | protected function add_final_formatters(Config $config, FormatterCollection $formatters): void |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | protected function get_children(Config $config): ?Children |
| 119 | { |
| 120 | return null; |
| 121 | } |
| 122 | |
| 123 | protected function get_attributes(Config $config, AttributeCollection $attributes): AttributeCollection |
| 124 | { |
| 125 | return $attributes; |
| 126 | } |
| 127 | |
| 128 | protected function get_type(Config $config): ?string |
| 129 | { |
| 130 | return null; |
| 131 | } |
| 132 | |
| 133 | } |
| 134 |