1: <?php
2:
3: namespace Charcoal\Ui\Dashboard;
4:
5: use \Pimple\Container;
6:
7: // From 'charcoal-factory'
8: use \Charcoal\Factory\FactoryInterface;
9:
10: /**
11: * Dashboard Builder
12: */
13: class DashboardBuilder
14: {
15: /**
16: * The default, concrete, dashboard model.
17: *
18: * @const string
19: */
20: const DEFAULT_TYPE = 'charcoal/ui/dashboard/generic';
21:
22: /**
23: * Store the dashboard factory instance.
24: *
25: * @var FactoryInterface
26: */
27: protected $factory;
28:
29: /**
30: * Store the dependency-injection container to fulfill the required services.
31: *
32: * @var Container $container
33: */
34: protected $container;
35:
36: /**
37: * Return a new dashboard builder.
38: *
39: * @param FactoryInterface $factory A dashboard factory.
40: * @param Container $container The DI container.
41: */
42: public function __construct(FactoryInterface $factory, Container $container)
43: {
44: $this->factory = $factory;
45: $this->container = $container;
46: }
47:
48: /**
49: * Build and return a new dashboard.
50: *
51: * @param array|\ArrayAccess $options The dashboard build options.
52: * @return DashboardInterface
53: */
54: public function build($options)
55: {
56: $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE;
57:
58: $obj = $this->factory->create($objType);
59: $obj->setData($options);
60:
61: return $obj;
62: }
63: }
64: