tanbal / php-router
A simple PHP router and backend utilities
v1.0.7
2026-11-30 19:28 UTC
Requires
- composer-plugin-api: ^2.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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.phphandles requests to/users.[id]/route.phphandles requests to/users/{id}.
The route files have access to:
$method: HTTP request method.$id: Resource ID (ornull).
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