merged branch endroid/master (PR #8488)
This PR was squashed before being merged into the master branch (closes #8488).
Discussion
----------
Add container aware trait
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR | will create one if merged
This trait can be used inside a class to make it container aware. As it is not always possible to extend the abstract ContainerAware class, the code for creating a container aware class is usually copied over and over (most of the time unchanged), resulting in a lot of redundant code in your project. As my projects are PHP 5.4 based nowadays, I would like to be able to use a trait in these scenarios to improve my workflow.
Commits
-------
4c9e606
Add container aware trait
This commit is contained in:
commit
6132b40b06
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
2.4.0
|
||||
-----
|
||||
|
||||
* added ContainerAwareTrait to add default container aware behavior to a class
|
||||
|
||||
2.2.0
|
||||
-----
|
||||
|
||||
|
35
src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
Executable file
35
src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection;
|
||||
|
||||
/**
|
||||
* ContainerAware trait.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
trait ContainerAwareTrait
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Sets the Container associated with this Controller.
|
||||
*
|
||||
* @param ContainerInterface $container A ContainerInterface instance
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user