Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SectionUtils.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Lc\ShopBundle\Services ;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Http\Discovery\Exception\NotFoundException;
  5. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  6. use Lc\ShopBundle\Context\SectionInterface;
  7. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  8. class SectionUtils
  9. {
  10. protected $em ;
  11. protected $merchantUtils ;
  12. protected $sectionRepository ;
  13. public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
  14. {
  15. $this->em = $em ;
  16. $this->sectionRepository = $this->em->getRepository($this->em->getClassMetadata(SectionInterface::class)->getName()) ;
  17. $this->merchantUtils = $merchantUtils ;
  18. }
  19. public function getSection($devAlias)
  20. {
  21. $section = $this->sectionRepository->findOneBy([
  22. 'merchant' => $this->merchantUtils->getMerchantCurrent(),
  23. 'devAlias' => $devAlias
  24. ]) ;
  25. if(!$section) {
  26. throw new NotFoundException('La section '.$devAlias.' est introuvable') ;
  27. }
  28. return $section ;
  29. }
  30. }