|
- <?php
-
- namespace Lc\ShopBundle\Services ;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Http\Discovery\Exception\NotFoundException;
- use Lc\ShopBundle\Context\MerchantUtilsInterface;
- use Lc\ShopBundle\Context\SectionInterface;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-
- class SectionUtils
- {
- protected $em ;
- protected $merchantUtils ;
- protected $sectionRepository ;
-
- public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
- {
- $this->em = $em ;
- $this->sectionRepository = $this->em->getRepository($this->em->getClassMetadata(SectionInterface::class)->getName()) ;
- $this->merchantUtils = $merchantUtils ;
- }
-
- public function getSection($devAlias)
- {
- $section = $this->sectionRepository->findOneBy([
- 'merchant' => $this->merchantUtils->getMerchantCurrent(),
- 'devAlias' => $devAlias
- ]) ;
-
- if(!$section) {
- throw new NotFoundException('La section '.$devAlias.' est introuvable') ;
- }
-
- return $section ;
- }
- }
|