src/Core/Router/Router.php line 65
<?phpdeclare(strict_types=1);/*** Copyright (c) 2020 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2020 TECLA Consulting Group oü*/namespace App\Core\Router;use App\Component\Identity\Encoder\IdEncoderInterface;use App\Component\Identity\IdInterface;use App\Contact\Security\ContactContextInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;use Symfony\Component\Routing\Matcher\RequestMatcherInterface;use Symfony\Component\Routing\RequestContext;use Symfony\Component\Routing\RouteCollection;use Symfony\Component\Routing\RouterInterface;final class Router implements RouterInterface, RequestMatcherInterface, WarmableInterface{private RouterInterface $router;private IdEncoderInterface $idEncoder;private ContactContextInterface $contactContext;public function __construct(RouterInterface $router,IdEncoderInterface $idEncoder,ContactContextInterface $contactContext) {$this->router = $router;$this->idEncoder = $idEncoder;$this->contactContext = $contactContext;}public function setContext(RequestContext $context){return $this->router->setContext($context);}public function getContext(): RequestContext{return $this->router->getContext();}public function matchRequest(Request $request): array{if (false === $this->router instanceof RequestMatcherInterface) {throw new \BadMethodCallException(sprintf('Router has to implement the "%s".', RequestMatcherInterface::class));}return $this->router->matchRequest($request);}public function getRouteCollection(): RouteCollection{return $this->router->getRouteCollection();}public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string{if (false === str_starts_with($name, '_')) {$this->addContextParameter($parameters);$this->encodeParametersIds($parameters);}return $this->router->generate($name, $parameters, $referenceType);}public function match(string $pathinfo): array{return $this->router->match($pathinfo);}public function warmUp(string $cacheDir): array{if ($this->router instanceof WarmableInterface) {$this->router->warmUp($cacheDir);}return [];}private function addContextParameter(array &$parameters): void{if (true === \array_key_exists('cid', $parameters)) {return;}if (null === $currentContact = $this->contactContext->getCurrent()) {return;}$parameters['cid'] = $currentContact->getId();}private function encodeParametersIds(array &$parameters): void{foreach ($parameters as $key => $parameter) {if (false === $parameter instanceof IdInterface) {continue;}$parameters[$key] = $this->idEncoder->encode($parameter);}}}