Search by

tanbal / php-router

Tanbal8

A simple PHP router and backend utilities

Package info

github.com/Tanbal8/php-router

Type:composer-plugin

pkg:composer/tanbal/php-router

Statistics

Installs: 17

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.7 2026-11-30 19:28 UTC

This package is auto-updated.

Last update: 2026-11-30 19:28:31 UTC


README

A lightweight PHP router and backend scaffolding installer for PHP projects.

Installation

Install the package using Composer:

composer require tanbal/php-router

After installation, the package automatically creates a backend directory in your project.

Existing files will not be overwritten.

Generated Structure

backend/
├── router.php
├── utils/
│   ├── dataManager.php
│   ├── nestedDataManager.php
│   └── response.php
├── routes/
└── data/

Running the PHP Server

From your project root, run:

php -S localhost:8000 backend/router.php

Creating Routes

Create a directory for each resource inside backend/routes/.

For example:

backend/
└── routes/
    └── users/
        ├── route.php
        └── [id]/
            └── route.php
  • route.php handles requests to /users.
  • [id]/route.php handles requests to /users/{id}.

The route files have access to:

  • $method: HTTP request method.
  • $id: Resource ID (or null).

Utilities

JSON

The JSON class provides methods for working with JSON files:

  • exists()
  • load()
  • save($data)
  • remove($id)

Response

The sendError() function sends a JSON error response and terminates execution.

sendError('Not found', 404);

Requirements

  • PHP 8.0+
  • Composer 2

License

MIT