Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI\DependencyException for Proxied Class #71

Open
djschilling opened this issue Nov 27, 2023 · 3 comments · Fixed by #77
Open

DI\DependencyException for Proxied Class #71

djschilling opened this issue Nov 27, 2023 · 3 comments · Fixed by #77
Labels
bug 🐞 Something isn't working

Comments

@djschilling
Copy link

I have a Class GroupMemberService which is Proxied by php-aop.
In its constructor the class GroupPolicy is passed which is also proxied.

I use DI to inject the constructor params.

This error occurs when i try to get GroupMemberService from the DI Service:

DI\DependencyException : Error while injecting dependencies into Churchtools\Domain\Group\Member\GroupMemberService: No entry or class found for 'Churchtools\Domain\Group\GroupPolicy__AopProxied'
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ObjectCreator.php:133
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ObjectCreator.php:56
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php:60
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Container.php:353
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Container.php:136
 /Users/david/projects/churchtools/tests/php/integration/Domain/Group/Member/GroupMemberWaitingListTest.php:52
 
 Caused by
 DI\NotFoundException: No entry or class found for 'Churchtools\Domain\Group\GroupPolicy__AopProxied'
 
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Container.php:133
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Reference.php:44
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php:55
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ParameterResolver.php:73
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ObjectCreator.php:124
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ObjectCreator.php:56
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php:60
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Container.php:353
 /Users/david/projects/churchtools/system/composer/php-di/php-di/src/Container.php:136
 /Users/david/projects/churchtools/tests/php/integration/Domain/Group/Member/GroupMemberWaitingListTest.php:52
@djschilling
Copy link
Author

I had today the same issue with an other Class: GroupService

I think i now know the reason for this issue.
Most of our dependencies can be resolved automatically by DI but not all.
For some of them we define them in our code like this:

    GroupService::class => static function (ContainerInterface $container) {
        return new GroupService(
            $container->get(EntityManager::class),
            ...
        );
    },

The Problem gets resolved if i define both GroupService and GroupService__AopProxied like this:

    GroupService::class => static function (ContainerInterface $container) {
        return new GroupService(
            $container->get(EntityManager::class),
            ...
        );
    },
    GroupService::class . '__AopProxied' => static function (ContainerInterface $container) {
        return $container->get(GroupService::class);
    },

It seems to work but its not a great solution because now i have to do this each time i use an Attribute in one of the classes i defined the definitions for in code.

@djschilling
Copy link
Author

I had again a similar case but a little different.

I have a class SignUpService with a function signUpMultipleForms. This function has a annotation which is handled by this framework and so a proxy class is created for it.
This is the start of the function:

Bildschirmfoto 2024-01-21 um 20 04 37

When calling the constructor of SignUpConditions i get the error: Churchtools\\Domain\\GroupHomepage\\SignUpConditions::__construct(): Argument #3 ($groupPolicy) must be of type Churchtools\\Domain\\Group\\GroupPolicy, Churchtools\\Domain\\Group\\GroupPolicy__AopProxied given, called in /private/var/tmp/ct-aop-cache/32167/proxies/src/Domain/GroupHomepage/SignUpService.php on line 159

My guess is that it has something to do with the SignUpConditions not being Proxied, but i am not sure.

@WalterWoshid do you have an idea about these issues?

@WalterWoshid
Copy link
Contributor

WalterWoshid commented May 11, 2024

Hi there, it was difficult trying to reproduce it, but I found some other errors. After a lot of thought and stupid luck, I removed all the type replacement logic and what a wonder, every test still worked. I think that might have fixed all your DI problems. I added some tests that looked similar to your code, they also work.

Try version 1.2.11 and tell me if that worked for you :)

@WalterWoshid WalterWoshid reopened this May 11, 2024
@WalterWoshid WalterWoshid added the bug 🐞 Something isn't working label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants