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