You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Factory;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  5. use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
  6. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  7. use Lc\CaracoleBundle\Resolver\SectionResolver;
  8. use Lc\SovBundle\Factory\AbstractFactory as SovAbstractFactory;
  9. trait FactoryTrait
  10. {
  11. protected $merchantResolver;
  12. protected $sectionResolver;
  13. public function __construct(
  14. EntityManagerInterface $em,
  15. MerchantResolver $merchantResolver,
  16. SectionResolver $sectionResolver
  17. ) {
  18. $this->em = $em;
  19. $this->merchantResolver = $merchantResolver;
  20. $this->sectionResolver = $sectionResolver;
  21. }
  22. public function create($params = array())
  23. {
  24. $entityClass = $this->em->getEntityName($this->getEntityClass());
  25. $entity = new $entityClass;
  26. if ($entity instanceof FilterMerchantInterface && !isset($params['merchant'])) {
  27. $params['merchant'] = $this->merchantResolver->getCurrent();
  28. }
  29. if ($entity instanceof FilterSectionInterface && !isset($params['section'])) {
  30. $params['section'] = $this->sectionResolver->getCurrent();
  31. }
  32. return parent::create($params);
  33. }
  34. }