UserFactory is now gets UserRepository directly instead of EntityManager.
This commit is contained in:
parent
55b5aaa1a2
commit
097d9a5f65
|
@ -82,7 +82,7 @@ services:
|
|||
# User factory
|
||||
app.point.user_factory:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory
|
||||
arguments: [ '@doctrine.orm.entity_manager' ]
|
||||
arguments: [ '@app.point.user_repository' ]
|
||||
|
||||
# Comment factory
|
||||
app.point.comment_factory:
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
namespace Skobkin\Bundle\PointToolsBundle\Service\Factory;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\User as UserDTO;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\ApiException;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\Factory\InvalidUserDataException;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException;
|
||||
|
@ -14,22 +14,16 @@ use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException;
|
|||
class UserFactory
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var EntityRepository
|
||||
* @var UserRepository
|
||||
*/
|
||||
private $userRepository;
|
||||
|
||||
/**
|
||||
* @param EntityManagerInterface $em
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(UserRepository $userRepository)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->userRepository = $em->getRepository('SkobkinPointToolsBundle:User');
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +42,7 @@ class UserFactory
|
|||
if (null === ($user = $this->userRepository->find($data['id']))) {
|
||||
// Creating new user
|
||||
$user = new User($data['id']);
|
||||
$this->em->persist($user);
|
||||
$this->userRepository->add($user);
|
||||
}
|
||||
|
||||
// Updating data
|
||||
|
@ -76,7 +70,7 @@ class UserFactory
|
|||
if (null === ($user = $this->userRepository->find($userData->getId()))) {
|
||||
// Creating new user
|
||||
$user = new User($userData->getId());
|
||||
$this->em->persist($user);
|
||||
$this->userRepository->add($user);
|
||||
}
|
||||
|
||||
// Updating data
|
||||
|
|
Loading…
Reference in a new issue