1 | <?php |
||
17 | class WidgetManager implements WidgetLocatorInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $widgets; |
||
23 | |||
24 | 17 | private function __construct() |
|
27 | |||
28 | 17 | public static function create(array $widgets) : WidgetManager |
|
38 | |||
39 | 10 | public static function createWithDefaultWidgets() : WidgetManager |
|
46 | |||
47 | 17 | public function registerWidget(string $widgetId, $widget) |
|
48 | { |
||
49 | 17 | if (!($widget instanceof WidgetInterface || is_string($widget) || is_callable($widget))) { |
|
50 | 1 | throw InvalidWidgetConfigurationException::forConfiguration($widgetId, $widget); |
|
51 | } |
||
52 | |||
53 | 16 | $widgetId = strtolower($widgetId); |
|
54 | |||
55 | 16 | $this->widgets[$widgetId] = $widget; |
|
56 | 16 | } |
|
57 | |||
58 | 4 | public function has(string $widgetId) : bool |
|
64 | |||
65 | 10 | public function get(string $widgetId) : WidgetInterface |
|
81 | |||
82 | 8 | protected function createWidget($widgetId) |
|
96 | } |