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('tpex', 'Thelia\Tpex\Tpex');
73:
74: $container->register('parser','Thelia\Core\Template\Parser')
75: ->addArgument(new Reference('service_container'))
76: ->addArgument(new Reference('tpex'))
77: ;
78: /**
79: * RouterListener implements EventSubscriberInterface and listen for kernel.request event
80: */
81: $container->register('listener.router', 'Symfony\Component\HttpKernel\EventListener\RouterListener')
82: ->addArgument(new Reference('matcher'))
83: ;
84:
85: /**
86: * @TODO add an other listener on kernel.request for checking some params Like check if User is log in, set the language and other.
87: *
88: * $container->register()
89: *
90: *
91: * $container->register('listener.request', 'Thelia\Core\EventListener\RequestListener')
92: * ->addArgument(new Reference('');
93: * ;
94: */
95:
96: $container->register('thelia.listener.view','Thelia\Core\EventListener\ViewListener')
97: ->addArgument(new Reference('service_container'))
98: ;
99:
100:
101:
102: $container->register('dispatcher','Symfony\Component\EventDispatcher\EventDispatcher')
103: ->addArgument(new Reference('service_container'))
104: ->addMethodCall('addSubscriber', array(new Reference('listener.router')))
105: ->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view')))
106: ;
107:
108:
109: // TODO : save listener from plugins
110:
111: $container->getDefinition('matcher.action')->addMethodCall("setDispatcher", array(new Reference('dispatcher')));
112:
113: $container->register('http_kernel','Thelia\Core\TheliaHttpKernel')
114: ->addArgument(new Reference('dispatcher'))
115: ->addArgument(new Reference('service_container'))
116: ->addArgument(new Reference('resolver'))
117: ;
118:
119: // DEFINE DEFAULT PARAMETER LIKE
120:
121: /**
122: * @TODO learn about container compilation
123: */
124:
125: }
126: }
127: