|
|
@@ -2,11 +2,11 @@ |
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Manager; |
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManager as DoctrineEntityManager; |
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
use Lc\ShopBundle\Context\UserInterface; |
|
|
|
use Lc\ShopBundle\Event\EntityManager\EntityManagerEvent; |
|
|
|
//use Lc\ShopBundle\IModel\EntityInterface; |
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
|
/** |
|
|
|
* class EntityManager. |
|
|
@@ -16,13 +16,24 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
|
|
class EntityManager |
|
|
|
{ |
|
|
|
protected $eventDispatcher; |
|
|
|
|
|
|
|
protected $entityManager; |
|
|
|
protected $security; |
|
|
|
protected $userSystem = null; |
|
|
|
|
|
|
|
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager) |
|
|
|
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, Security $security) |
|
|
|
{ |
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
|
|
$this->entityManager = $entityManager; |
|
|
|
$this->security = $security; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUserSystem() |
|
|
|
{ |
|
|
|
if ($this->userSystem === null) { |
|
|
|
$this->userSystem = $this->entityManager->getRepository($this->getEntityName(UserInterface::class))->findOneByDevAlias('system'); |
|
|
|
} |
|
|
|
return $this->userSystem; |
|
|
|
} |
|
|
|
|
|
|
|
public function getRepository($className) |
|
|
@@ -33,14 +44,21 @@ class EntityManager |
|
|
|
|
|
|
|
public function create($entity): self |
|
|
|
{ |
|
|
|
|
|
|
|
if ($this->security->getUser() === null) { |
|
|
|
$entity->setUpdatedBy($this->getUserSystem()); |
|
|
|
$entity->setCreadtedBy($this->getUserSystem()); |
|
|
|
} |
|
|
|
$this->persist($entity); |
|
|
|
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::CREATE_EVENT); |
|
|
|
|
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|
public function update($entity): self |
|
|
|
{ |
|
|
|
if ($this->security->getUser() === null) { |
|
|
|
$entity->setUpdatedBy($this->getUserSystem()); |
|
|
|
} |
|
|
|
$this->persist($entity); |
|
|
|
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::UPDATE_EVENT); |
|
|
|
|
|
|
@@ -78,7 +96,7 @@ class EntityManager |
|
|
|
{ |
|
|
|
if (substr($className, -9) === 'Interface') { |
|
|
|
return $this->entityManager->getClassMetadata($className)->getName(); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
return $className; |
|
|
|
} |
|
|
|
|