Skip to content

Commit

Permalink
[All] DependencyInjection new ContainerBuilderIntegrationInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Jun 28, 2024
1 parent d05e2a4 commit f2e4d58
Show file tree
Hide file tree
Showing 41 changed files with 319 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

namespace Draw\Component\AwsToolKit\DependencyInjection;

use Draw\Component\AwsToolKit\DependencyInjection\Compiler\AddNewestInstanceRoleCommandOptionPass;
use Draw\Component\AwsToolKit\EventListener\NewestInstanceRoleCheckListener;
use Draw\Component\AwsToolKit\Imds\ImdsClientInterface;
use Draw\Component\AwsToolKit\Imds\ImdsClientV1;
use Draw\Component\AwsToolKit\Imds\ImdsClientV2;
use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationTrait;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;

class AwsToolKitIntegration implements IntegrationInterface
class AwsToolKitIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface
{
use IntegrationTrait;

Expand All @@ -21,6 +23,11 @@ public function getConfigSectionName(): string
return 'aws_tool_kit';
}

public function buildContainer(ContainerBuilder $container): void
{
$container->addCompilerPass(new AddNewestInstanceRoleCommandOptionPass());
}

public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
{
$this->registerClasses(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Draw\Component\AwsToolKit\DependencyInjection\Compiler;

use Draw\Component\AwsToolKit\EventListener\NewestInstanceRoleCheckListener;
use Draw\Component\DependencyInjection\Container\DefinitionFinder;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

class AddNewestInstanceRoleCommandOptionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
try {
$container->findDefinition(NewestInstanceRoleCheckListener::class);
} catch (ServiceNotFoundException) {
return;
}

foreach (DefinitionFinder::findConsoleCommandDefinitions($container) as $definition) {
$definition
->addMethodCall(
'addOption',
[
NewestInstanceRoleCheckListener::OPTION_AWS_NEWEST_INSTANCE_ROLE,
null,
InputOption::VALUE_REQUIRED,
'The instance role the server must be the newest of to run the command.',
]
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Draw\Bundle\FrameworkExtraBundle\Tests\DependencyInjection\Compiler;
namespace Draw\Component\AwsToolKit\Tests\DependencyInjection\Compiler;

use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddNewestInstanceRoleCommandOptionPass;
use Draw\Component\AwsToolKit\DependencyInjection\Compiler\AddNewestInstanceRoleCommandOptionPass;
use Draw\Component\AwsToolKit\EventListener\NewestInstanceRoleCheckListener;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler;
namespace Draw\Component\Console\DependencyInjection\Compiler;

use Draw\Component\Console\EventListener\CommandFlowListener;
use Draw\Component\DependencyInjection\Container\DefinitionFinder;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -18,12 +19,7 @@ public function process(ContainerBuilder $container): void
return;
}

foreach (array_keys($container->findTaggedServiceIds('console.command')) as $serviceId) {
$definition = $container->getDefinition($serviceId);
if ($definition->isAbstract()) {
continue;
}

foreach (DefinitionFinder::findConsoleCommandDefinitions($container) as $definition) {
$definition->addMethodCall(
'addOption',
[
Expand Down
9 changes: 8 additions & 1 deletion packages/console/DependencyInjection/ConsoleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Draw\Component\Console\DependencyInjection;

use Draw\Component\Console\Command\PurgeExecutionCommand;
use Draw\Component\Console\DependencyInjection\Compiler\AddCommandExecutionOptionsCompilerPass;
use Draw\Component\Console\Descriptor\TextDescriptor;
use Draw\Component\Console\Entity\Execution;
use Draw\Component\Console\EventListener\CommandFlowListener;
use Draw\Component\Console\EventListener\DocumentationFilterCommandEventListener;
use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationTrait;
use Draw\Component\DependencyInjection\Integration\PrependIntegrationInterface;
Expand All @@ -17,7 +19,7 @@
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;

class ConsoleIntegration implements IntegrationInterface, PrependIntegrationInterface
class ConsoleIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface, PrependIntegrationInterface
{
use IntegrationTrait;

Expand All @@ -26,6 +28,11 @@ public function getConfigSectionName(): string
return 'console';
}

public function buildContainer(ContainerBuilder $container): void
{
$container->addCompilerPass(new AddCommandExecutionOptionsCompilerPass());
}

public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
{
$this->registerClasses(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Draw\Bundle\FrameworkExtraBundle\Tests\DependencyInjection\Compiler;
namespace Draw\Component\Console\Tests\DependencyInjection\Compiler;

use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddCommandExecutionOptionsCompilerPass;
use Draw\Component\Console\DependencyInjection\Compiler\AddCommandExecutionOptionsCompilerPass;
use Draw\Component\Console\EventListener\CommandFlowListener;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Draw\Component\CronJob\DependencyInjection\Compiler;

use Draw\Component\CronJob\EventListener\PostExecutionQueueCronJobListener;
use Draw\Component\DependencyInjection\Container\DefinitionFinder;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

class AddPostCronJobExecutionOptionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
try {
$container->findDefinition(PostExecutionQueueCronJobListener::class);
} catch (ServiceNotFoundException) {
return;
}

foreach (DefinitionFinder::findConsoleCommandDefinitions($container) as $definition) {
$definition
->addMethodCall(
'addOption',
[
PostExecutionQueueCronJobListener::OPTION_POST_EXECUTION_QUEUE_CRON_JOB,
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Queue does cron job by name after execution of the command.',
]
);
}
}
}
9 changes: 8 additions & 1 deletion packages/cron-job/DependencyInjection/CronJobIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
namespace Draw\Component\CronJob\DependencyInjection;

use Draw\Component\CronJob\CronJobProcessor;
use Draw\Component\CronJob\DependencyInjection\Compiler\AddPostCronJobExecutionOptionPass;
use Draw\Component\CronJob\Entity\CronJob;
use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationTrait;
use Draw\Component\DependencyInjection\Integration\PrependIntegrationInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;

class CronJobIntegration implements IntegrationInterface, PrependIntegrationInterface
class CronJobIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface, PrependIntegrationInterface
{
use IntegrationTrait;

Expand All @@ -22,6 +24,11 @@ public function getConfigSectionName(): string
return 'cron_job';
}

public function buildContainer(ContainerBuilder $container): void
{
$container->addCompilerPass(new AddPostCronJobExecutionOptionPass());
}

public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
{
$this->registerClasses(
Expand Down
24 changes: 24 additions & 0 deletions packages/dependency-injection/Container/DefinitionFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Draw\Component\DependencyInjection\Container;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class DefinitionFinder
{
/**
* @return iterable<Definition>
*/
public static function findConsoleCommandDefinitions(ContainerBuilder $container, bool $ignoreAbstract = true): iterable
{
foreach (array_keys($container->findTaggedServiceIds('console.command')) as $serviceId) {
$definition = $container->getDefinition($serviceId);
if ($ignoreAbstract && $definition->isAbstract()) {
continue;
}

yield $definition;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler;
namespace Draw\Component\DependencyInjection\DependencyInjection\Compiler;

use Draw\Component\Core\Reflection\ReflectionAccessor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Draw\Component\DependencyInjection\DependencyInjection;

use Draw\Component\DependencyInjection\DependencyInjection\Compiler\TagIfExpressionCompilerPass;
use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;

class DependencyInjectionIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface
{
public function getConfigSectionName(): string
{
return 'dependency_injection';
}

public function buildContainer(ContainerBuilder $container): void
{
$container->addCompilerPass(new TagIfExpressionCompilerPass());
}

public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
{
}

public function addConfiguration(ArrayNodeDefinition $node): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Draw\Component\DependencyInjection\Integration;

use Symfony\Component\DependencyInjection\ContainerBuilder;

interface ContainerBuilderIntegrationInterface
{
public function buildContainer(ContainerBuilder $container): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ trait ExtendableExtensionTrait

abstract private function provideExtensionClasses(): array;

/**
* @return array<IntegrationInterface>
*/
public function getIntegrations(): array
{
return $this->integrations;
}

private function registerDefaultIntegrations(): void
{
foreach ($this->provideExtensionClasses() as $extensionClass) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler;
namespace Draw\Component\EntityMigrator\DependencyInjection\Compiler;

use Draw\Component\EntityMigrator\MigrationInterface;
use Draw\Component\EntityMigrator\Migrator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Draw\Component\EntityMigrator\DependencyInjection;

use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationInterface;
use Draw\Component\DependencyInjection\Integration\IntegrationTrait;
use Draw\Component\DependencyInjection\Integration\PrependIntegrationInterface;
use Draw\Component\EntityMigrator\Command\MigrateCommand;
use Draw\Component\EntityMigrator\Command\QueueBatchCommand;
use Draw\Component\EntityMigrator\DependencyInjection\Compiler\EntityMigratorCompilerPass;
use Draw\Component\EntityMigrator\Entity\BaseEntityMigration;
use Draw\Component\EntityMigrator\Entity\EntityMigrationInterface;
use Draw\Component\EntityMigrator\Entity\Migration;
Expand All @@ -18,7 +20,7 @@
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;

class EntityMigratorIntegration implements IntegrationInterface, PrependIntegrationInterface
class EntityMigratorIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface, PrependIntegrationInterface
{
use IntegrationTrait;

Expand All @@ -27,6 +29,11 @@ public function getConfigSectionName(): string
return 'entity_migrator';
}

public function buildContainer(ContainerBuilder $container): void
{
$container->addCompilerPass(new EntityMigratorCompilerPass());
}

public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
{
$container
Expand Down

This file was deleted.

Loading

0 comments on commit f2e4d58

Please sign in to comment.