clean code with php-cs-fixer
This commit is contained in:
@@ -7,24 +7,23 @@ use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class RequestListener implements EventSubscriberInterface {
|
||||
|
||||
class RequestListener implements EventSubscriberInterface
|
||||
{
|
||||
protected $container;
|
||||
|
||||
public function __construct(ContainerInterface $container) {
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function onKernelRequest(GetResponseEvent $event){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getSubscribedEvents(){
|
||||
|
||||
public function onKernelRequest(GetResponseEvent $event)
|
||||
{
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::REQUEST => array('onKernelRequest', 30)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -5,63 +5,61 @@ namespace Thelia\Core\EventListener;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* ViewSubscriber Main class subscribing to view http response.
|
||||
*
|
||||
*
|
||||
* @TODO Look if it's possible to block this definition in dependency-injection
|
||||
*
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
|
||||
class ViewListener implements EventSubscriberInterface{
|
||||
|
||||
class ViewListener implements EventSubscriberInterface
|
||||
{
|
||||
private $parser;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param \Thelia\Core\Template\ParserInterface $parser
|
||||
*/
|
||||
public function __construct(ParserInterface $parser) {
|
||||
public function __construct(ParserInterface $parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* 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){
|
||||
|
||||
public function onKernelView(GetResponseForControllerResultEvent $event)
|
||||
{
|
||||
$content = $this->parser->getContent();
|
||||
|
||||
if($content instanceof Response){
|
||||
|
||||
if ($content instanceof Response) {
|
||||
$event->setResponse($content);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$event->setResponse(new Response($content, $this->parser->getStatus() ?: 200));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Register the method to execute in this class for a specific event (here the kernel.view event)
|
||||
*
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*/
|
||||
public static function getSubscribedEvents(){
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::VIEW => array('onKernelView'),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -2,82 +2,85 @@
|
||||
|
||||
namespace Thelia\Core\Template;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Master class of Thelia's parser. The loop mechnism depends of this parser
|
||||
*
|
||||
*
|
||||
* From this class all the parser is lunch
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
|
||||
|
||||
class Parser implements ParserInterface {
|
||||
|
||||
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 = 200;
|
||||
|
||||
public function __construct(ContainerBuilder $container) {
|
||||
|
||||
public function __construct(ContainerBuilder $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function getContent() {
|
||||
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) {
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return type the status of the response
|
||||
*/
|
||||
public function getStatus() {
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* status HTTP of the response
|
||||
*
|
||||
*
|
||||
* @param int $status
|
||||
*/
|
||||
public function setStatus($status) {
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function loadParser(){
|
||||
|
||||
|
||||
public function loadParser()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -3,25 +3,23 @@
|
||||
namespace Thelia\Core\Template;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
interface ParserInterface {
|
||||
|
||||
interface ParserInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function getContent();
|
||||
|
||||
|
||||
public function setContent($content);
|
||||
|
||||
|
||||
public function getStatus();
|
||||
|
||||
|
||||
public function setStatus($status);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -4,90 +4,88 @@ namespace Thelia\Core;
|
||||
|
||||
/**
|
||||
* Root class of Thelia
|
||||
*
|
||||
*
|
||||
* It extends Symfony\Component\HttpKernel\Kernel for changing some fonctionnality
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
|
||||
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Thelia\Core\TheliaBundle;
|
||||
|
||||
class Thelia extends Kernel {
|
||||
class Thelia extends Kernel
|
||||
{
|
||||
/**
|
||||
* Initializes the service container.
|
||||
*
|
||||
*
|
||||
* @TODO cache container initialization
|
||||
*
|
||||
* 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the service container.
|
||||
*
|
||||
* @return ContainerBuilder The compiled service container
|
||||
*/
|
||||
protected function buildContainer(){
|
||||
|
||||
protected function buildContainer()
|
||||
{
|
||||
$container = $this->getContainerBuilder();
|
||||
|
||||
foreach($this->bundles as $bundle){
|
||||
|
||||
foreach ($this->bundles as $bundle) {
|
||||
$bundle->build($container);
|
||||
}
|
||||
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* return available bundle
|
||||
*
|
||||
*
|
||||
* Part of Symfony\Component\HttpKernel\KernelInterface
|
||||
*
|
||||
*
|
||||
* @return array An array of bundle instances.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function registerBundles() {
|
||||
|
||||
public function registerBundles()
|
||||
{
|
||||
$bundles = array(
|
||||
/* TheliaBundle contain all the dependency injection description */
|
||||
new TheliaBundle()
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* OTHER CORE BUNDLE CAN BE DECLARE HERE AND INITIALIZE WITH SPECIFIC CONFIGURATION
|
||||
*
|
||||
*
|
||||
* HOW TO DECLARE OTHER BUNDLE ? ETC
|
||||
*/
|
||||
|
||||
|
||||
return $bundles;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the container configuration
|
||||
*
|
||||
*
|
||||
* part of Symfony\Component\HttpKernel\KernelInterface
|
||||
*
|
||||
* @param LoaderInterface $loader A LoaderInterface instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function registerContainerConfiguration(LoaderInterface $loader){
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
//Nothing is load here but it's possible to load container configuration here.
|
||||
//exemple in sf2 : $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -10,42 +10,42 @@ use Symfony\Component\DependencyInjection\Scope;
|
||||
/**
|
||||
* First Bundle use in Thelia
|
||||
* It initialize dependency injection container.
|
||||
*
|
||||
*
|
||||
* @TODO load configuration from thelia plugin
|
||||
* @TODO register database configuration.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
|
||||
class TheliaBundle extends Bundle {
|
||||
|
||||
class TheliaBundle extends Bundle
|
||||
{
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Construct the depency injection builder
|
||||
*
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
|
||||
public function build(ContainerBuilder $container) {
|
||||
|
||||
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
$container->addScope( new Scope('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')
|
||||
->addArgument(new Reference('controller.default'));
|
||||
|
||||
|
||||
$container->register('matcher','Thelia\Routing\Matcher\theliaMatcherCollection')
|
||||
->addMethodCall('add', array(new Reference('matcher.default'), -255))
|
||||
//->addMethodCall('add','a matcher class (instance or class name)
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
$container->register('resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver');
|
||||
|
||||
|
||||
$container->register('parser','Thelia\Core\Template\Parser')
|
||||
->addArgument(new Reference('service_container'))
|
||||
;
|
||||
@@ -55,13 +55,13 @@ class TheliaBundle extends Bundle {
|
||||
$container->register('listener.router', 'Symfony\Component\HttpKernel\EventListener\RouterListener')
|
||||
->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('');
|
||||
* ;
|
||||
@@ -70,26 +70,23 @@ class TheliaBundle extends Bundle {
|
||||
$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('dispatcher'))
|
||||
->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('thelia.listener.view')))
|
||||
;
|
||||
|
||||
|
||||
// DEFINE DEFAULT PARAMETER LIKE
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @TODO learn about container compilation
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user