1: <?php
2:
3: namespace Charcoal\Ui\MenuItem;
4:
5: use \Pimple\Container;
6:
7: use \Charcoal\Factory\FactoryInterface;
8:
9: 10: 11:
12: class MenuItemBuilder
13: {
14: 15: 16: 17: 18:
19: const DEFAULT_TYPE = 'charcoal/ui/menu-item/generic';
20:
21: 22: 23: 24: 25:
26: protected $factory;
27:
28: 29: 30: 31: 32:
33: protected $container;
34:
35: 36: 37: 38: 39: 40:
41: public function __construct(FactoryInterface $factory, Container $container)
42: {
43: $this->factory = $factory;
44: $this->container = $container;
45: }
46:
47: 48: 49: 50: 51: 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: 'menu' => $options['menu'],
60: 'logger' => $container['logger'],
61: 'view' => $container['view'],
62: 'menu_item_builder' => $container['menu/item/builder'],
63: 'container' => $container
64: ]);
65: $obj->setData($options);
66:
67: return $obj;
68: }
69: }
70: