src/WellCommerce/Bundle/AppBundle/Repository/ShopRepository.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=0);
  3. /*
  4.  * WellCommerce Foundation
  5.  *
  6.  * This file is part of the WellCommerce package.
  7.  *
  8.  * (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
  9.  *
  10.  * For the full copyright and license information,
  11.  * please view the LICENSE file that was distributed with this source code.
  12.  */
  13. namespace WellCommerce\Bundle\AppBundle\Repository;
  14. use Doctrine\Persistence\ManagerRegistry;
  15. use WellCommerce\Bundle\AppBundle\Entity\Shop;
  16. use WellCommerce\Bundle\CoreBundle\Doctrine\Repository\EntityRepository;
  17. /**
  18.  * Class ShopRepository
  19.  *
  20.  * @author Adam Piotrowski <adam@wellcommerce.org>
  21.  */
  22. class ShopRepository extends EntityRepository
  23. {
  24.     public function __construct(ManagerRegistry $registrystring $className Shop::class)
  25.     {
  26.         parent::__construct($registry$className);
  27.     }
  28.     public function resolve(int $currentShopIdstring $url): Shop
  29.     {
  30.         if (=== $currentShopId) {
  31.             $currentShop $this->findOneBy(['url' => $url]);
  32.             if ($currentShop instanceof Shop) {
  33.                 return $currentShop;
  34.             }
  35.         }
  36.         $currentShop $this->find($currentShopId);
  37.         if ($currentShop instanceof Shop) {
  38.             return $currentShop;
  39.         }
  40.         return $this->findOneBy([]);
  41.     }
  42. }