Last active
October 20, 2023 01:07
-
-
Save vudaltsov/4c2329a4ad1f8a80ca0e61017cea36cb to your computer and use it in GitHub Desktop.
Symfony PHP configurator ContainerBuilder injection example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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