# File core/lib/Thelia/Core/Thelia.php | thelia

      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\HttpKernel\Kernel;
     36: use Symfony\Component\Config\Loader\LoaderInterface;
     37:
     38:
     39: use Thelia\Core\Bundle;
     40: use Thelia\Log\Tlog;
     41:
     42: use Propel;
     43: use PropelConfiguration;
     44:
     45: class Thelia extends Kernel
     46: {
     47:
     48:     public function init()
     49:     {
     50:         parent::init();
     51:
     52:         $this->initPropel();
     53:     }
     54:
     55:     protected function initPropel()
     56:     {
     57:         if (file_exists(THELIA_ROOT . '/local/config/config_db.php') === false) {
     58:             return ;
     59:         }
     60:         Propel::init(THELIA_CONF_DIR . "/config_thelia.php");
     61:
     62:         if ($this->isDebug()) {
     63:             Propel::setLogger(Tlog::getInstance());
     64:             $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
     65:             $config->setParameter('debugpdo.logging.details.method.enabled', true);
     66:             $config->setParameter('debugpdo.logging.details.time.enabled', true);
     67:             $config->setParameter('debugpdo.logging.details.mem.enabled', true);
     68:
     69:             $con = Propel::getConnection("thelia");
     70:             $con->useDebug(true);
     71:         }
     72:     }
     73:
     74:     /**
     75:      *
     76:      * Load some configuration
     77:      * Initialize all plugins
     78:      *
     79:      */
     80:     public function loadConfiguration()
     81:     {
     82:
     83:     }
     84:
     85:     /**
     86:      *
     87:      * initialize session in Request object
     88:      *
     89:      * All param must be change in Config table
     90:      *
     91:      * @param \Symfony\Component\HttpFoundation\Request $request
     92:      */
     93:
     94:
     95:     /**
     96:      *
     97:      * boot parent kernel and after current kernel
     98:      *
     99:      */
    100:     public function boot()
    101:     {
    102:
    103:
    104:
    105:         parent::boot();
    106:
    107:         $this->loadConfiguration();
    108:     }
    109:
    110:     /**
    111:      * Gets the cache directory.
    112:      *
    113:      * @return string The cache directory
    114:      *
    115:      * @api
    116:      */
    117:     public function getCacheDir()
    118:     {
    119:         if (defined('THELIA_ROOT')) {
    120:             return THELIA_ROOT.'cache/'.$this->environment;
    121:         } else {
    122:             return parent::getCacheDir();
    123:         }
    124:
    125:     }
    126:
    127:     /**
    128:      * Gets the log directory.
    129:      *
    130:      * @return string The log directory
    131:      *
    132:      * @api
    133:      */
    134:     public function getLogDir()
    135:     {
    136:         if (defined('THELIA_ROOT')) {
    137:             return THELIA_ROOT.'log/';
    138:         } else {
    139:             return parent::getLogDir();
    140:         }
    141:     }
    142:
    143:     /**
    144:      * Builds the service container.
    145:      *
    146:      * @return ContainerBuilder The compiled service container
    147:      */
    148: //    protected function buildContainer()
    149: //    {
    150: //        $container = $this->getContainerBuilder();
    151: //        $container->set('kernel', $this);
    152: //
    153: //        foreach ($this->bundles as $bundle) {
    154: //            $bundle->build($container);
    155: //        }
    156: //
    157: //        return $container;
    158: //    }
    159:
    160:     /**
    161:      * return available bundle
    162:      *
    163:      * Part of Symfony\Component\HttpKernel\KernelInterface
    164:      *
    165:      * @return array An array of bundle instances.
    166:      *
    167:      */
    168:     public function registerBundles()
    169:     {
    170:         $bundles = array(
    171:             /* TheliaBundle contain all the dependency injection description */
    172:             new Bundle\TheliaBundle()
    173:         );
    174:
    175:         /**
    176:          * OTHER CORE BUNDLE CAN BE DECLARE HERE AND INITIALIZE WITH SPECIFIC CONFIGURATION
    177:          *
    178:          * HOW TO DECLARE OTHER BUNDLE ? ETC
    179:          */
    180:
    181:         return $bundles;
    182:
    183:     }
    184:
    185:     /**
    186:      * Loads the container configuration
    187:      *
    188:      * part of Symfony\Component\HttpKernel\KernelInterface
    189:      *
    190:      * @param LoaderInterface $loader A LoaderInterface instance
    191:      *
    192:      * @api
    193:      */
    194:     public function registerContainerConfiguration(LoaderInterface $loader)
    195:     {
    196:         //Nothing is load here but it's possible to load container configuration here.
    197:         //exemple in sf2 : $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    198:     }
    199:
    200: }
    201: