1: <?php
2: /*************************************************************************************/
3: /* */
4: /* Thelia */
5: /* */
6: /* Copyright (c) OpenStudio */
7: /* email : info@thelia.net */
8: /* web : http://www.thelia.net */
9: /* */
10: /* This program is free software; you can redistribute it and/or modify */
11: /* it under the terms of the GNU General Public License as published by */
12: /* the Free Software Foundation; either version 3 of the License */
13: /* */
14: /* This program is distributed in the hope that it will be useful, */
15: /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16: /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17: /* GNU General Public License for more details. */
18: /* */
19: /* You should have received a copy of the GNU General Public License */
20: /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
21: /* */
22: /*************************************************************************************/
23: namespace Thelia\Core\Bundle;
24:
25: use Symfony\Component\HttpKernel\Bundle\Bundle;
26: use Symfony\Component\DependencyInjection\ContainerBuilder;
27: use Symfony\Component\DependencyInjection\Reference;
28: use Symfony\Component\DependencyInjection\Scope;
29:
30: /**
31: * First Bundle use in Thelia
32: * It initialize dependency injection container.
33: *
34: * @TODO load configuration from thelia plugin
35: * @TODO register database configuration.
36: *
37: *
38: * @author Manuel Raynaud <mraynaud@openstudio.fr>
39: */
40:
41: class TheliaBundle extends Bundle
42: {
43: /**
44: *
45: * Construct the depency injection builder
46: *
47: * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
48: */
49:
50: public function build(ContainerBuilder $container)
51: {
52: $container->addScope( new Scope('request'));
53:
54: $container->register('request', 'Symfony\Component\HttpFoundation\Request')
55: ->setSynthetic(true);
56:
57: $container->register('controller.default','Thelia\Controller\DefaultController');
58: $container->register('matcher.default','Thelia\Routing\Matcher\DefaultMatcher')
59: ->addArgument(new Reference('controller.default'));
60:
61: $container->register('matcher.action', 'Thelia\Routing\Matcher\ActionMatcher');
62:
63: $container->register('matcher','Thelia\Routing\TheliaMatcherCollection')
64: ->addMethodCall('add', array(new Reference('matcher.default'), -255))
65: ->addMethodCall('add', array(new Reference('matcher.action'), -200))
66: //->addMethodCall('add','a matcher class (instance or class name)
67:
68: ;
69:
70: $container->register('resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver');
71:
72: $container->register('parser','Thelia\Core\Template\Parser')
73: ->addArgument(new Reference('service_container'))
74: ;
75: /**
76: * RouterListener implements EventSubscriberInterface and listen for kernel.request event
77: */
78: $container->register('listener.router', 'Symfony\Component\HttpKernel\EventListener\RouterListener')
79: ->addArgument(new Reference('matcher'))
80: ;
81:
82: /**
83: * @TODO add an other listener on kernel.request for checking some params Like check if User is log in, set the language and other.
84: *
85: * $container->register()
86: *
87: *
88: * $container->register('listener.request', 'Thelia\Core\EventListener\RequestListener')
89: * ->addArgument(new Reference('');
90: * ;
91: */
92:
93: $container->register('thelia.listener.view','Thelia\Core\EventListener\ViewListener')
94: ->addArgument(new Reference('service_container'))
95: ;
96:
97:
98:
99: $container->register('dispatcher','Symfony\Component\EventDispatcher\EventDispatcher')
100: ->addArgument(new Reference('service_container'))
101: ->addMethodCall('addSubscriber', array(new Reference('listener.router')))
102: ->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view')))
103: ;
104:
105:
106: // TODO : save listener from plugins
107:
108: $container->getDefinition('matcher.action')->addMethodCall("setDispatcher", array(new Reference('dispatcher')));
109:
110: $container->register('http_kernel','Thelia\Core\TheliaHttpKernel')
111: ->addArgument(new Reference('dispatcher'))
112: ->addArgument(new Reference('service_container'))
113: ->addArgument(new Reference('resolver'))
114: ;
115:
116: // DEFINE DEFAULT PARAMETER LIKE
117:
118: /**
119: * @TODO learn about container compilation
120: */
121:
122: }
123: }
124: