Skip to content

Commit

Permalink
added ContainerAwareInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 28, 2010
1 parent eeb0742 commit 83a64df
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 47 deletions.
8 changes: 6 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
Expand Up @@ -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.
Expand All @@ -14,11 +15,14 @@
*/

/**
* 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 <fabien.potencier@symfony-project.com>
*/
class Controller extends BaseController implements \ArrayAccess
class Controller extends ContainerAware implements \ArrayAccess
{
/**
* Creates a Response instance.
Expand Down
Expand Up @@ -9,7 +9,7 @@
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.
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function createController($controller)
}

$controller = new $class();
if ($controller instanceof ControllerInterface) {
if ($controller instanceof ContainerAwareInterface) {
$controller->setContainer($this->container);
}

Expand Down
@@ -1,8 +1,6 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Controller;

use Symfony\Component\DependencyInjection\ContainerInterface;
namespace Symfony\Component\DependencyInjection;

/*
* This file is part of the Symfony framework.
Expand All @@ -14,11 +12,11 @@
*/

/**
* FrameworkBundle Controller gives you convenient access to all commonly needed services.
* A simple implementation of ContainerAwareInterface.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class BaseController implements ControllerInterface
class ContainerAware implements ContainerAwareInterface
{
protected $container;

Expand All @@ -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;
}
Expand Down
@@ -1,8 +1,6 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Controller;

use Symfony\Component\DependencyInjection\ContainerInterface;
namespace Symfony\Component\DependencyInjection;

/*
* This file is part of the Symfony framework.
Expand All @@ -14,16 +12,16 @@
*/

/**
* FrameworkBundle ControllerInterface is a simple interface for controllers.
* ContainerAwareInterface should be implemented by classes that depends on a Container.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
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);
}
15 changes: 2 additions & 13 deletions src/Symfony/Framework/Bundle/Bundle.php
Expand Up @@ -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;
Expand All @@ -22,24 +22,13 @@
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
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.
*/
Expand Down
9 changes: 0 additions & 9 deletions src/Symfony/Framework/Bundle/BundleInterface.php
Expand Up @@ -2,8 +2,6 @@

namespace Symfony\Framework\Bundle;

use Symfony\Component\DependencyInjection\ContainerInterface;

/*
* This file is part of the Symfony framework.
*
Expand All @@ -29,11 +27,4 @@ public function boot();
* Shutdowns the Bundle.
*/
public function shutdown();

/**
* Sets the Container associated with this bundle.
*
* @param ContainerInterface $container A ContainerInterface instance
*/
public function setContainer(ContainerInterface $container);
}
11 changes: 3 additions & 8 deletions src/Symfony/Framework/bootstrap.php
@@ -1,18 +1,15 @@
<?php
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;
use Symfony\Component\Finder\Finder;
abstract class Bundle implements BundleInterface {
protected $container;
abstract class Bundle extends ContainerAware implements BundleInterface {
protected $name;
protected $namespacePrefix;
protected $path;
protected $reflection;
public function setContainer(ContainerInterface $container = null) {
$this->container = $container; }
public function boot() { }
public function shutdown() { }
public function getName() {
Expand Down Expand Up @@ -58,11 +55,9 @@ protected function initReflection() {
$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 {
Expand Down

0 comments on commit 83a64df

Please sign in to comment.