Extended
1 day ago
ExtendedValueLink.php
1 day ago
ExtendedValueLinkFactory.php
1 day ago
ExtendedValueRegistry.php
1 day ago
ExtendedValueRegistry.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Value; |
| 6 | |
| 7 | use AC\Value\Extended\ExtendedValue; |
| 8 | use LogicException; |
| 9 | |
| 10 | class ExtendedValueRegistry |
| 11 | { |
| 12 | private static array $views = []; |
| 13 | |
| 14 | public static function add(ExtendedValue $view): void |
| 15 | { |
| 16 | self::$views[] = $view; |
| 17 | } |
| 18 | |
| 19 | public function has_view(string $name): bool |
| 20 | { |
| 21 | foreach (self::$views as $view) { |
| 22 | if ($view->can_render($name)) { |
| 23 | return true; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | public function get_view(string $name): ExtendedValue |
| 31 | { |
| 32 | foreach (self::$views as $view) { |
| 33 | if ($view->can_render($name)) { |
| 34 | return $view; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | throw new LogicException('No extended value found for view: ' . $name); |
| 39 | } |
| 40 | |
| 41 | } |
| 42 |