1: <?php
2:
3: namespace Charcoal\Ui\ServiceProvider;
4:
5: use \Pimple\Container;
6: use \Pimple\ServiceProviderInterface;
7:
8: use \Charcoal\Ui\Menu\MenuBuilder;
9: use \Charcoal\Ui\Menu\MenuFactory;
10: use \Charcoal\Ui\MenuItem\MenuItemBuilder;
11: use \Charcoal\Ui\MenuItem\MenuItemFactory;
12:
13: 14: 15:
16: class MenuServiceProvider implements ServiceProviderInterface
17: {
18: 19: 20: 21:
22: public function register(Container $container)
23: {
24: $this->registerMenuServices($container);
25: $this->registerMenuItemServices($container);
26: }
27:
28: 29: 30: 31:
32: public function registerMenuServices(Container $container)
33: {
34: 35: 36: 37:
38: $container['menu/factory'] = function(Container $container) {
39: $menuFactory = new MenuFactory();
40: $menuFactory->setArguments([
41: 'menu_item_builder' => $container['menu/item/builder']
42: ]);
43: return $menuFactory;
44: };
45:
46: 47: 48: 49:
50: $container['menu/builder'] = function(Container $container) {
51: $menuFactory = $container['menu/factory'];
52: $menuBuilder = new MenuBuilder($menuFactory, $container);
53: return $menuBuilder;
54: };
55: }
56:
57: 58: 59: 60:
61: public function registerMenuItemServices(Container $container)
62: {
63: 64: 65: 66:
67: $container['menu/item/factory'] = function(Container $container) {
68: $menuItemFactory = new MenuItemFactory();
69: return $menuItemFactory;
70: };
71:
72: 73: 74: 75:
76: $container['menu/item/builder'] = function(Container $container) {
77: $menuItemFactory = $container['menu/item/factory'];
78: $menuItemBuilder = new MenuItemBuilder($menuItemFactory, $container);
79: return $menuItemBuilder;
80: };
81: }
82: }
83: