From 69ac78c7905f242241e5fe3c4a8bd85d73e4d398 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 10 Oct 2012 18:07:08 +0200 Subject: [PATCH] =?UTF-8?q?sauvegarde=2010/10/2012=20D=C3=A9but=20d'impl?= =?UTF-8?q?=C3=A9mentation=20du=20controlleur=20/=20matcher=20pour=20le=20?= =?UTF-8?q?routing=20Voir=20http://dev.thelia.net/index.php=3Ftitle=3DRout?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Thelia/Controller/TheliaController.php | 11 +++ core/lib/Thelia/Core/Thelia.php | 63 ++++++++---- core/lib/Thelia/Core/TheliaBundle.php | 28 ++++++ .../Matcher/TheliaMatcherCollection.php | 98 +++++++++++++++++++ index_dev.php | 8 +- 5 files changed, 183 insertions(+), 25 deletions(-) create mode 100644 core/lib/Thelia/Controller/TheliaController.php create mode 100644 core/lib/Thelia/Core/TheliaBundle.php create mode 100644 core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php diff --git a/core/lib/Thelia/Controller/TheliaController.php b/core/lib/Thelia/Controller/TheliaController.php new file mode 100644 index 000000000..fa4e1de5b --- /dev/null +++ b/core/lib/Thelia/Controller/TheliaController.php @@ -0,0 +1,11 @@ + diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 5cd612fd3..343b375e6 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -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'); } diff --git a/core/lib/Thelia/Core/TheliaBundle.php b/core/lib/Thelia/Core/TheliaBundle.php new file mode 100644 index 000000000..3faf7dc84 --- /dev/null +++ b/core/lib/Thelia/Core/TheliaBundle.php @@ -0,0 +1,28 @@ +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')); + + + } +} +?> diff --git a/core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php b/core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php new file mode 100644 index 000000000..023a09d97 --- /dev/null +++ b/core/lib/Thelia/Routing/Matcher/TheliaMatcherCollection.php @@ -0,0 +1,98 @@ +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; + } + + + + +} +?> diff --git a/index_dev.php b/index_dev.php index 5ea3e475e..aae114bcd 100644 --- a/index_dev.php +++ b/index_dev.php @@ -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); ?>