FOSFacebookBundle integration with custom User stuff (without FOSUB)

143 Views Asked by At


I don't use FOSUserBundle and I've got a UserRepository which manage my users :

<?php

class UserRepository extends EntityRepository implements UserProviderInterface
{
    public function loadUserByUsername($username)
    {
        $q = $this
            ->createQueryBuilder('u')
            ->where('u.username = :username OR u.email = :email')
            ->setParameter('username', $username)
            ->setParameter('email', $username)
            ->getQuery();

        try {
            $user = $q->getSingleResult();
        } catch (NoResultException $e) {
            throw new UsernameNotFoundException(sprintf('Unable to find an active User object identified by "%s".', $username), 0, $e);
        }

        return $user;
    }

    public function refreshUser(UserInterface $user)
    {
        $class = get_class($user);
        if (!$this->supportsClass($class)) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class));
        }

        return $this->loadUserByUsername($user->getUsername());
    }

    public function supportsClass($class)
    {
        return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName());
    }

    protected function findUserBy(array $criteria)
    {
        $userRepository = $this->getEntityManager()->getRepository('FindBack\SiteBundle\Entity\User');
        return $userRepository->findOneBy($criteria);
    }

}

I want to use FOSFacebookBundle in my application so I follow the configuration steps as they are described in : FOSFacebookBundle documentation

So, I've got to define a custom FacebookProvider and create the associated service :

services:
    my.facebook.user:
        class: Acme\MyBundle\Security\User\Provider\FacebookProvider
        arguments:
            facebook: "@fos_facebook.api"
            userManager: "@fos_user.user_manager"
            validator: "@validator"

I don't have any userManager, but I have a UserProvider which is my UserRepository. Do have I to set the userManager to my UserRepository like this :

userManager: "@my_user_repository"       ?

My User Provider is defined in config.yml this way :

providers:
    main:
        entity: { class: FindBackSiteBundle:User }

Do have I to make it a service in order to use it as an argument (see above) ?

I tried to do it and it failed. I think I must set arguments to my user_repository service because it extends EntityRepository.
I actually got an error :

... Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, none given ...

Is there a way to integrate FOSFacebookBundle with my own User stuff, without FOSUserBundle ?

Thanks in advance !

0

There are 0 best solutions below