Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace League\Tactician\Bundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* This compiler pass maps Handler DI tags to specific commands
*/
class CommandHandlerPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*
* @throws \Exception
* @api
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('tactician.handler.locator.symfony')) {
throw new \Exception('Missing tactician.handler.locator.symfony definition');
}
$handlerLocator = $container->findDefinition('tactician.handler.locator.symfony');
$mapping = [];
foreach ($container->findTaggedServiceIds('tactician.handler') as $id => $tags) {
foreach ($tags as $attributes) {
if (!isset($attributes['command'])) {
throw new \Exception('The tactician.handler tag must always have a command attribute');
}
$mapping[$attributes['command']] = $id;
}
}
$handlerLocator->addArgument($mapping);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace League\Tactician\Bundle\DependencyInjection\Compiler;
use League\Tactician\Doctrine\ORM\TransactionMiddleware;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
/**
* This compiler pass registers doctrine entity manager middleware
*/
class DoctrineMiddlewarePass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!class_exists(TransactionMiddleware::class) || !$container->hasParameter('doctrine.entity_managers')) {
return;
}
$entityManagers = $container->getParameter('doctrine.entity_managers');
if (empty($entityManagers)) {
return;
}
foreach ($entityManagers as $name => $serviceId) {
$container->setDefinition(
sprintf('tactician.middleware.doctrine.%s', $name),
new Definition(TransactionMiddleware::class, [ new Reference($serviceId) ])
);
}
$defaultEntityManager = $container->getParameter('doctrine.default_entity_manager');
$container->setAlias('tactician.middleware.doctrine', sprintf('tactician.middleware.doctrine.%s', $defaultEntityManager));
}
}