added ContainerAwareInterface
This commit is contained in:
parent
eeb0742826
commit
83a64df542
@ -3,6 +3,7 @@
|
|||||||
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* 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 <fabien.potencier@symfony-project.com>
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
*/
|
*/
|
||||||
class Controller extends BaseController implements \ArrayAccess
|
class Controller extends ContainerAware implements \ArrayAccess
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a Response instance.
|
* Creates a Response instance.
|
||||||
|
@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\EventDispatcher\Event;
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameConverter;
|
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.
|
* This file is part of the Symfony framework.
|
||||||
@ -68,7 +68,7 @@ class ControllerResolver extends BaseControllerResolver
|
|||||||
}
|
}
|
||||||
|
|
||||||
$controller = new $class();
|
$controller = new $class();
|
||||||
if ($controller instanceof ControllerInterface) {
|
if ($controller instanceof ContainerAwareInterface) {
|
||||||
$controller->setContainer($this->container);
|
$controller->setContainer($this->container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
namespace Symfony\Component\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -14,11 +12,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FrameworkBundle Controller gives you convenient access to all commonly needed services.
|
* A simple implementation of ContainerAwareInterface.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
*/
|
*/
|
||||||
class BaseController implements ControllerInterface
|
class ContainerAware implements ContainerAwareInterface
|
||||||
{
|
{
|
||||||
protected $container;
|
protected $container;
|
||||||
|
|
||||||
@ -27,7 +25,7 @@ class BaseController implements ControllerInterface
|
|||||||
*
|
*
|
||||||
* @param ContainerInterface $container A ContainerInterface instance
|
* @param ContainerInterface $container A ContainerInterface instance
|
||||||
*/
|
*/
|
||||||
public function setContainer(ContainerInterface $container)
|
public function setContainer(ContainerInterface $container = null)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
namespace Symfony\Component\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -14,16 +12,16 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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>
|
* @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
|
* @param ContainerInterface $container A ContainerInterface instance
|
||||||
*/
|
*/
|
||||||
function setContainer(ContainerInterface $container);
|
function setContainer(ContainerInterface $container = null);
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Framework\Bundle;
|
namespace Symfony\Framework\Bundle;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
@ -22,24 +22,13 @@ use Symfony\Component\Finder\Finder;
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
* @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 $name;
|
||||||
protected $namespacePrefix;
|
protected $namespacePrefix;
|
||||||
protected $path;
|
protected $path;
|
||||||
protected $reflection;
|
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.
|
* Boots the Bundle.
|
||||||
*/
|
*/
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Framework\Bundle;
|
namespace Symfony\Framework\Bundle;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
*
|
*
|
||||||
@ -29,11 +27,4 @@ interface BundleInterface
|
|||||||
* Shutdowns the Bundle.
|
* Shutdowns the Bundle.
|
||||||
*/
|
*/
|
||||||
public function shutdown();
|
public function shutdown();
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Container associated with this bundle.
|
|
||||||
*
|
|
||||||
* @param ContainerInterface $container A ContainerInterface instance
|
|
||||||
*/
|
|
||||||
public function setContainer(ContainerInterface $container);
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Symfony\Framework\Bundle;
|
namespace Symfony\Framework\Bundle;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
abstract class Bundle implements BundleInterface {
|
abstract class Bundle extends ContainerAware implements BundleInterface {
|
||||||
protected $container;
|
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $namespacePrefix;
|
protected $namespacePrefix;
|
||||||
protected $path;
|
protected $path;
|
||||||
protected $reflection;
|
protected $reflection;
|
||||||
public function setContainer(ContainerInterface $container = null) {
|
|
||||||
$this->container = $container; }
|
|
||||||
public function boot() { }
|
public function boot() { }
|
||||||
public function shutdown() { }
|
public function shutdown() { }
|
||||||
public function getName() {
|
public function getName() {
|
||||||
@ -58,11 +55,9 @@ abstract class Bundle implements BundleInterface {
|
|||||||
$this->reflection = new \ReflectionObject($this);
|
$this->reflection = new \ReflectionObject($this);
|
||||||
$this->path = dirname($this->reflection->getFilename()); } }
|
$this->path = dirname($this->reflection->getFilename()); } }
|
||||||
namespace Symfony\Framework\Bundle;
|
namespace Symfony\Framework\Bundle;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
interface BundleInterface {
|
interface BundleInterface {
|
||||||
public function boot();
|
public function boot();
|
||||||
public function shutdown();
|
public function shutdown(); }
|
||||||
public function setContainer(ContainerInterface $container); }
|
|
||||||
namespace Symfony\Framework;
|
namespace Symfony\Framework;
|
||||||
use Symfony\Framework\Bundle\Bundle;
|
use Symfony\Framework\Bundle\Bundle;
|
||||||
class KernelBundle extends Bundle {
|
class KernelBundle extends Bundle {
|
||||||
|
Reference in New Issue
Block a user