From 83a64df542d6fcdf8547ed97bdd5a510f36960b8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 28 Aug 2010 09:39:04 +0200 Subject: [PATCH] added ContainerAwareInterface --- .../FrameworkBundle/Controller/Controller.php | 8 ++++++-- .../Controller/ControllerResolver.php | 4 ++-- .../DependencyInjection/ContainerAware.php} | 10 ++++------ .../ContainerAwareInterface.php} | 12 +++++------- src/Symfony/Framework/Bundle/Bundle.php | 15 ++------------- src/Symfony/Framework/Bundle/BundleInterface.php | 9 --------- src/Symfony/Framework/bootstrap.php | 11 +++-------- 7 files changed, 22 insertions(+), 47 deletions(-) rename src/Symfony/{Bundle/FrameworkBundle/Controller/BaseController.php => Component/DependencyInjection/ContainerAware.php} (63%) rename src/Symfony/{Bundle/FrameworkBundle/Controller/ControllerInterface.php => Component/DependencyInjection/ContainerAwareInterface.php} (55%) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php index 69d8eb9749..73fbe8e931 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php @@ -3,6 +3,7 @@ namespace Symfony\Bundle\FrameworkBundle\Controller; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\DependencyInjection\ContainerAware; /* * This file is part of the Symfony framework. @@ -14,11 +15,14 @@ use Symfony\Component\HttpFoundation\Response; */ /** - * FrameworkBundle Controller gives you convenient access to all commonly needed services. + * Controller is a simple implementation of a Controller. + * + * It provides methods to common features needed in controllers + * and an array access to the container services. * * @author Fabien Potencier */ -class Controller extends BaseController implements \ArrayAccess +class Controller extends ContainerAware implements \ArrayAccess { /** * Creates a Response instance. diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php index 2194d7a5c2..d9248910e2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php @@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameConverter; -use Symfony\Bundle\FrameworkBundle\Controller\ControllerInterface; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; /* * This file is part of the Symfony framework. @@ -68,7 +68,7 @@ class ControllerResolver extends BaseControllerResolver } $controller = new $class(); - if ($controller instanceof ControllerInterface) { + if ($controller instanceof ContainerAwareInterface) { $controller->setContainer($this->container); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/BaseController.php b/src/Symfony/Component/DependencyInjection/ContainerAware.php similarity index 63% rename from src/Symfony/Bundle/FrameworkBundle/Controller/BaseController.php rename to src/Symfony/Component/DependencyInjection/ContainerAware.php index c3f1dfd727..62a3ecac70 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/BaseController.php +++ b/src/Symfony/Component/DependencyInjection/ContainerAware.php @@ -1,8 +1,6 @@ */ -class BaseController implements ControllerInterface +class ContainerAware implements ContainerAwareInterface { protected $container; @@ -27,7 +25,7 @@ class BaseController implements ControllerInterface * * @param ContainerInterface $container A ContainerInterface instance */ - public function setContainer(ContainerInterface $container) + public function setContainer(ContainerInterface $container = null) { $this->container = $container; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerInterface.php b/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php similarity index 55% rename from src/Symfony/Bundle/FrameworkBundle/Controller/ControllerInterface.php rename to src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php index 8395a30f67..3247b217e8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerInterface.php +++ b/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php @@ -1,8 +1,6 @@ */ -interface ControllerInterface +interface ContainerAwareInterface { /** - * Sets the Container associated with this Controller. + * Sets the Container. * * @param ContainerInterface $container A ContainerInterface instance */ - function setContainer(ContainerInterface $container); + function setContainer(ContainerInterface $container = null); } diff --git a/src/Symfony/Framework/Bundle/Bundle.php b/src/Symfony/Framework/Bundle/Bundle.php index 2faae00501..2ad56e038a 100644 --- a/src/Symfony/Framework/Bundle/Bundle.php +++ b/src/Symfony/Framework/Bundle/Bundle.php @@ -2,7 +2,7 @@ namespace Symfony\Framework\Bundle; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Console\Application; @@ -22,24 +22,13 @@ use Symfony\Component\Finder\Finder; * * @author Fabien Potencier */ -abstract class Bundle implements BundleInterface +abstract class Bundle extends ContainerAware implements BundleInterface { - protected $container; protected $name; protected $namespacePrefix; protected $path; protected $reflection; - /** - * Sets the Container associated with this bundle. - * - * @param ContainerInterface $container A ContainerInterface instance - */ - public function setContainer(ContainerInterface $container = null) - { - $this->container = $container; - } - /** * Boots the Bundle. */ diff --git a/src/Symfony/Framework/Bundle/BundleInterface.php b/src/Symfony/Framework/Bundle/BundleInterface.php index 72ffa35b6b..133e3f707e 100644 --- a/src/Symfony/Framework/Bundle/BundleInterface.php +++ b/src/Symfony/Framework/Bundle/BundleInterface.php @@ -2,8 +2,6 @@ namespace Symfony\Framework\Bundle; -use Symfony\Component\DependencyInjection\ContainerInterface; - /* * This file is part of the Symfony framework. * @@ -29,11 +27,4 @@ interface BundleInterface * Shutdowns the Bundle. */ public function shutdown(); - - /** - * Sets the Container associated with this bundle. - * - * @param ContainerInterface $container A ContainerInterface instance - */ - public function setContainer(ContainerInterface $container); } diff --git a/src/Symfony/Framework/bootstrap.php b/src/Symfony/Framework/bootstrap.php index e35da87c64..3162b94068 100644 --- a/src/Symfony/Framework/bootstrap.php +++ b/src/Symfony/Framework/bootstrap.php @@ -1,18 +1,15 @@ container = $container; } public function boot() { } public function shutdown() { } public function getName() { @@ -58,11 +55,9 @@ abstract class Bundle implements BundleInterface { $this->reflection = new \ReflectionObject($this); $this->path = dirname($this->reflection->getFilename()); } } namespace Symfony\Framework\Bundle; -use Symfony\Component\DependencyInjection\ContainerInterface; interface BundleInterface { public function boot(); - public function shutdown(); - public function setContainer(ContainerInterface $container); } + public function shutdown(); } namespace Symfony\Framework; use Symfony\Framework\Bundle\Bundle; class KernelBundle extends Bundle {