-
Notifications
You must be signed in to change notification settings - Fork 93
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
Custom generator as a service produces PHPStan error #297
Comments
How does an annotation like that look like? I need something to reproduce that. Also you might solve that by providing |
Will take a look at this objectManagerLoader feature. |
I just ran into the same issue, but there seems to be a solution that is cleaner anyway. This will trigger the error: ...and this will not:
|
objectManagerLoader (see README) will AFAIK solve it. |
@NMe84 it works because |
I know, I'm just pointing out that this would be a solution and, let's be honest, much cleaner code than using magic strings. |
Thanks this worked! use Symfony\Component\Uid\Uuid;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private Uuid $uuid; |
As @nicolas-grekas pointed out in symfony/symfony-docs#18427 (review), In many cases, If you don't want to change your application code, to solve the Can't instantiate custom generator issue, and want to keep using the service, I can confirm that using the # phpstan.neon
parameters:
doctrine:
objectManagerLoader: tests/object-manager.php # needs to be created according to README.md Maybe the README.md could be extended by something like:
Currently it sounds as the objectManagerLoader is relevant for "more advanced analysis" and "DQL validation" only. What do you think? After all, this seems not to be an issue with phpstan-doctrine to me. Instead the issue seems to be caused by Doctrine bundle, by intentionally using the |
Since Doctrine Bundle 2.3 we can pass a service id to the CustomIdGenerator annotation. However this causes
Internal error: Internal error: Can't instantiate custom generator : app.doctrine.user_id_generator in file /app/src/Entity/User.php
.BTW. Can this even be fixed? It would require
phpstan/phpstan-doctrine
to have access to the Symfony's DI container.The text was updated successfully, but these errors were encountered: