Skip to content

Commit

Permalink
Merge pull request #51 from moufmouf/autowire_alias
Browse files Browse the repository at this point in the history
Fixing autowiring on service aliases
  • Loading branch information
moufmouf committed Jan 24, 2020
2 parents 33a8cbb + 0a6d3cc commit df74e32
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion DependencyInjection/GraphqliteCompilerPass.php
Expand Up @@ -304,7 +304,11 @@ private function makePublicInjectedServices(ReflectionClass $refClass, Annotatio
});

foreach ($services as $service) {
$container->getDefinition($service)->setPublic(true);
if ($container->hasAlias($service)) {
$container->getAlias($service)->setPublic(true);
} else {
$container->getDefinition($service)->setPublic(true);
}
}

}
Expand Down
5 changes: 3 additions & 2 deletions Tests/Fixtures/Entities/Contact.php
Expand Up @@ -37,11 +37,12 @@ public function getName(): string
* @Field()
* @Autowire(for="$testService")
* @Autowire(for="$someService", identifier="someService")
* @Autowire(for="$someAlias", identifier="someAlias")
* @return string
*/
public function injectService(TestGraphqlController $testService = null, stdClass $someService = null): string
public function injectService(TestGraphqlController $testService = null, stdClass $someService = null, stdClass $someAlias = null): string
{
if (!$testService instanceof TestGraphqlController || $someService === null) {
if (!$testService instanceof TestGraphqlController || $someService === null || $someAlias === null) {
return 'KO';
}
return 'OK';
Expand Down
3 changes: 3 additions & 0 deletions Tests/Fixtures/config/services.yaml
Expand Up @@ -20,6 +20,9 @@ services:
someService:
class: stdClass

someAlias:
alias: someService

Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler
# controllers are imported separately to make sure services can be injected
Expand Down

0 comments on commit df74e32

Please sign in to comment.