Closed
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | yes |
Symfony version | 4.0.6 |
I started to use more and more PHP based configuration which allows managing configuration much nicer than any other file format, but encounter bit a problem. PHPFileLoader
both in DI/Router check if a returned value from config file is \Closure:
if ($callback instanceof \Closure) {
$callback(new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource), $this->container, $this);
}
For example, I am using this kind of style configurations:
<?php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
$configuration = new class {
public function registerDoctrineEntities(ContainerConfigurator $configurator): void
{
// ...
}
public function registerDoctrineRepositories(ContainerConfigurator $configurator): void
{
// ...
}
public function registerParameters(ContainerConfigurator $configurator): void
{
// ...
}
public function registerServices(ContainerConfigurator $configurator): void
{
// ...
}
public function __invoke(ContainerConfigurator $configurator): void
{
$this->registerDoctrineEntities($configurator);
$this->registerDoctrineRepositories($configurator);
$this->registerParameters($configurator);
$this->registerServices($configurator);
}
};
return $configuration;
But at the moment, I can't return $configuration
because of the check of if ($callback instanceof \Closure)
if it was is_callable($callback)
it would let me use this kind of style configurations. But Instead, now I have to wrap it in the anonymous function. Magic method __invoke
is used by a lot of closure style based systems like Middlewares and etc.
If you think this is possible I can create pull requests for this feature.