sauvegarde 10/10/2012
Début d'implémentation du controlleur / matcher pour le routing Voir http://dev.thelia.net/index.php?title=Routing
This commit is contained in:
11
core/lib/Thelia/Controller/TheliaController.php
Normal file
11
core/lib/Thelia/Controller/TheliaController.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Controller;
|
||||
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||
|
||||
|
||||
class TheliaController extends ControllerResolver {
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -10,46 +10,66 @@ namespace Thelia\Core;
|
||||
*/
|
||||
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
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.
|
||||
*
|
||||
* The cached version of the service container is used when fresh, otherwise the
|
||||
* container is built.
|
||||
*/
|
||||
protected function initializeContainer(){
|
||||
if(false === $container = require THELIA_ROOT . '/local/config/container.php'){
|
||||
/**
|
||||
* @todo redirect to installation process
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
$this->container = $this->buildContainer();
|
||||
$this->container->set('kernel', $this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
|
||||
* Builds the service container.
|
||||
*
|
||||
* @return ContainerBuilder The compiled service container
|
||||
*/
|
||||
public function getContainer(){
|
||||
return $this->container;
|
||||
protected function buildContainer(){
|
||||
|
||||
$container = $this->getContainerBuilder();
|
||||
|
||||
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() {
|
||||
|
||||
$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
|
||||
*
|
||||
@@ -60,7 +80,8 @@ class Thelia extends Kernel {
|
||||
* @api
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
28
core/lib/Thelia/Core/TheliaBundle.php
Normal file
28
core/lib/Thelia/Core/TheliaBundle.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Scope;
|
||||
|
||||
|
||||
class TheliaBundle extends Bundle {
|
||||
public function build(ContainerBuilder $container) {
|
||||
|
||||
$container->addScope( new Scope('request'));
|
||||
|
||||
$container->register('request', 'Symfony\Component\HttpFoundation\Request');
|
||||
$container->register('dispatcher','Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher')
|
||||
->addArgument(new Reference('service_container'));
|
||||
$container->register('resolver', 'Thelia\Controller\TheliaController');
|
||||
|
||||
$container->register('http_kernel','Symfony\Component\HttpKernel\HttpKernel')
|
||||
->addArgument(new Reference('dispatcher'))
|
||||
->addArgument(new Reference('resolver'));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
98
core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php
Normal file
98
core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Routing\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
|
||||
class TheliaMatcherCollection implements RequestMatcherInterface, UrlMatcherInterface {
|
||||
|
||||
protected $context;
|
||||
protected $matchers = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Check if this constructor id needed (is RequestContext needed ? )
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
|
||||
|
||||
$this->context = new RequestContext();
|
||||
}
|
||||
|
||||
public function add($matcher){
|
||||
if(!$matcher instanceof RequestMatcherInterface && !$matcher instanceof UrlMatcherInterface){
|
||||
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
|
||||
}
|
||||
|
||||
$this->matchers[] = $matcher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries to match a request with a set of routes.
|
||||
*
|
||||
* If the matcher can not find information, it must throw one of the exceptions documented
|
||||
* below.
|
||||
*
|
||||
* @param Request $request The request to match
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @throws ResourceNotFoundException If no matching resource could be found
|
||||
* @throws MethodNotAllowedException If a matching resource was found but the request method is not allowed
|
||||
*/
|
||||
public function matchRequest(Request $request){
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to match a URL path with a set of routes.
|
||||
*
|
||||
* If the matcher can not find information, it must throw one of the exceptions documented
|
||||
* below.
|
||||
*
|
||||
* @param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded)
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @throws ResourceNotFoundException If the resource could not be found
|
||||
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function match($pathinfo){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request context.
|
||||
*
|
||||
* @param RequestContext $context The context
|
||||
*
|
||||
*/
|
||||
public function setContext(RequestContext $context){
|
||||
$this->context = $context;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the request context.
|
||||
*
|
||||
* @return RequestContext The context
|
||||
*
|
||||
*/
|
||||
public function getContext(){
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -22,11 +22,11 @@ if( false === in_array($request->getClientIp(), $trustIp)){
|
||||
|
||||
$thelia = new Thelia('dev', true);
|
||||
|
||||
var_dump($thelia->getContainer());
|
||||
//var_dump($thelia->getContainer());
|
||||
|
||||
//$response = $thelia->handle($request)->prepare($request)->send();
|
||||
//
|
||||
//$thelia->terminate($request, $reponse);
|
||||
$response = $thelia->handle($request)->prepare($request)->send();
|
||||
|
||||
$thelia->terminate($request, $reponse);
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user