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:
24: namespace Thelia\Core;
25:
26: /**
27: * Root class of Thelia
28: *
29: * It extends Symfony\Component\HttpKernel\Kernel for changing some fonctionnality
30: *
31: *
32: * @author Manuel Raynaud <mraynaud@openstudio.fr>
33: */
34:
35: use Symfony\Component\DependencyInjection\ContainerBuilder;
36: use Symfony\Component\HttpKernel\Kernel;
37: use Symfony\Component\Config\Loader\LoaderInterface;
38: use Symfony\Component\Config\Definition\Processor;
39: use Symfony\Component\Config\ConfigCache;
40: use Symfony\Component\Config\Resource\FileResource;
41: use Symfony\Component\Config\Util\XmlUtils;
42: use Symfony\Component\Yaml\Yaml;
43: use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
44:
45:
46: use Thelia\Core\Bundle;
47: use Thelia\Log\Tlog;
48: use Thelia\Config\DatabaseConfiguration;
49: use Thelia\Config\DefinePropel;
50: use Thelia\Core\TheliaContainerBuilder;
51: use Thelia\Core\DependencyInjection\Loader\XmlFileLoader;
52: use Symfony\Component\Config\FileLocator;
53:
54: use Propel;
55: use PropelConfiguration;
56:
57: class Thelia extends Kernel
58: {
59:
60: protected $tpexConfig;
61:
62: public function init()
63: {
64: parent::init();
65: if($this->debug) {
66: ini_set('display_errors', 1);
67: }
68: $this->initPropel();
69: }
70:
71: protected function initPropel()
72: {
73: if (file_exists(THELIA_ROOT . '/local/config/database.yml') === false) {
74: return ;
75: }
76:
77: if(! Propel::isInit()) {
78:
79: $definePropel = new DefinePropel(new DatabaseConfiguration(),
80: Yaml::parse(THELIA_ROOT . '/local/config/database.yml'));
81:
82: Propel::setConfiguration($definePropel->getConfig());
83:
84: if ($this->isDebug()) {
85: Propel::setLogger(Tlog::getInstance());
86: $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
87: $config->setParameter('debugpdo.logging.details.method.enabled', true);
88: $config->setParameter('debugpdo.logging.details.time.enabled', true);
89: $config->setParameter('debugpdo.logging.details.mem.enabled', true);
90:
91: $con = Propel::getConnection("thelia");
92: $con->useDebug(true);
93: }
94:
95: Propel::initialize();
96: }
97: }
98:
99: /**
100: *
101: * Load some configuration
102: * Initialize all plugins
103: *
104: */
105: protected function loadConfiguration(ContainerBuilder $container)
106: {
107:
108: $loader = new XmlFileLoader($container, new FileLocator(THELIA_ROOT . "/core/lib/Thelia"));
109: $loader->load("config.xml");
110:
111: $modules = \Thelia\Model\ModuleQuery::getActivated();
112:
113: foreach ($modules as $module) {
114:
115: try {
116: $loader = new XmlFileLoader($container, new FileLocator(THELIA_PLUGIN_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
117: $loader->load("config.xml");
118: } catch(\InvalidArgumentException $e) {
119:
120: }
121: }
122: }
123:
124: /**
125: *
126: * initialize session in Request object
127: *
128: * All param must be change in Config table
129: *
130: * @param \Symfony\Component\HttpFoundation\Request $request
131: */
132:
133: /**
134: * Gets a new ContainerBuilder instance used to build the service container.
135: *
136: * @return ContainerBuilder
137: */
138: protected function getContainerBuilder()
139: {
140: return new TheliaContainerBuilder(new ParameterBag($this->getKernelParameters()));
141: }
142:
143: /**
144: * Builds the service container.
145: *
146: * @return ContainerBuilder The compiled service container
147: *
148: * @throws \RuntimeException
149: */
150: protected function buildContainer()
151: {
152: $container = parent::buildContainer();
153:
154: $this->loadConfiguration($container);
155: $container->customCompile();
156:
157: return $container;
158: }
159:
160: /**
161: * Gets the cache directory.
162: *
163: * @return string The cache directory
164: *
165: * @api
166: */
167: public function getCacheDir()
168: {
169: if (defined('THELIA_ROOT')) {
170: return THELIA_ROOT.'cache/'.$this->environment;
171: } else {
172: return parent::getCacheDir();
173: }
174:
175: }
176:
177: /**
178: * Gets the log directory.
179: *
180: * @return string The log directory
181: *
182: * @api
183: */
184: public function getLogDir()
185: {
186: if (defined('THELIA_ROOT')) {
187: return THELIA_ROOT.'log/';
188: } else {
189: return parent::getLogDir();
190: }
191: }
192:
193: /**
194: * return available bundle
195: *
196: * Part of Symfony\Component\HttpKernel\KernelInterface
197: *
198: * @return array An array of bundle instances.
199: *
200: */
201: public function registerBundles()
202: {
203: $bundles = array(
204: /* TheliaBundle contain all the dependency injection description */
205: new Bundle\TheliaBundle()
206: );
207:
208: /**
209: * OTHER CORE BUNDLE CAN BE DECLARE HERE AND INITIALIZE WITH SPECIFIC CONFIGURATION
210: *
211: * HOW TO DECLARE OTHER BUNDLE ? ETC
212: */
213:
214: return $bundles;
215:
216: }
217:
218: /**
219: * Loads the container configuration
220: *
221: * part of Symfony\Component\HttpKernel\KernelInterface
222: *
223: * @param LoaderInterface $loader A LoaderInterface instance
224: *
225: * @api
226: */
227: public function registerContainerConfiguration(LoaderInterface $loader)
228: {
229: //Nothing is load here but it's possible to load container configuration here.
230: //exemple in sf2 : $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
231: }
232:
233: }
234: