Download the PHP package devceliojr/simplerouter without Composer
On this page you can find all versions of the php package devceliojr/simplerouter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devceliojr/simplerouter
More information about devceliojr/simplerouter
Files in devceliojr/simplerouter
Package simplerouter
Short Description A lightweight, easy-to-use PHP router for building web applications.
License MIT
Informations about the package simplerouter
SimpleRouter
SimpleRouter is a lightweight and easy-to-use PHP router for building web applications.
Features
- Simple and intuitive syntax
- Support for dynamic routes with URL parameters
- Support for HTTP methods (GET, POST, PUT, PATCH, and DELETE)
- Easily customizable
- Lightweight and fast
Requirements
- PHP >= 8.1
Installation
You can install SimpleRouter using Composer:
Usage
Here's a simple example of how to use SimpleRouter:
This will create a new router, define a route for the homepage, and run the router.
You can also define dynamic routes with URL parameters:
In this example, any URL that matches the pattern /users/{id:number}
will be handled by the callback function, which will receive the value of id
as an argument.
The supported parameter types are:
number
: accepts only numeric valuesletter
: accepts only alphabetical charactersalpha
: accepts alphanumeric charactersany
: accepts any character
You can use HTTP methods other than GET by calling the corresponding function on the router:
In this example, the callback function will be executed when a POST request is made to the /users
URL.
You can also use HTTP verbs with dynamic routes:
In this example, the callback function will be executed when a PUT request is made to a URL that matches the pattern /users/{id:number}
.
For more complex applications, you can use nested routes and subgroups:
In this example, the HomeController
class handles the root URL, while the AdminController
class handles URLs under the /admin
prefix. The financial
method of the AdminController
class is accessed by navigating to /admin/financial
.
For more information on how to use SimpleRouter, please refer to the documentation.
Contributing
Contributions are welcome! If you'd like to contribute to SimpleRouter, please open an issue or pull request on GitHub.
License
SimpleRouter is open-source software licensed under the MIT license.