您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

44 行
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. parent::__construct($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. }