Created
October 1, 2010 11:34
-
-
Save avalanche123/606086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Symfony\Component\DependencyInjection; | |
/* | |
* This file is part of the Symfony framework. | |
* | |
* (c) Fabien Potencier <[email protected]> | |
* | |
* This source file is subject to the MIT license that is bundled | |
* with this source code in the file LICENSE. | |
*/ | |
/** | |
* ContainerAwareInterface should be implemented by classes that depends on a Container. | |
* | |
* @author Fabien Potencier <[email protected]> | |
*/ | |
interface ContainerAwareInterface | |
{ | |
/** | |
* Sets the Container. | |
* | |
* @param ContainerInterface $container A ContainerInterface instance | |
*/ | |
function setContainer(ContainerInterface $container = null); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<container xmlns="http://www.symfony-project.org/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd"> | |
<services> | |
<service id="index_controller" class="Company\ApplicationBundle\Controller\SimpleController" /> | |
</services> | |
</container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<container xmlns="http://www.symfony-project.org/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd"> | |
<interfaces> | |
<interface class="Symfony\Component\DependencyInjection\ContainerAwareInterface"> | |
<call method="setContainer"> | |
<argument type="service" id="container" /> | |
</call> | |
</interface> | |
</interfaces> | |
</container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Company\ApplicationBundle\Controller; | |
use Symfony\Component\DependencyInjection\Container; | |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
class SimpleController implements ContainerAwareInterface | |
{ | |
/** | |
* @var Symfony\Component\DependencyInjection\Container | |
*/ | |
private $container; | |
/** | |
* @param Symfony\Component\DependencyInjection\Container $container | |
*/ | |
public function setContainer(Container $container) | |
{ | |
$this->container = $container; | |
} | |
//... | |
} |
yes, you can read more here http://avalanche123.com/post/1221451286/interface-injection-and-symfony2-dic
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is kinda awesome if i understand it correctly. So if a class implementes a specific interface (in this case ContainerAwareInterface) the service will call setContainer for that class?