| @@ 44-51 (lines=8) @@ | ||
| 41 | * @param string $class_name |
|
| 42 | * @throws \RuntimeException |
|
| 43 | */ |
|
| 44 | public static function register( $type, $class_name ) |
|
| 45 | { |
|
| 46 | if( !in_array($type, self::$registered_components) ) |
|
| 47 | { |
|
| 48 | self::$registered_components[$type] = $class_name; |
|
| 49 | } |
|
| 50 | else throw new \RuntimeException("A component of type '$type' has already been registered."); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * |
|
| @@ 86-95 (lines=10) @@ | ||
| 83 | * @param type $props |
|
| 84 | * @throws \RuntimeException |
|
| 85 | */ |
|
| 86 | private static function create_registered_component( $type, $props ) |
|
| 87 | { |
|
| 88 | if(in_array($type, self::$registered_components)) |
|
| 89 | { |
|
| 90 | $class_name = self::$registered_components[$type]; |
|
| 91 | return new $class_name($props); |
|
| 92 | } |
|
| 93 | ||
| 94 | throw new \RuntimeException("A component of type '$type' has not been registered."); |
|
| 95 | } |
|
| 96 | ||
| 97 | /** |
|
| 98 | * Private constructor to prevent instantiation |
|