-
I'm trying to create a single-file bundle which would autowire / autoconfigure a namespace. Currently I have this: <?php
declare(strict_types=1);
namespace Import;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ImportBundle extends Bundle
{
public function createContainerExtension(): ExtensionInterface
{
return new class extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->import('config.php');
}
public function getAlias(): string
{
return 'import';
}
};
}
} and <?php
use Symfony\Component\DependencyInjection\Loader\Configurator\ Is it possible to merge these two files into one? I was looking at using the Callback loader, but it doesn't seem to work as I expect. TIA. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Looks like ClosureLoader can't take a configurator. Perhaps a nice feature :) ref #42647 also |
Beta Was this translation helpful? Give feedback.
-
If you want to keep things in a single file, your extension class will need to define its services using the lower-level API of the DI component (i.e. using the |
Beta Was this translation helpful? Give feedback.
-
This proposal #43701 could help here. |
Beta Was this translation helpful? Give feedback.
-
I just wanted to come back to this ticket to let you know that you can now use https://github.com/yceruto/micro-symfony for this goal (it is available for 5.4 so far). |
Beta Was this translation helpful? Give feedback.
This proposal #43701 could help here.