-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
152 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Prokl\BitrixSymfonyRouterBundle\Services\Agnostic; | ||
|
||
use Prokl\BitrixSymfonyRouterBundle\Services\Router\InitRouter; | ||
use Prokl\WpSymfonyRouterBundle\Services\Agnostic\Contracts\RouterInitializerInterface; | ||
|
||
/** | ||
* Class BitrixInitializerRouter | ||
* @package Prokl\BitrixSymfonyRouterBundle\Services\Agnostic | ||
* | ||
* @since 24.07.2021 | ||
*/ | ||
class BitrixInitializerRouter implements RouterInitializerInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function init(InitRouter $router) | ||
{ | ||
AddEventHandler('main', 'OnProlog', [$router, 'handle']); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Services/Agnostic/Contracts/RouterInitializerInterface.php
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,23 @@ | ||
<?php | ||
|
||
namespace Prokl\WpSymfonyRouterBundle\Services\Agnostic\Contracts; | ||
|
||
use Prokl\BitrixSymfonyRouterBundle\Services\Router\InitRouter; | ||
|
||
/** | ||
* Interface Prokl\WpSymfonyRouterBundle\Services\Agnostic\Contracts | ||
* @package Local\Bitrix | ||
* | ||
* @since 24.07.2021 | ||
*/ | ||
interface RouterInitializerInterface | ||
{ | ||
/** | ||
* Инициализация роутера. | ||
* | ||
* @param InitRouter $router Инициализированный роутер. | ||
* | ||
* @return mixed | ||
*/ | ||
public function init(InitRouter $router); | ||
} |
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,72 @@ | ||
<?php | ||
|
||
namespace Prokl\BitrixSymfonyRouterBundle\Services\Agnostic; | ||
|
||
use Prokl\BitrixSymfonyRouterBundle\Services\Controllers\ErrorJsonController; | ||
use Prokl\BitrixSymfonyRouterBundle\Services\Router\InitRouter; | ||
use Prokl\WpSymfonyRouterBundle\Services\Agnostic\Contracts\RouterInitializerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver; | ||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver; | ||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver; | ||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestValueResolver; | ||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\SessionValueResolver; | ||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\VariadicValueResolver; | ||
use Symfony\Component\HttpKernel\Controller\ControllerResolver; | ||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Component\Serializer\Encoder\JsonEncoder; | ||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | ||
use Symfony\Component\Serializer\Serializer; | ||
|
||
/** | ||
* Class Router | ||
* @package Prokl\BitrixSymfonyRouterBundle\Services\Agnostic | ||
* | ||
* @since 24.07.2021 | ||
*/ | ||
class Router | ||
{ | ||
/** | ||
* @var InitRouter $router Инициализированный экземпляр роутера. | ||
*/ | ||
private $router; | ||
|
||
/** | ||
* AgnosticRouter constructor. | ||
* | ||
* @param RouterInterface $router Инициализированный экземпляр роутера. | ||
* @param RouterInitializerInterface $routerInitializer Инициализатор роутера. | ||
*/ | ||
public function __construct( | ||
RouterInterface $router, | ||
RouterInitializerInterface $routerInitializer | ||
) { | ||
$this->router = new InitRouter( | ||
$router, | ||
new ErrorJsonController( | ||
new Serializer( | ||
[new ObjectNormalizer], | ||
[new JsonEncoder] | ||
|
||
) | ||
), | ||
new EventDispatcher(), | ||
new ControllerResolver(), | ||
new ArgumentResolver( | ||
new ArgumentMetadataFactory(), | ||
[ | ||
new RequestAttributeValueResolver(), | ||
new RequestValueResolver(), | ||
new SessionValueResolver(), | ||
new DefaultValueResolver(), | ||
new VariadicValueResolver(), | ||
] | ||
), | ||
new RequestStack() | ||
); | ||
|
||
$routerInitializer->init($this->router); | ||
} | ||
} |
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