| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Effectra PHP Router is a lightweight and flexible routing library for PHP applications. It provides a convenient way to define routes and dispatch incoming requests to the appropriate controllers or callbacks.
You can install the Effectra PHP Router library via Composer. Run the following command in your project directory:
composer require effectra/router
To get started with Effectra PHP Router, follow these steps:
require_once 'vendor/autoload.php';use Effectra\Router\Route;
use Effectra\Router\RouteGroup;
use Effectra\Http\Foundation\RequestFoundation;
use Effectra\Http\Message\Response;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;//pass response class to the router
$response = new Response();
$route = new Route($response);$route->get('/home', function () {
return 'Welcome to the home page!';
});
$route->post('/contact', 'StaticController@login');
$router->get('/', [HomeController::class, 'index']);
$router->get('/users/', [UserController::class, 'index']);
$router->post('/signin', function (RequestInterface $request, ResponseInterface $response) {
return $response->json([
'message' => 'hello world'
]);
});
$route->crud('/report', ReportController::class, 'read|readOne|create|delete|deleteAll|search');
$route->auth('/auth/', AuthController::class);
$route->group('/file/upload/', UploadController::class, function(RouteGroup $router){
$router->post('audio','createAudio');
$router->post('video','createVideo');
});$request = RequestFoundation::createFromGlobals();
$route->dispatch($request);The Route class provides several methods to define routes:
The Route class supports middleware for route groups. You can use the middleware method to add middleware to a group of routes:
$router->get('/users/{id}', [UserController::class, 'show'])->middleware(new AuthMiddleware());The Route class provides methods to handle 404 Not Found and 500 Internal Server Error responses:
$route->setNotFound(function () {
// Handle 404 Not Found response
});
$route->setInternalServerError(function () {
// Handle 500 Internal Server Error response
});Contributions to the Effectra PHP Router library are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
The Effectra PHP Router library is open-source software licensed under the MIT license.
| Back | FazBrowse Home | New Git URL |