PHPackages                             musicman3/r2-d2 - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. musicman3/r2-d2

ActiveLibrary[HTTP &amp; Networking](/categories/http)

musicman3/r2-d2
===============

R2-D2 PHP Router

v1.0.5(7mo ago)0130Apache-2.0PHPPHP ^8.2

Since Oct 26Pushed 3mo agoCompare

[ Source](https://github.com/musicman3/r2-d2)[ Packagist](https://packagist.org/packages/musicman3/r2-d2)[ RSS](/packages/musicman3-r2-d2/feed)WikiDiscussions main Synced today

READMEChangelog (8)DependenciesVersions (7)Used By (0)

R2-D2 PHP AutoRouter
====================

[](#r2-d2-php-autorouter)

### Project installation:

[](#project-installation)

`composer require musicman3/r2-d2`

### System requirements:

[](#system-requirements)

- OS Unix, Linux or Windows
- Apache Web Server &gt;= 2.4 or Nginx &gt;= 1.17
- PHP &gt;= 8.3

Project R2-D2 is an automatic router that automatically creates routing for new objects added to the project, eliminating the need for constant configuration when adding new objects. It was created primarily for the eMarket project:

R2-D2 only allows you to configure the main routing branches, while R2-D2 automatically collects all object data and routes it. This eliminates the need to route each new object.

You simply add new objects (classes), and they will be automatically configured according to the configuration file structure. For autorouting to be feasible, we must adhere to the minimum placement requirements for new objects, which are also set in the configuration file.

All setup starts with placing a configuration file in a single entry point for all requests.

The structure of the configuration file. Example for 5 branches: `./, ./admin, ./install, ./uploads, ./services/jsonrpc/request`:

```
['engine' =>
 [
 'catalog' => [ // Name
    'branch' => '/', // Branch name
    'constructor' => '/view/default/catalog/constructor.php', // Path to template constructor
    'pagesPath' => '/view/default/catalog/pages', // Path to template pages
    'jsPath' => '/js/structure/catalog/pages', // Path to JS files
    'modelPath' => '/model/eMarket/Catalog', // Path to Model (objects this branch)
    'namespace' => '\eMarket\Catalog', // Path to branch Namespace
    'index_route' => 'catalog', // Default index page for this branch
  ],
  'admin' => [
    'branch' => '/admin',
    'constructor' => '/view/default/admin/constructor.php',
    'pagesPath' => '/view/default/admin/pages',
    'jsPath' => '/js/structure/admin/pages',
    'modelPath' => '/model/eMarket/Admin',
    'namespace' => '\eMarket\Admin',
    'index_route' => 'dashboard',
  ],
  'install' => [
    'branch' => '/install',
    'constructor' => '/view/default/install/constructor.php',
    'pagesPath' => '/view/default/install/pages',
    'jsPath' => '/js/structure/install/pages',
    'modelPath' => '/model/eMarket/Install',
    'namespace' => '\eMarket\Install',
    'index_route' => 'index',
  ],
  'uploads' => [
    'branch' => '/uploads',
    'constructor' => '',
    'pagesPath' => '',
    'jsPath' => '',
    'modelPath' => '/model/eMarket/Uploads',
    'namespace' => '\eMarket\Uploads',
    'index_route' => '',
  ],
  'JsonRpc' => [
    'branch' => '/services/jsonrpc/request',
    'constructor' => '',
    'pagesPath' => '',
    'jsPath' => '',
    'modelPath' => '/model/eMarket/JsonRpc',
    'namespace' => '\eMarket\JsonRpc',
    'index_route' => 'JsonRpcController',
  ],
 ]
];
```

The response array of values ​​from R2-D2 will be something like this (for url )

```
['engine' =>
    [
    'branch' => '/admin', // branch (http://localhost/admin)
    'constructor' => '/var/www/localhost/view/default/admin/constructor.php', // Path to template constructor
    'page' => '/var/www/localhost/view/default/admin/pages/orders/index.php', // Path to this template file
    'js' => '/var/www/localhost/js/structure/admin/pages/orders/js.php', // Path to JS file-constructor
    'namespace' => '\eMarket\Admin\Orders', // Object namespace
    'routing_parameter' => 'orders', // Routing path (?route=dashboard),
    'index_route' => 'dashboard', // Default index page for this branch (dashboard)
    ]
]
```

Routing uses the keyword `route`, so an example url would look like this: [https://localhost/admin/?route=my\_route\_path](https://localhost/admin/?route=my_route_path)

Example:

```
$R2D2 = new \R2D2\R2D2();

$config = [...]; // My config file
$R2D2->config($config); // Set config
$config = $R2D2->getConfig() // Get config

$route = $R2D2->route(); (Outbound routing as an array)

// For convenience, methods have been created that output data as a string.
$constructor = $R2D2->constructor(); (Path to template constructor file)
$page = $R2D2->page(); (Path to this template page file)
$js = $R2D2->js(); (Path to JS file-constructor)
$namespace = $R2D2->namespace(); (Object namespace)
$routing_parameter = $R2D2->routingParameter(); (Routing path)
$index = $R2D2->indexRoute(); (Default index page)
$middleware = $R2D2->getMiddleware(); (Get middleware list)
```

To ensure the router finds the object we need, we add a required parameter to the object variable `public static $routing_parameter`: This parameter does not have to match the name of the object, and can be arbitrary. This parameter must be unique for all objects in the specified section and must not be repeated in other objects in this section. Therefore, when creating an object, we immediately assign it the `route` parameter, aallowing us to easily add objects to the project by simply copying the file to the directory, without creating a new routing parameter for the object in the router configuration. R2-D2 will automatically construct the entire routing path.

You can also use middleware for objects. To do this, add the `$middleware` public static property with a list of middleware to use, as a string or array. This list will be displayed during routing via the `getPageObject()` method. You can then connect middleware objects according to your architecture.

Example:

```
declare(strict_types=1);

namespace myProject\Admin;

/**
 * Invoice
 *
 */
class InvoiceBlank {

    public static $routing_parameter = 'invoice';
    public static $middleware = 'Authorize, CSRF'; // or array variant ['Authorize, CSRF']

    /**
     * Constructor
     *
     */
    function __construct() {
    }
}
```

After this, the specified method will be accessible via the URL: `/admin/?route=invoice`

### PHP Standards Recommendations Used:

[](#php-standards-recommendations-used)

- PSR-1 (Basic Coding Standard)
- PSR-4 (Autoloading Standard)
- PSR-5 (PHPDoc Standard)
- PSR-12 (Extended Coding Style Guide)
- PSR-19 (PHPDoc tags)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance72

Regular maintenance activity

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

6

Last Release

238d ago

PHP version history (2 changes)v1.0.0PHP ^8.3

v1.0.3PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/36889207?v=4)[Dave](/maintainers/musicman3)[@musicman3](https://github.com/musicman3)

---

Top Contributors

[![musicman3](https://avatars.githubusercontent.com/u/36889207?v=4)](https://github.com/musicman3 "musicman3 (82 commits)")

### Embed Badge

![Health badge](/badges/musicman3-r2-d2/health.svg)

```
[![Health](https://phpackages.com/badges/musicman3-r2-d2/health.svg)](https://phpackages.com/packages/musicman3-r2-d2)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M92](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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