Base.php
2 days ago
BaseColumnFactory.php
2 days ago
ColumnFactory.php
2 days ago
ColumnIdGenerator.php
2 days ago
ColumnLabelTrait.php
2 days ago
Context.php
2 days ago
CustomFieldContext.php
2 days ago
GroupTrait.php
2 days ago
LabelEncoder.php
2 days ago
SettingUpdater.php
2 days ago
ColumnFactory.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Column; |
| 6 | |
| 7 | use AC\Column; |
| 8 | use AC\FormatterCollection; |
| 9 | use AC\Setting\ComponentCollection; |
| 10 | use AC\Setting\Config; |
| 11 | use AC\Type\ColumnId; |
| 12 | |
| 13 | abstract class ColumnFactory |
| 14 | { |
| 15 | abstract public function create(Config $config): Column; |
| 16 | |
| 17 | abstract public function get_column_type(): string; |
| 18 | |
| 19 | abstract public function get_label(): string; |
| 20 | |
| 21 | protected function resolve_id(Config $config): ColumnId |
| 22 | { |
| 23 | $id = (string)$config->get('name'); |
| 24 | |
| 25 | if (ColumnId::is_valid_id($id)) { |
| 26 | return new ColumnId($id); |
| 27 | } |
| 28 | |
| 29 | return (new ColumnIdGenerator())->generate(); |
| 30 | } |
| 31 | |
| 32 | public function get_description(): ?string |
| 33 | { |
| 34 | return null; |
| 35 | } |
| 36 | |
| 37 | protected function get_settings(Config $config): ComponentCollection |
| 38 | { |
| 39 | return new ComponentCollection(); |
| 40 | } |
| 41 | |
| 42 | protected function get_context(Config $config): Context |
| 43 | { |
| 44 | return new Context($config, $this->get_label()); |
| 45 | } |
| 46 | |
| 47 | protected function get_formatters(Config $config): FormatterCollection |
| 48 | { |
| 49 | return $this->get_formatters_from_settings( |
| 50 | $this->get_settings($config) |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | private function get_formatters_from_settings(ComponentCollection $settings): FormatterCollection |
| 55 | { |
| 56 | $formatters = new FormatterCollection(); |
| 57 | |
| 58 | foreach ($settings as $setting) { |
| 59 | foreach ($setting->get_formatters() as $formatter) { |
| 60 | $formatters->add($formatter); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return $formatters; |
| 65 | } |
| 66 | |
| 67 | } |
| 68 |