My problem is the $this->getUser();
method (called from Controller) from Symfony Security can't get my User Repository.
The "App\Model\ODM\Repository\UserRepository" document repository implements "Doctrine\Bundle\MongoDBBundle\Repository\ServiceDocumentRepositoryInterface", but its service could not be found. Make sure the service exists and is tagged with "doctrine_mongodb.odm.repository_service".
I have a CompilerPass that get my Repositories and add them to Container Definitions depending on some env value.
I add the Repo with "generic" Interfaces (valid for both ODM and ORM) as keys AND with the Repo FQCN as keys, so they should be accessible via both the generic Interface and the true Repo name, but I'm working only with ODM for now.
Also, I "tag" my repo with doctrine_mongodb
argument, to extends the ServiceDocumentRepository
baseClass.
I don't include the compilerPass because the class is quite "heavy", but if needed I'll include it.
Here is my UserRepo
class UserRepository extends BaseRepository implements RepositoryInterface, UserRepositoryInterface
{
/**
* UserRepository constructor.
*
* @param ManagerRegistry $managerRegistry
*/
public function __construct(ManagerRegistry $managerRegistry)
{
parent::__construct($managerRegistry, User::class);
}
...
My BaseRepo (just a few methods in here, just the extends is interesting)
abstract class BaseRepository extends ServiceDocumentRepository implements RepositoryInterface
{
...
It's working great "in-app", I could create a User on a registration page, but using $guardHandler->authenticateUserAndHandleSuccess()
method after register, i'm redirected to my homepage where the $this->getUser();
is, and then I have the error message posted above.
After some research, it seems the problem is in Doctrine\Bundle\MongoDBBundle\Repository\ContainerRepositoryFactory
The container
of this class doesn't seem to have any of my Repo definition.
I surely missed something but I don't know where.
I remember making something similar few years ago but extending DocumentRepository
and not ServiceDocumentRepository
.
If you need any other information, let me know.
I feel really dumb about this question now that I found the solution ...
It was LITTERALY in the error message, I just had to add doctrine_mongodb.odm.repository_service
to my Repo's Definition, in my Compiler Pass
...
$definition->addArgument(new Reference('doctrine_mongodb'));
$definition->addTag('doctrine_mongodb.odm.repository_service');
...
Thanks to the people who looked at my problem and sorry for wasting your time.
I Hope this answer could help others peoples that register Repo in a CompilerPass
(I will set this answer as the solution asap, in 2 days)