Skip to content

Commit

Permalink
Readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
feuzeu committed Dec 22, 2024
1 parent bd0a3d6 commit afc0a7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Starting from version 2.3.0, the private services that need to be accessed with

These services will then be automatically passed to the service locator, together with those received as arguments.

In the following example, the `App\Services\TaggedService` service will be passed to the service locator.
In the following example, the `Twig` and `App\Services\TaggedService` services will be passed to the service locator.

```yaml
lagdo.facades.service_locator:
Expand Down
12 changes: 4 additions & 8 deletions src/DependencyInjection/Compiler/CompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

use function array_keys;

class CompilerPass implements CompilerPassInterface
{
/**
Expand All @@ -20,16 +18,14 @@ public function process(ContainerBuilder $container): void
return;
}

$serviceLocatorDefinition = $container->getDefinition('lagdo.facades.service_locator');

$serviceLocator = $container->getDefinition('lagdo.facades.service_locator');
// Append the tagged services to the service locator first argument.
$locatedServices = $serviceLocatorDefinition->getArguments()[0] ?? [];
$locatedServices = $serviceLocator->getArguments()[0] ?? [];
$services = $container->findTaggedServiceIds('lagdo.facades.service');
foreach(array_keys($services) as $service)
foreach($services as $service => $_)
{
$locatedServices[$service] = new Reference($service);
}

$serviceLocatorDefinition->replaceArgument(0, $locatedServices);
$serviceLocator->replaceArgument(0, $locatedServices);
}
}

0 comments on commit afc0a7d

Please sign in to comment.