PHPackages                             simp/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. simp/router

ActiveLibrary

simp/router
===========

Library that provide the routing process

v1.1.6(2w ago)098MITPHP

Since Feb 4Pushed 2w ago1 watchersCompare

[ Source](https://github.com/CHANCENY/router)[ Packagist](https://packagist.org/packages/simp/router)[ RSS](/packages/simp-router/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (8)Versions (17)Used By (0)

Router Library
==============

[](#router-library)

Overview
--------

[](#overview)

This is a simple PHP routing library that allows defining and handling routes easily. It supports various HTTP methods, dynamic parameters, and optional data type specifications.

Features
--------

[](#features)

- Supports GET, POST, PUT, DELETE requests
- Allows route parameters with type enforcement (int, float, bool, double)
- Handles dynamic routing with class-based controllers
- JSON-based response handling

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

[](#installation)

1. Clone the repository or download the source code.
2. Install dependencies using Composer: ```
    composer require simp/router
    ```

Usage
-----

[](#usage)

### Defining Routes

[](#defining-routes)

Routes are defined in `index.php` using the `Route` class. Example:

```
equire_once "vendor/autoload.php";

use Simp\Router\Route;

require_once "Example.php";
require_once "Help.php";
require_once "ExampleMiddleware.php";

// Make the middleware_register_file where you can declare middlewares.
$middleware_register_file = __DIR__ . '/middleware.yml';

$route = new Route($middleware_register_file);

$route->get("/","index",Example::class);

$route->get("/api/help-document/[help_title:".Help::class."]","api_help",Example::class . "@help");

$route->get("/api/posts","posts",Example::class . "@posts");

$route->get("/api/post/[id:int]","post",Example::class. "@post");

$route->post("/api/post","post_create",Example::class . "@post_create");

$route->delete("/api/post/[id:int]","post_delete",Example::class . "@post_delete");

$route->put("/api/post/[id:int]","post_update",Example::class);

$route->get("/api/posts/search/[title]","post_search",Example::class);

$route->get("/api/post/[id:int]/image","post_image",Example::class);
```

### Handling Requests

[](#handling-requests)

Route handlers should extend `RouteEntryController` and implement an `entry` method to handle requests. Example:

```
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class Example
{

    private array $posts;

    public function __construct()
    {
        $this->posts = json_decode(file_get_contents(__DIR__ . '/posts.json'), true);
    }

    function index(...$args): object
    {
        return new Response("Post Simple Api");
    }

    function posts(...$args): object
    {
        return new JsonResponse($this->posts,200, ['Content-Type' => 'application/json']);
    }

    function post(...$args): object
    {
        $post = array_filter($this->posts, fn ($post) => $post['id'] === $args['request']->query->get('id'));
        return new JsonResponse(array_values($post),200, ['Content-Type' => 'application/json']);
    }

    function post_create(...$args): object
    {
        $data = json_decode($args['request']->payload->getContent(), true);
        $data['id'] = time();
        $this->posts[] = $data;
        file_put_contents(__DIR__ . '/posts.json', json_encode($this->posts, JSON_PRETTY_PRINT));
        return new JsonResponse($data,200, ['Content-Type' => 'application/json']);
    }

    function post_delete(...$args): object
    {
        $id = $args['request']->query->get('id');
        $this->posts = array_filter($this->posts, fn ($post) => $post['id'] !== $id);
        file_put_contents(__DIR__ . '/posts.json', json_encode($this->posts, JSON_PRETTY_PRINT));
        return new JsonResponse(['status'=>200, 'msg'=>'deleted post'],200, ['Content-Type' => 'application/json']);
    }

    function post_update(...$args): object
    {
        $data = json_decode($args['request']->payload->getContent(), true);
        $id = $args['request']->query->get('id');

        $updated = false;
        $posts = array_map(function ($post) use ($data, $id, &$updated,&$count) {
            if ($post['id'] === $id) {
                foreach ($post as $key => $value) {
                    if (!empty($data[$key])) {
                        $post[$key] = $data[$key];
                        $updated = true;
                    }
                }
            }

            return $post;
        },$this->posts);

        if(!$updated) {
            $post = array_filter($posts, fn ($post) => $post['id'] === $id);
            if ($post) {
                $index = array_keys($post);
                $index = $index[0];
                $new_data = array_merge(reset($post), $data);
                $posts[$index] = $new_data;
                $updated = true;
            }

        }

        $this->posts = array_values($posts);
        file_put_contents(__DIR__ . '/posts.json', json_encode($this->posts, JSON_PRETTY_PRINT));
        return new JsonResponse(['status'=>$updated],200, ['Content-Type' => 'application/json']);
    }

    function post_search(...$args): object
    {
        $matches = [];
        $title = $args['request']->query->get('title');
        foreach ($this->posts as $post) {
            $post_title = $post['title'];
            $percent = 0;

            similar_text(strtolower($post_title), strtolower($title), $percent);
            if ($percent > 50) {
                $matches[] = $post;

            }
        }
        return new JsonResponse($matches,200, ['Content-Type' => 'application/json']);
    }

    function api_help(...$args): object
    {
        return new Response($args['request']->query->get('help_title')->content , 200);
    }

    function post_image(...$args): object
    {
        $id = $args['request']->query->get('id');
        $post_found = array_filter($this->posts, fn ($post) => $post['id'] === $id);
        if ($post = reset($post_found)) {
            $image = $post['image'] ?? null;
            if ($image) {
                $content = file_get_contents($image);
                $base64 = "data:application/octet-stream;base64," . base64_encode($content);
                return new JsonResponse(['image'=>$base64],200, ['Content-Type' => "application/json"]);
            }
        }
        return new Response(null,404, ['Content-Type' => 'application/json']);
    }
}
```

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

[](#requirements)

- PHP 8.0+
- Composer

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance96

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70% 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 ~26 days

Recently: every ~41 days

Total

16

Last Release

19d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6097a3277a85cf902ab5d617af1515359091563d1d288dd969e59ca50646a782?d=identicon)[Chance007](/maintainers/Chance007)

---

Top Contributors

[![CHANCENY](https://avatars.githubusercontent.com/u/96126430?v=4)](https://github.com/CHANCENY "CHANCENY (7 commits)")[![maybuck](https://avatars.githubusercontent.com/u/12176638?v=4)](https://github.com/maybuck "maybuck (3 commits)")

### Embed Badge

![Health badge](/badges/simp-router/health.svg)

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[typo3/cms

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

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

Drupal is an open source content management platform powering millions of websites and applications.

19461.2M1.1k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6938.6M290](/packages/drupal-core-recommended)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

605.0M332](/packages/shopware-core)[typo3/cms-core

TYPO3 CMS Core

3212.0M3.3k](/packages/typo3-cms-core)

PHPackages © 2026

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