|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of Monsieur Biz' Search plugin for Sylius. |
| 5 | + * |
| 6 | + * (c) Monsieur Biz <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE.txt |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace MonsieurBiz\SyliusSearchPlugin\Routing; |
| 15 | + |
| 16 | +use Exception; |
| 17 | +use MonsieurBiz\SyliusSearchPlugin\Checker\ElasticsearchCheckerInterface; |
| 18 | +use Symfony\Component\Routing\RequestContext as BaseRequestContext; |
| 19 | + |
| 20 | +class RequestContext extends BaseRequestContext |
| 21 | +{ |
| 22 | + private BaseRequestContext $decorated; |
| 23 | + |
| 24 | + private ElasticsearchCheckerInterface $elasticsearchChecker; |
| 25 | + |
| 26 | + public function __construct( |
| 27 | + BaseRequestContext $decorated, |
| 28 | + ElasticsearchCheckerInterface $elasticsearchChecker |
| 29 | + ) { |
| 30 | + parent::__construct( |
| 31 | + $decorated->getBaseUrl(), |
| 32 | + $decorated->getMethod(), |
| 33 | + $decorated->getHost(), |
| 34 | + $decorated->getScheme(), |
| 35 | + $decorated->getHttpPort(), |
| 36 | + $decorated->getHttpsPort(), |
| 37 | + $decorated->getPathInfo(), |
| 38 | + $decorated->getQueryString() |
| 39 | + ); |
| 40 | + $this->decorated = $decorated; |
| 41 | + $this->elasticsearchChecker = $elasticsearchChecker; |
| 42 | + } |
| 43 | + |
| 44 | + public function checkElasticsearch(): bool |
| 45 | + { |
| 46 | + return $this->elasticsearchChecker->check(); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @throws Exception |
| 51 | + * |
| 52 | + * @return mixed |
| 53 | + */ |
| 54 | + public function __call(string $name, array $arguments) |
| 55 | + { |
| 56 | + $callback = [$this->decorated, $name]; |
| 57 | + if (\is_callable($callback)) { |
| 58 | + return \call_user_func($callback, $arguments); |
| 59 | + } |
| 60 | + |
| 61 | + throw new Exception(sprintf('Method %s not found for class "%s"', $name, \get_class($this->decorated))); |
| 62 | + } |
| 63 | +} |
0 commit comments