diff --git a/core/lib/Thelia/Controller/DefaultController.php b/core/lib/Thelia/Controller/DefaultController.php index 8d94aca19..9da3e8c2c 100644 --- a/core/lib/Thelia/Controller/DefaultController.php +++ b/core/lib/Thelia/Controller/DefaultController.php @@ -6,6 +6,8 @@ use Thelia\Controller\NullControllerInterface; use Symfony\Component\HttpFoundation\Request; /** + * + * Must be the last controller call. It fixes default values * * @author Manuel Raynaud */ diff --git a/core/lib/Thelia/Core/EventListener/RequestListener.php b/core/lib/Thelia/Core/EventListener/RequestListener.php new file mode 100644 index 000000000..490645b2e --- /dev/null +++ b/core/lib/Thelia/Core/EventListener/RequestListener.php @@ -0,0 +1,30 @@ +container = $container; + } + + public function onKernelRequest(GetResponseEvent $event){ + + } + + + public static function getSubscribedEvents(){ + return array( + KernelEvents::REQUEST => array('onKernelRequest', 30) + ); + } +} + +?> diff --git a/core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Thelia/Core/EventListener/ViewListener.php similarity index 77% rename from core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php rename to core/lib/Thelia/Core/EventListener/ViewListener.php index 323e15bd6..33e36e9be 100644 --- a/core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -1,6 +1,6 @@ */ -class ViewSubscriber implements EventSubscriberInterface{ +class ViewListener implements EventSubscriberInterface{ private $parser; @@ -31,18 +33,21 @@ class ViewSubscriber implements EventSubscriberInterface{ /** * + * Launch the parser defined on the constructor and get the result. * + * The result is transform id needed into a Response object * * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event */ public function onKernelView(GetResponseForControllerResultEvent $event){ + $content = $this->parser->getContent(); if($content instanceof Response){ $event->setResponse($content); } else{ - $event->setResponse(new Response($content, $this->parser->getStatus())); + $event->setResponse(new Response($content, $this->parser->getStatus() ?: 200)); } } diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php index 1627da3f9..bd49ba5ec 100644 --- a/core/lib/Thelia/Core/Template/Parser.php +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Thelia\Core\Template\ParserInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\EventDispatcher\EventDispatcher; /** * @@ -20,11 +21,17 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; class Parser implements ParserInterface { + const PREFIXE = 'prx'; + + const SHOW_TIME = true; + const ALLOW_DEBUG = true; + const USE_CACHE = true; + protected $container; protected $content; - protected $status; - + protected $status = 200; + public function __construct(ContainerBuilder $container) { $this->container = $container; } @@ -36,18 +43,34 @@ class Parser implements ParserInterface { */ public function getContent() { $this->loadParser(); - + $this->content = "toto"; return $this->content; } + /** + * + * set $content with the body of the response or the Response object directly + * + * @param string|Symfony\Component\HttpFoundation\Response $content + */ public function setContent($content) { $this->content = $content; } + /** + * + * @return type the status of the response + */ public function getStatus() { - return 200; + return $this->status; } + /** + * + * status HTTP of the response + * + * @param int $status + */ public function setStatus($status) { $this->status = $status; } diff --git a/core/lib/Thelia/Core/TheliaBundle.php b/core/lib/Thelia/Core/TheliaBundle.php index 107e72f50..0568521e9 100644 --- a/core/lib/Thelia/Core/TheliaBundle.php +++ b/core/lib/Thelia/Core/TheliaBundle.php @@ -47,24 +47,43 @@ class TheliaBundle extends Bundle { $container->register('resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver'); $container->register('parser','Thelia\Core\Template\Parser') - ->addArgument(new Reference('service_container')); + ->addArgument(new Reference('service_container')) + ; /** * RouterListener implements EventSubscriberInterface and listen for kernel.request event */ $container->register('listener.router', 'Symfony\Component\HttpKernel\EventListener\RouterListener') - ->setArguments(array(new Reference('matcher'))); + ->setArguments(array(new Reference('matcher'))) + ; + + /** + * @TODO add an other listener on kernel.request for checking some params Like check if User is log in, set the language and other. + * + * $container->register() + * + * + * $container->register('listener.request', 'Thelia\Core\EventListener\RequestListener') + * ->addArgument(new Reference(''); + * ; + */ - $container->register('listener.view','Thelia\Core\EventSubscriber\ViewSubscriber') - ->addArgument(new Reference('parser')); + $container->register('thelia.listener.view','Thelia\Core\EventListener\ViewListener') + ->addArgument(new Reference('parser')) + ; $container->register('http_kernel','Symfony\Component\HttpKernel\HttpKernel') ->addArgument(new Reference('dispatcher')) - ->addArgument(new Reference('resolver')); + ->addArgument(new Reference('resolver')) + ; $container->register('dispatcher','Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher') ->addArgument(new Reference('service_container')) ->addMethodCall('addSubscriber', array(new Reference('listener.router'))) - ->addMethodCall('addSubscriber', array(new Reference('listener.view'))); + ->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view'))) + ; + + // DEFINE DEFAULT PARAMETER LIKE + /** diff --git a/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php b/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php index 8e8bff580..2962cbab4 100644 --- a/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php +++ b/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php @@ -33,4 +33,4 @@ class DefaultMatcher implements RequestMatcherInterface{ } -?> +?> \ No newline at end of file diff --git a/core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php b/core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php index 33e40a9e6..546b03a03 100644 --- a/core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php +++ b/core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php @@ -150,10 +150,6 @@ class TheliaMatcherCollection implements RequestMatcherInterface, RequestContext */ public function getContext(){ return $this->context; - } - - - - + } } -?> +?> \ No newline at end of file