diff --git a/core/lib/Thelia/Controller/DefaultController.php b/core/lib/Thelia/Controller/DefaultController.php index c6f5645cb..8d94aca19 100644 --- a/core/lib/Thelia/Controller/DefaultController.php +++ b/core/lib/Thelia/Controller/DefaultController.php @@ -2,15 +2,31 @@ namespace Thelia\Controller; -use Thelia\Controller\NullController; +use Thelia\Controller\NullControllerInterface; +use Symfony\Component\HttpFoundation\Request; /** * * @author Manuel Raynaud */ -class DefaultController extends NullController{ - - +class DefaultController implements NullControllerInterface{ + /** + * + * set the default value for thelia + * + * In this case there is no action so we have to verify if some needed params are not missing + * + * @param \Symfony\Component\HttpFoundation\Request $request + */ + public function noAction(Request $request) { + if($request->query->has('view') === false){ + $fond = "index"; + if($request->request->has('view')){ + $fond = $request->request->get('view'); + } + $request->query->set('view', $fond); + } + } } ?> diff --git a/core/lib/Thelia/Controller/NullController.php b/core/lib/Thelia/Controller/NullControllerInterface.php similarity index 53% rename from core/lib/Thelia/Controller/NullController.php rename to core/lib/Thelia/Controller/NullControllerInterface.php index bd2a51e90..bce28c38e 100644 --- a/core/lib/Thelia/Controller/NullController.php +++ b/core/lib/Thelia/Controller/NullControllerInterface.php @@ -2,19 +2,19 @@ namespace Thelia\Controller; +use Symfony\Component\HttpFoundation\Request; + /** * * @author Manuel Raynaud */ -abstract class NullController { +interface NullControllerInterface { /** * Nothing to do */ - public function noAction(){ - - } + public function noAction(Request $request); } ?> diff --git a/core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php new file mode 100644 index 000000000..e1aec22fc --- /dev/null +++ b/core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php @@ -0,0 +1,53 @@ + + */ + +class ViewSubscriber implements EventSubscriberInterface{ + + private $parser; + + public function __construct(ParserInterface $parser) { + $this->parser = $parser; + } + + public function onKernelView(GetResponseForControllerResultEvent $event){ + $content = $this->parser->getContent(); + + if($content instanceof Response){ + $event->setResponse($content); + } + else{ + $event->setResponse(new Response($this->parser->getContent(), $this->parser->getStatus())); + } + + + //$event->setResponse(($content = $this->parser->getContent() instanceof Response) ?: new Response($this->parser->getContent(), $this->parser->getStatus()) ); + } + + + /** + * + * @return array The event names to listen to + */ + public static function getSubscribedEvents(){ + return array( + KernelEvents::VIEW => array(array('onKernelView', 32)), + ); + } +} +?> diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php new file mode 100644 index 000000000..039d5b90a --- /dev/null +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -0,0 +1,36 @@ +container = $container; + } + + public function getContent() { + return new Response('toto'); + } + + public function setContent($content) { + + } + + public function getStatus() { + return 200; + } + + public function setStatus($status) { + + } + +} +?> diff --git a/core/lib/Thelia/Core/Template/ParserInterface.php b/core/lib/Thelia/Core/Template/ParserInterface.php new file mode 100644 index 000000000..a3e234626 --- /dev/null +++ b/core/lib/Thelia/Core/Template/ParserInterface.php @@ -0,0 +1,27 @@ + + * + */ + +interface ParserInterface { + + /** + * + */ + public function getContent(); + + public function setContent($content); + + public function getStatus(); + + public function setStatus($status); +} + +?> \ No newline at end of file diff --git a/core/lib/Thelia/Core/TheliaBundle.php b/core/lib/Thelia/Core/TheliaBundle.php index e3d04866a..f19796bbb 100644 --- a/core/lib/Thelia/Core/TheliaBundle.php +++ b/core/lib/Thelia/Core/TheliaBundle.php @@ -31,7 +31,8 @@ class TheliaBundle extends Bundle { $container->addScope( new Scope('request')); - $container->register('request', 'Symfony\Component\HttpFoundation\Request'); + $container->register('request', 'Symfony\Component\HttpFoundation\Request') + ->setSynthetic(true); $container->register('controller.default','Thelia\Controller\DefaultController'); $container->register('matcher.default','Thelia\Routing\Matcher\DefaultMatcher') @@ -45,7 +46,8 @@ class TheliaBundle extends Bundle { $container->register('resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver'); - //$container->register('parser','Thelia\Core\TheliaTemplate'); + $container->register('parser','Thelia\Core\Template\Parser') + ->addArgument(new Reference('service_container')); /** * RouterListener implements EventSubscriberInterface and listen for kernel.request event */ @@ -53,9 +55,10 @@ class TheliaBundle extends Bundle { ->setArguments(array(new Reference('matcher'))); /** - * @TODO think how to use kernel.view event for templating. In most of case controller doesn't return a Response instance + * @TODO think how to use kernel.view event for templating. In most of case (in Thelia) controller doesn't return a Response instance */ - //$container->register('listener.view') + $container->register('listener.view','Thelia\Core\EventSubscriber\ViewSubscriber') + ->addArgument(new Reference('parser')); $container->register('http_kernel','Symfony\Component\HttpKernel\HttpKernel') ->addArgument(new Reference('dispatcher')) @@ -63,7 +66,8 @@ class TheliaBundle extends Bundle { $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.router'))) + ->addMethodCall('addSubscriber', array(new Reference('listener.view'))); /** diff --git a/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php b/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php index f6669209d..8e8bff580 100644 --- a/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php +++ b/core/lib/Thelia/Routing/Matcher/DefaultMatcher.php @@ -4,7 +4,7 @@ namespace Thelia\Routing\Matcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Matcher\RequestMatcherInterface; -use Thelia\Controller\NullController; +use Thelia\Controller\NullControllerInterface; /** * Default matcher when no action is needed and there is no result for urlmatcher @@ -15,7 +15,7 @@ class DefaultMatcher implements RequestMatcherInterface{ protected $controller; - public function __construct(NullController $controller) { + public function __construct(NullControllerInterface $controller) { $this->controller = $controller; } diff --git a/index_dev.php b/index_dev.php index aae114bcd..0f7bc8f16 100644 --- a/index_dev.php +++ b/index_dev.php @@ -22,11 +22,9 @@ if( false === in_array($request->getClientIp(), $trustIp)){ $thelia = new Thelia('dev', true); -//var_dump($thelia->getContainer()); - $response = $thelia->handle($request)->prepare($request)->send(); -$thelia->terminate($request, $reponse); +$thelia->terminate($request, $response); ?>