assets
2 weeks ago
sources
2 months ago
class-ecs-drb-mapper.php
2 months ago
class-ecs-drb-sources.php
2 months ago
class-ecs-dynamic-repeater-module.php
2 weeks ago
class-ecs-drb-sources.php
47 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Dynamic Repeater Builder — Source Registry |
| 4 | */ |
| 5 | |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit; |
| 8 | } |
| 9 | |
| 10 | class ECS_DRB_Sources { |
| 11 | |
| 12 | private static ?self $instance = null; |
| 13 | |
| 14 | /** @var ECS_DRB_Source_Base[] */ |
| 15 | private array $sources = []; |
| 16 | |
| 17 | public static function instance(): self { |
| 18 | if ( null === self::$instance ) { |
| 19 | self::$instance = new self(); |
| 20 | } |
| 21 | return self::$instance; |
| 22 | } |
| 23 | |
| 24 | private function __construct() {} |
| 25 | |
| 26 | public function register( ECS_DRB_Source_Base $source ): void { |
| 27 | $this->sources[ $source->get_id() ] = $source; |
| 28 | } |
| 29 | |
| 30 | public function get( string $id ): ?ECS_DRB_Source_Base { |
| 31 | return $this->sources[ $id ] ?? null; |
| 32 | } |
| 33 | |
| 34 | /** @return ECS_DRB_Source_Base[] */ |
| 35 | public function get_all(): array { |
| 36 | return $this->sources; |
| 37 | } |
| 38 | |
| 39 | /** Compact list for wp_localize_script. */ |
| 40 | public function get_list_for_js(): array { |
| 41 | return array_values( array_map( fn( $s ) => [ |
| 42 | 'id' => $s->get_id(), |
| 43 | 'label' => $s->get_label(), |
| 44 | ], $this->sources ) ); |
| 45 | } |
| 46 | } |
| 47 |