Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from vincentchalamon/issues/3
Browse files Browse the repository at this point in the history
[RFR] Fix #3: improve autowiring
  • Loading branch information
vincentchalamon authored Sep 18, 2017
2 parents 451780c + 4ec5b89 commit 1e237f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
11 changes: 10 additions & 1 deletion DependencyInjection/MigrationCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CoopTilleuls\MigrationBundle\DependencyInjection;

use CoopTilleuls\MigrationBundle\Loader\AbstractLoader;
use Doctrine\Common\Inflector\Inflector;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -39,8 +40,16 @@ public function process(ContainerBuilder $container)
{
$services = [];
foreach ($container->findTaggedServiceIds($this->tag) as $id => $attributes) {
$class = $container->getDefinition($id)->getClass();
$definition = $container->getDefinition($id);
$class = $definition->getClass();
$reflection = new \ReflectionClass($class);

// Override AbstractLoader parameters for autowiring
if ($reflection->isSubclassOf(AbstractLoader::class)) {
$definition->replaceArgument('$connectionName', $container->getParameter('coop_tilleuls_migration.legacy_connection_name'));
}

// Generate aliases
$alias = Inflector::tableize(preg_replace('/^(.*)Loader$/i', '$1', $reflection->getShortName()));
$aliases = [$class, $alias, str_replace('_', '-', $alias)];
if (true === $this->allowAlias && isset($attributes[0]['alias'])) {
Expand Down
20 changes: 6 additions & 14 deletions features/app/LegacyBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
services:
legacy.loader.user:
class: CoopTilleuls\MigrationBundle\Tests\LegacyBundle\Loader\UserLoader
parent: coop_tilleuls_migration.loader.abstract
tags:
- { name: coop_tilleuls_migration.loader, alias: user }
_defaults:
autowire: true
autoconfigure: true
public: false

legacy.loader.foo:
class: CoopTilleuls\MigrationBundle\Tests\LegacyBundle\Loader\FooLoader
tags:
- { name: coop_tilleuls_migration.loader }

legacy.transformer.user:
class: CoopTilleuls\MigrationBundle\Tests\LegacyBundle\Transformer\UserTransformer
tags:
- { name: coop_tilleuls_migration.transformer }
CoopTilleuls\MigrationBundle\Tests\LegacyBundle\:
resource: '%kernel.root_dir%/LegacyBundle/{Loader,Transformer}'

0 comments on commit 1e237f0

Please sign in to comment.