Browse Source

SectionResolver : getCurrent côté front

packProduct
Guillaume 3 years ago
parent
commit
be814ab33b
1 changed files with 34 additions and 8 deletions
  1. +34
    -8
      Resolver/SectionResolver.php

+ 34
- 8
Resolver/SectionResolver.php View File

protected MerchantResolver $merchantResolver; protected MerchantResolver $merchantResolver;
protected SectionStore $sectionStore; protected SectionStore $sectionStore;
protected RequestStack $requestStack; protected RequestStack $requestStack;
protected UrlResolver $urlResolver;


public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionStore $sectionStore, RequestStack $requestStack)
{
public function __construct(
EntityManagerInterface $entityManager,
MerchantResolver $merchantResolver,
SectionStore $sectionStore,
RequestStack $requestStack,
UrlResolver $urlResolver
) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->merchantResolver = $merchantResolver; $this->merchantResolver = $merchantResolver;
$this->sectionStore = $sectionStore; $this->sectionStore = $sectionStore;
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
$this->urlResolver = $urlResolver;
} }


public function getCurrent() public function getCurrent()
$requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all(); $requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all();


// admin // admin
if(isset($requestAttributesArray['easyadmin_context'])) {
if (isset($requestAttributesArray['easyadmin_context'])) {
$currentAdminSection = null; $currentAdminSection = null;
$userMerchant = $this->merchantResolver->getUserMerchant(); $userMerchant = $this->merchantResolver->getUserMerchant();


} }


return $currentAdminSection; return $currentAdminSection;
}
// front
} // front
else { else {
return $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOneDefault();
$sectionCurrent = null;
$isCli = php_sapi_name() === 'cli';

// local
if ($isCli || $this->urlResolver->isServerLocalhost()) {
$sectionArray = $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOnline();

foreach ($sectionArray as $section) {
if ($section->getDevAlias() == $_ENV['CURRENT_SECTION_LOCAL']) {
$sectionCurrent = $section;
}
}
}
// distant
else {
$sectionCurrent = $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOneDefault();
}

return $sectionCurrent;
} }
} }



Loading…
Cancel
Save