PHPackages                             beta/bx.router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. beta/bx.router

ActiveBitrix-module[Framework](/categories/framework)

beta/bx.router
==============

Routing for Bitrix app

1.11.2(1y ago)103.1k↑47.8%6[1 issues](https://github.com/beta-eto-code/bx.router/issues)MITPHPPHP &gt;=7.2

Since Apr 3Pushed 1y ago3 watchersCompare

[ Source](https://github.com/beta-eto-code/bx.router)[ Packagist](https://packagist.org/packages/beta/bx.router)[ RSS](/packages/beta-bxrouter/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (7)Versions (45)Used By (0)

Роутер для bitrix (PSR-7, PSR-15, PSR-17 implementation)
========================================================

[](#роутер-для-bitrix-psr-7-psr-15-psr-17-implementation)

### Установка

[](#установка)

```
composer require beta/bx.router

```

### Пример инициализации приложения:

[](#пример-инициализации-приложения)

```
use BX\Router\RestApplication;
use BX\Router\Middlewares\Logger;
use BX\Router\Middlewares\UseBitrixCookies;
use BX\Router\Middlewares\HttpException;

$app = new RestApplication();
$router = $app->getRouter();

$defaultMiddleware = new UseBitrixCookies(); // подставляет куки из bitrix в запрос
$defaultMiddleware->addMiddleware(new HttpException($app->getFactory())); // добавляем обработчик ошибок

$app->registerMiddleware($defaultMiddleware); // регистрируем цепочку middleware

$app->setResponseHandler(new CustomResponseHandler);    // Устанавливаем собственный обработчик ответа
$app->setService('jwt', new UserTokenService());        // Регистрируем внешний сервис для доступа из контроллера

$logger = new Logger();
$router->get('/api/v1/catalog/', new CatalogController)->registerMiddleware($logger);
$router->get('/api/v1/some/{test}/', new SomeController)->registerMiddleware($logger);
$router->get('/api/v1/pages/main/', new MainPageConroller)
    ->useCache(3600, 'main_page')       // Кешируем ответ, ключ не обязателен, работает только c GET методами
    ->registerMiddleware($logger);
$router->default(new DefaultController) // Контроллер по-умолчанию
    ->registerMiddleware($logger);

$app->run();
```

### Пример контроллера c вызовом компонента:

[](#пример-контроллера-c-вызовом-компонента)

```
use BX\Router\Interfaces\BitrixServiceInterface;
use BX\Router\Interfaces\AppFactoryInterface;
use BX\Router\Interfaces\ContainerGetterInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use BX\Router\BaseController;

class CatalogController extends BaseController
{
    /**
    * @var BitrixServiceInterface
     */
    protected $bitrixService;
    /**
    * @var AppFactoryInterface
     */
    protected $appFactory;
    /**
    * @var ContainerGetterInterface
     */
    protected $containerGetter;

    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $component = $this->appFactory->createComponentWrapper('api:catlog.list'); // Создаем обертку компонента
        $component->setContainer($this->containerGetter);
        $component->setAppFactory($this->appFactory);
        $component->setBitrixService($this->bitrixService);

        return $component->handle($request);    // Возвращаем ответ с данными из массива $arResult
    }
}
```

### Пример простого контроллера:

[](#пример-простого-контроллера)

```
use BX\Router\Interfaces\BitrixServiceInterface;
use BX\Router\Interfaces\AppFactoryInterface;
use BX\Router\Interfaces\ContainerGetterInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use BX\Router\BaseController;

class MainPageConroller extends BaseController
{
    /**
    * @var BitrixServiceInterface
     */
    protected $bitrixService;
    /**
    * @var AppFactoryInterface
     */
    protected $appFactory;
    /**
    * @var ContainerGetterInterface
     */
    protected $containerGetter;

    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $this->containerGetter->has('jwt'); // проверяем внешний сервис
        $jwt = $this->containerGetter->get('jwt');
        if (!($jwt instanceof UserTokenService)) {
            throw new \Exception('Что-то пошло не так...');
        }

        $request->getAttribute('test'); // атрибут из адресной строки
        $request->getAttributes();      // список атрибутов из адресной строки

        $jwtToken = trim(str_replace('Bearer', $request->getHeader('Authorization')));
        $userContext = $jwt->getUserContext($jwtToken);
        $user = $userContext->getUser();

        $data = $user->toArray();
        $response = $this->appFactory->createResponse();
        $response->getBody()->write(json_encode($data));

        return $response;
    }
}
```

### Пример контроллера с выборкой атрибутов из адресной строки:

[](#пример-контроллера-с-выборкой-атрибутов-из-адресной-строки)

```
use BX\Router\Interfaces\BitrixServiceInterface;
use BX\Router\Interfaces\AppFactoryInterface;
use BX\Router\Interfaces\ContainerGetterInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use BX\Router\BaseController;

class SomeController extends BaseController
{
    /**
    * @var BitrixServiceInterface
     */
    protected $bitrixService;
    /**
    * @var AppFactoryInterface
     */
    protected $appFactory;
    /**
    * @var ContainerGetterInterface
     */
    protected $containerGetter;

    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $testAttribute = $request->getAttribute('test'); // атрибут из адресной строки
        $attributes = $request->getAttributes();         // список атрибутов из адресной строки

        $response = $this->appFactory->createResponse();
        $response->getBody()->write(json_encode($attributes));

        return $response;
    }
}
```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 89% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~91 days

Total

43

Last Release

577d ago

Major Versions

0.2.1 → 1.0.02021-07-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/c75fd54c926c6b835a6b6cd92514d60d55a285d35847b9f22aefcc7ad5ef9ae7?d=identicon)[nnagornyy](/maintainers/nnagornyy)

---

Top Contributors

[![alex19pov31](https://avatars.githubusercontent.com/u/786683?v=4)](https://github.com/alex19pov31 "alex19pov31 (65 commits)")[![nnagornyy](https://avatars.githubusercontent.com/u/20841535?v=4)](https://github.com/nnagornyy "nnagornyy (6 commits)")[![KotovaZ](https://avatars.githubusercontent.com/u/31381189?v=4)](https://github.com/KotovaZ "KotovaZ (1 commits)")[![kys](https://avatars.githubusercontent.com/u/760417?v=4)](https://github.com/kys "kys (1 commits)")

### Embed Badge

![Health badge](/badges/beta-bxrouter/health.svg)

```
[![Health](https://phpackages.com/badges/beta-bxrouter/health.svg)](https://phpackages.com/packages/beta-bxrouter)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[cakephp/authentication

Authentication plugin for CakePHP

1214.1M106](/packages/cakephp-authentication)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
