Skip to content

Instantly share code, notes, and snippets.

@vudaltsov
Last active October 20, 2023 01:07
Show Gist options
  • Save vudaltsov/4c2329a4ad1f8a80ca0e61017cea36cb to your computer and use it in GitHub Desktop.
Save vudaltsov/4c2329a4ad1f8a80ca0e61017cea36cb to your computer and use it in GitHub Desktop.
Symfony PHP configurator ContainerBuilder injection example
<?php
declare(strict_types=1);
namespace HardcorePhpCourse2\Infrastructure\MessageBus;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use VUdaltsov\SymfonyCourse\Infrastructure\MessageBus\Handler;
return static function (ContainerConfigurator $di, string $env, ContainerBuilder $containerBuilder): void {
if ($env === 'prod') {
// ...
}
$containerBuilder->addCompilerPass(new DependencyInjection\MessageBusPass());
$containerBuilder->registerForAutoconfiguration(Middleware::class)->addTag(Middleware::class);
$containerBuilder->registerAttributeForAutoconfiguration(
Attribute\Handler::class,
static function (ChildDefinition $definition, Handler $attribute, \Reflector $reflector): void {
// ...
},
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment