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.

преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @author La clic ! <contact@laclic.fr>
  4. */
  5. namespace Lc\CaracoleBundle\Resolver;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  8. use Lc\SovBundle\Resolver\UrlResolver;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. class MerchantResolver
  11. {
  12. protected $requestStack;
  13. protected $em;
  14. protected $urlResolver;
  15. public function __construct(EntityManagerInterface $entityManager, RequestStack $requestStack, UrlResolver $urlResolver)
  16. {
  17. $this->requestStack = $requestStack;
  18. $this->em = $entityManager;
  19. $this->urlResolver = $urlResolver;
  20. }
  21. public function getCurrent(): MerchantInterface
  22. {
  23. /* if($currentMerchant) {
  24. return $currentMerchant ;
  25. }*/
  26. $currentMerchant = false;
  27. $request = $this->requestStack->getCurrentRequest();
  28. $merchantRepo = $this->em->getRepository(MerchantInterface::class);
  29. $merchants = $merchantRepo->findAll();
  30. if ($request) {
  31. if ($this->urlResolver->isServerLocalhost()) {
  32. foreach ($merchants as $merchant) {
  33. if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) {
  34. $currentMerchant = $merchant;
  35. }
  36. }
  37. } // distant
  38. else {
  39. foreach ($merchants as $merchant) {
  40. $url = $merchant->getMerchantConfig('url');
  41. if ($url && strlen($url) && strpos($url, $_SERVER['HTTP_HOST']) !== false) {
  42. $currentMerchant = $merchant;
  43. }
  44. }
  45. }
  46. } else {
  47. /*if ($_ENV['CURRENT_MERCHANT_COMMAND']) {
  48. foreach ($merchants as $merchant) {
  49. if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_COMMAND']) {
  50. $currentMerchant = $merchant;
  51. }
  52. }
  53. }*/
  54. }
  55. if ($currentMerchant instanceof MerchantInterface) {
  56. return $currentMerchant;
  57. } else {
  58. throw new \ErrorException('Aucun merchant courant');
  59. }
  60. }
  61. }