mise en place du templatind dans Thelia
This commit is contained in:
@@ -2,15 +2,31 @@
|
||||
|
||||
namespace Thelia\Controller;
|
||||
|
||||
use Thelia\Controller\NullController;
|
||||
use Thelia\Controller\NullControllerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Manuel Raynaud <mraynadu@openstudio.fr>
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace Thelia\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
|
||||
abstract class NullController {
|
||||
interface NullControllerInterface {
|
||||
|
||||
/**
|
||||
* Nothing to do
|
||||
*/
|
||||
public function noAction(){
|
||||
|
||||
}
|
||||
public function noAction(Request $request);
|
||||
|
||||
}
|
||||
?>
|
||||
53
core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php
Normal file
53
core/lib/Thelia/Core/EventSubscriber/ViewSubscriber.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core\EventSubscriber;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
|
||||
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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
36
core/lib/Thelia/Core/Template/Parser.php
Normal file
36
core/lib/Thelia/Core/Template/Parser.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core\Template;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
|
||||
class Parser implements ParserInterface {
|
||||
|
||||
protected $container;
|
||||
|
||||
public function __construct(ContainerBuilder $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getContent() {
|
||||
return new Response('toto');
|
||||
}
|
||||
|
||||
public function setContent($content) {
|
||||
|
||||
}
|
||||
|
||||
public function getStatus() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
public function setStatus($status) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
27
core/lib/Thelia/Core/Template/ParserInterface.php
Normal file
27
core/lib/Thelia/Core/Template/ParserInterface.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core\Template;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
interface ParserInterface {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getContent();
|
||||
|
||||
public function setContent($content);
|
||||
|
||||
public function getStatus();
|
||||
|
||||
public function setStatus($status);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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')));
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user