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