-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: better condition to not load routes
- Loading branch information
Etienne Gutbub
committed
Sep 6, 2023
1 parent
457090d
commit a548713
Showing
3 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' No Commerce plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <sylius@monsieurbiz.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusNoCommercePlugin\Routing; | ||
|
||
use Exception; | ||
use MonsieurBiz\SyliusNoCommercePlugin\Provider\FeaturesProviderInterface; | ||
use Symfony\Component\Routing\RequestContext as BaseRequestContext; | ||
|
||
final class NoCommerceRequestContext extends BaseRequestContext | ||
{ | ||
private BaseRequestContext $decorated; | ||
|
||
private FeaturesProviderInterface $featuresProvider; | ||
|
||
public function __construct( | ||
BaseRequestContext $decorated, | ||
FeaturesProviderInterface $featuresProvider | ||
) { | ||
parent::__construct( | ||
$decorated->getBaseUrl(), | ||
$decorated->getMethod(), | ||
$decorated->getHost(), | ||
$decorated->getScheme(), | ||
$decorated->getHttpPort(), | ||
$decorated->getHttpsPort(), | ||
$decorated->getPathInfo(), | ||
$decorated->getQueryString() | ||
); | ||
$this->decorated = $decorated; | ||
$this->featuresProvider = $featuresProvider; | ||
} | ||
|
||
public function checkNoCommerce(): bool | ||
{ | ||
return $this->featuresProvider->isNoCommerceEnabledForChannel(); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* | ||
* @return mixed | ||
*/ | ||
public function __call(string $name, array $arguments) | ||
{ | ||
$callback = [$this->decorated, $name]; | ||
if (\is_callable($callback)) { | ||
return \call_user_func($callback, $arguments); | ||
} | ||
|
||
throw new Exception(sprintf('Method %s not found for class "%s"', $name, \get_class($this->decorated))); | ||
} | ||
} |