Closed
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | no |
Symfony version | 3.4 |
Description
It would be great to define default service definition by trait usage.
This could be a great alternative for some auto-wiring setter like parameters, instead of manual definition.
Concrete case
Here is my KernelRootDirTrait
:
trait KernelRootDirTrait
{
/**
* @var string
*/
private $kernelRootDir;
/**
* @return string
*/
public function getKernelRootDir(): string
{
return $this->kernelRootDir;
}
/**
* @param string $kernelRootDir
*/
public function setKernelRootDir(string $kernelRootDir)
{
$this->kernelRootDir = $kernelRootDir;
}
}
And the service:
class MyService
{
use KernelRootDirTrait;
}
If we could define the default by trait usage like this:
services:
_trait:
AppBundle\PropertyTrait\KernelRootDirTrait:
calls:
- [setKernelRootDir, ['%kernel.root_dir%']]
With that, the MyService
service will automatically have the %kernerl.root_dir%
parameter. :-)
The interest of trait is the re-usability of them. This will remove lot of manual parameter definition lines.
What do you think?