Skip to content

Commit

Permalink
Рефакторинг
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 24, 2021
1 parent 28efd7b commit bf04840
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion DependencyInjection/SymfonyRouterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ private function registerRouterConfiguration(
if ($config['router_caching_routes']) {
$routerDefinition = $container->getDefinition('router');
$routerDefinition->addMethodCall(
'setConfigCacheFactory', [new Reference('config_cache_factory')]
'setConfigCacheFactory',
[new Reference('config_cache_factory')]
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
init.router:
class: Prokl\BitrixSymfonyRouterBundle\Services\Router\InitRouter
arguments:
- '@routes.collection'
- '@router'
- '@routing.json.error.controller'
- '@event_dispatcher'
- '@controller_resolver'
Expand Down
23 changes: 17 additions & 6 deletions Services/Router/InitRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;

/**
* Class InitRouter
Expand All @@ -31,6 +31,7 @@
* @since 30.10.2020 ArgumentResolver пробрасывается снаружи.
* @since 19.11.2020 RequestStack пробрасывается снаружи.
* @since 06.03.2021 Инициация события kernel.terminate.
* @since 24.07.2021 Поддержка кэширования роутов.
*/
class InitRouter
{
Expand All @@ -39,6 +40,11 @@ class InitRouter
*/
private static $bundlesRoutes = [];

/**
* @var RouterInterface $router Router.
*/
private $router;

/**
* @var RouteCollection $routeCollection Коллекция роутов.
*/
Expand Down Expand Up @@ -82,7 +88,7 @@ class InitRouter
/**
* InitRouter constructor.
*
* @param RouteCollection $routeCollection Коллекция роутов.
* @param RouterInterface $router Роутер.
* @param ErrorControllerInterface $errorController Error controller.
* @param EventDispatcher $dispatcher Event dispatcher.
* @param ControllerResolverInterface $controllerResolver Controller resolver.
Expand All @@ -94,7 +100,7 @@ class InitRouter
* @since 19.11.2020 RequestStack пробрасывается снаружи.
*/
public function __construct(
RouteCollection $routeCollection,
RouterInterface $router,
ErrorControllerInterface $errorController,
EventDispatcher $dispatcher,
ControllerResolverInterface $controllerResolver,
Expand All @@ -107,7 +113,10 @@ public function __construct(
$this->dispatcher = $dispatcher;
$this->controllerResolver = $controllerResolver;
$this->argumentResolver = $argumentResolver;
$this->routeCollection = $routeCollection;

$this->router = $router;
$this->routeCollection = $router->getRouteCollection();

$this->requestStack = $requestStack;
$this->requestStack->push($this->request);

Expand All @@ -118,7 +127,9 @@ public function __construct(
// Роуты бандлов.
$this->mixRoutesBundles();

$matcher = new UrlMatcher($this->routeCollection, $requestContext);
$matcher = $this->router->getMatcher();
$matcher->setContext($requestContext);

// Подписчики на события по умолчанию.
$this->defaultSubscribers = [
new RouterListener($matcher, $this->requestStack),
Expand Down Expand Up @@ -289,4 +300,4 @@ private function translateHttpResponseCode(int $code) : string

return $code . ' ' . $text;
}
}
}

0 comments on commit bf04840

Please sign in to comment.