1: <?php
2:
3: namespace Charcoal\App\Template;
4:
5: use InvalidArgumentException;
6:
7:
8: use Pimple\Container;
9:
10:
11: use Charcoal\Factory\FactoryInterface;
12:
13: 14: 15:
16: class WidgetBuilder
17: {
18: 19: 20:
21: protected $factory;
22:
23: 24: 25: 26:
27: protected $container;
28:
29: 30: 31: 32:
33: public function __construct(FactoryInterface $factory, Container $container)
34: {
35: $this->factory = $factory;
36: $this->container = $container;
37: }
38:
39: 40: 41: 42: 43:
44: public function build($options)
45: {
46: if (isset($options['controller'])) {
47: $objType = $options['controller'];
48: } elseif (isset($options['type'])) {
49: $objType = $options['type'];
50: } else {
51: throw new InvalidArgumentException('Undefined widget type');
52: }
53:
54: $obj = $this->factory->create($objType);
55: $obj->setData($options);
56:
57: return $obj;
58: }
59: }
60: