diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php index 1ed7a7116..16fa57fb6 100644 --- a/core/lib/Thelia/Core/Template/Parser.php +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -4,7 +4,7 @@ namespace Thelia\Core\Template; use Symfony\Component\HttpFoundation\Response; use Thelia\Core\Template\ParserInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @@ -25,12 +25,22 @@ class Parser implements ParserInterface const ALLOW_DEBUG = true; const USE_CACHE = true; + /** + * + * @var Symfony\Component\DependencyInjection\ContainerInterface + */ protected $container; protected $content; protected $status = 200; - public function __construct(ContainerBuilder $container) + /** + * + * @param type $container + * + * public function __construct(ContainerBuilder $container) + */ + public function __construct(ContainerInterface $container) { $this->container = $container; } @@ -43,7 +53,10 @@ class Parser implements ParserInterface public function getContent() { $this->loadParser(); - $this->content = "toto"; + + $request = $this->container->get('request'); + + $this->content = $request->get("test"); return $this->content; } diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 03c517b6e..024421386 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -25,11 +25,46 @@ class Thelia extends Kernel * The cached version of the service container is used when fresh, otherwise the * container is built. */ - protected function initializeContainer() +// protected function initializeContainer() +// { +// $this->container = $this->buildContainer(); +// $this->container->set('kernel', $this); +// +// } + + /** + * Gets the cache directory. + * + * @return string The cache directory + * + * @api + */ + public function getCacheDir() { - $this->container = $this->buildContainer(); - $this->container->set('kernel', $this); - + if(defined('THELIA_ROOT')) + { + return THELIA_ROOT.'cache/'.$this->environment; + } else { + return parent::getCacheDir(); + } + + } + + /** + * Gets the log directory. + * + * @return string The log directory + * + * @api + */ + public function getLogDir() + { + if(defined('THELIA_ROOT')) + { + return THELIA_ROOT.'log/'; + } else { + return parent::getLogDir(); + } } /** @@ -37,16 +72,16 @@ class Thelia extends Kernel * * @return ContainerBuilder The compiled service container */ - protected function buildContainer() - { - $container = $this->getContainerBuilder(); - - foreach ($this->bundles as $bundle) { - $bundle->build($container); - } - - return $container; - } +// protected function buildContainer() +// { +// $container = $this->getContainerBuilder(); +// +// foreach ($this->bundles as $bundle) { +// $bundle->build($container); +// } +// +// return $container; +// } /** * return available bundle diff --git a/core/lib/Thelia/Core/TheliaBundle.php b/core/lib/Thelia/Core/TheliaBundle.php index 135e43011..c9a59bf9c 100644 --- a/core/lib/Thelia/Core/TheliaBundle.php +++ b/core/lib/Thelia/Core/TheliaBundle.php @@ -71,16 +71,19 @@ class TheliaBundle extends Bundle ->addArgument(new Reference('parser')) ; - $container->register('http_kernel','Symfony\Component\HttpKernel\HttpKernel') - ->addArgument(new Reference('dispatcher')) - ->addArgument(new Reference('resolver')) - ; + - $container->register('dispatcher','Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher') + $container->register('dispatcher','Symfony\Component\EventDispatcher\EventDispatcher') ->addArgument(new Reference('service_container')) ->addMethodCall('addSubscriber', array(new Reference('listener.router'))) ->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view'))) ; + + $container->register('http_kernel','Thelia\Core\TheliaHttpKernel') + ->addArgument(new Reference('dispatcher')) + ->addArgument(new Reference('service_container')) + ->addArgument(new Reference('resolver')) + ; // DEFINE DEFAULT PARAMETER LIKE diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php new file mode 100644 index 000000000..8f5b7d446 --- /dev/null +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -0,0 +1,58 @@ +container = $container; + } + + + /** + * Handles a Request to convert it to a Response. + * + * When $catch is true, the implementation must catch all exceptions + * and do its best to convert them to a Response instance. + * + * @param Request $request A Request instance + * @param integer $type The type of the request + * (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST) + * @param Boolean $catch Whether to catch exceptions or not + * + * @return Response A Response instance + * + * @throws \Exception When an Exception occurs during processing + * + * @api + */ + public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) + { + //$request->headers->set('X-Php-Ob-Level', ob_get_level()); + + $this->container->enterScope('request'); + $this->container->set('request', $request, 'request'); + + try { + $response = parent::handle($request, $type, $catch); + } catch (\Exception $e) { + $this->container->leaveScope('request'); + + throw $e; + } + + $this->container->leaveScope('request'); + + return $response; + } +} \ No newline at end of file