|
- <?php
-
- namespace Lc\CaracoleBundle\Factory;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\SectionResolver;
- use Lc\SovBundle\Factory\AbstractFactory as SovAbstractFactory;
-
- trait FactoryTrait
- {
- protected $merchantResolver;
- protected $sectionResolver;
-
- public function __construct(
- EntityManagerInterface $em,
- MerchantResolver $merchantResolver,
- SectionResolver $sectionResolver
- ) {
- $this->em = $em;
- $this->merchantResolver = $merchantResolver;
- $this->sectionResolver = $sectionResolver;
- }
-
- public function create($params = array())
- {
- $entityClass = $this->em->getEntityName($this->getEntityClass());
- $entity = new $entityClass;
-
- if ($entity instanceof FilterMerchantInterface && !isset($params['merchant'])) {
- $params['merchant'] = $this->merchantResolver->getCurrent();
- }
-
- if ($entity instanceof FilterSectionInterface && !isset($params['section'])) {
- $params['section'] = $this->sectionResolver->getCurrent();
- }
-
- return parent::create($params);
- }
-
- }
|