PHPackages                             r2-packages/framework - 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. r2-packages/framework

ActiveProject[Framework](/categories/framework)

r2-packages/framework
=====================

A simple reusable PHP package

v1.0.51(1w ago)0169↓50%MITPHPPHP &gt;=7.4

Since Apr 28Pushed 2d agoCompare

[ Source](https://github.com/easymagic/r2-packages)[ Packagist](https://packagist.org/packages/r2-packages/framework)[ RSS](/packages/r2-packages-framework/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (52)Used By (0)

R2 Packages Framework
=====================

[](#r2-packages-framework)

[![Latest Stable Version](https://camo.githubusercontent.com/bcba06d98f24f3bd26225a23da5f2eae3f52529bf0d597d4a527e46b8f1fa8f2/68747470733a2f2f706f7365722e707567782e6f72672f72322d7061636b616765732f6672616d65776f726b2f762f737461626c65)](https://packagist.org/packages/r2-packages/framework)[![Total Downloads](https://camo.githubusercontent.com/c146929c94610a9e931258923f960be439edc15c6573919cdd748a1e9fd0dcb6/68747470733a2f2f706f7365722e707567782e6f72672f72322d7061636b616765732f6672616d65776f726b2f646f776e6c6f616473)](https://packagist.org/packages/r2-packages/framework)[![License](https://camo.githubusercontent.com/d4c69873e25155ef51814b070fbc9f8d06676668233dda0d7ee65e37394362dd/68747470733a2f2f706f7365722e707567782e6f72672f72322d7061636b616765732f6672616d65776f726b2f6c6963656e7365)](https://packagist.org/packages/r2-packages/framework)

A small reusable PHP routing framework package.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Composer

Installation
------------

[](#installation)

Install the package with Composer:

```
composer require r2-packages/framework
```

If you are using this package locally, require Composer's autoloader:

```
require __DIR__ . '/vendor/autoload.php';
```

Basic Usage
-----------

[](#basic-usage)

Create a router, register routes, and run the router with the current request path and method.

```
use R2Packages\Framework\Route;

$route = new Route();

$route->get('/', function ($request) {
    echo 'Welcome';
});

$route->get('/users/{id}', function ($request) {
    echo 'User ID: ' . $request['id'];
});

$route->post('/users', [UserController::class, 'store']);
$route->delete('/users/{id}', [UserController::class, 'delete']);

$route->run($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
```

Controller Routes
-----------------

[](#controller-routes)

Controller routes should be registered as an array containing the class name and method name.

```
$route->get('/users/{id}', [UserController::class, 'show']);
```

The controller is instantiated with the request array, and the matched method receives the request array.

```
class UserController
{
    private $request;

    public function __construct($request)
    {
        $this->request = $request;
    }

    public function show($request)
    {
        echo 'User ID: ' . $request['id'];
    }
}
```

Route Prefixes
--------------

[](#route-prefixes)

Use `prefix()` to group routes under a shared path.

```
$route->prefix('api', function ($route) {
    $route->get('/users', [UserController::class, 'index']);
    $route->get('/users/{id}', [UserController::class, 'show']);
});
```

The example above registers:

- `api/users`
- `api/users/{id}`

Middleware
----------

[](#middleware)

Use `globalMiddleware()` to apply middleware classes to a group of routes.

```
$route->globalMiddleware([AuthMiddleware::class], function ($route) {
    $route->get('/dashboard', [DashboardController::class, 'index']);
});
```

Middleware classes must provide a `handle()` method.

```
class AuthMiddleware
{
    public function handle($request)
    {
        if (empty($request['Authorization'])) {
            R2Packages\Framework\Utils::jsonResponse([
                'success' => false,
                'message' => 'Unauthorized',
            ], 401);
        }
    }
}
```

Named Routes
------------

[](#named-routes)

Use `name()` to assign a name to the most recently registered route, then generate the route path with `getRouteByName()`.

```
$route->get('/users/{id}', [UserController::class, 'show'])->name('users.show');

$path = $route->getRouteByName('users.show', [
    'id' => 10,
]);

echo $path; // users/10
```

Helpers
-------

[](#helpers)

The `Utils` class provides helper methods for common responses and formatting.

```
use R2Packages\Framework\Utils;

Utils::jsonResponse([
    'success' => true,
    'message' => 'Created successfully',
]);

Utils::dd($data);

$snakeCase = Utils::camelCaseToSnakeCase('createdAt');
```

License
-------

[](#license)

MIT

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance99

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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 ~1 days

Total

51

Last Release

10d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c2d53b44dde4b89393c8b361e41e94cb1b438ab1f7cde4780fdd82a4e29a706?d=identicon)[easymagic](/maintainers/easymagic)

---

Top Contributors

[![easymagic](https://avatars.githubusercontent.com/u/2946882?v=4)](https://github.com/easymagic "easymagic (46 commits)")

### Embed Badge

![Health badge](/badges/r2-packages-framework/health.svg)

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

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k104.3M822](/packages/laravel-socialite)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k38.6M289](/packages/laravel-dusk)[pinguo/php-msf

Pinguo Micro Service Framework For PHP

1.7k4.2k](/packages/pinguo-php-msf)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)

PHPackages © 2026

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