Download the PHP package viragrajput/router without Composer
On this page you can find all versions of the php package viragrajput/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download viragrajput/router
More information about viragrajput/router
Files in viragrajput/router
Package router
Short Description A custom router package for handling HTTP routing in PHP applications
License MIT
Informations about the package router
Virag Router
ViragRouter is a lightweight PHP router package that allows you to easily define and handle routes in your PHP applications.
With ViragRouter, you're equipped with a robust suite of capabilities essential for efficient route handling: seamless route definition, dynamic parameter management, route grouping with middleware support, named routes for URL generation, and more. Its lightweight architecture guarantees minimal overhead, delivering optimal performance without sacrificing functionality.
Note :
ViragRouter is actively developed and continuously enhanced. While it's currently in its developmental phase and may contain occasional bugs, so it is not recommended for production use at this time. We appreciate your patience and understanding as i work towards delivering a stable and reliable product. However, you can safely use it for learning purposes, exploring its features, and exploring advanced routing concepts in PHP.
Installation
You can install ViragRouter via Composer:
Run local PHP Server
Usage
Creating Routes
You can define routes using the Route
class provided by ViragRouter. Here's an example of how to define a route:
Route Parameters
You can define route parameters by enclosing them in curly braces {}
. These parameters will be passed to your route handler. Here's an example:
Route Groups
You can group routes and apply common attributes using the group
method. Here's an example:
Named Routes
You can name your routes using the name
method. Named routes allow you to generate URLs based on the route name. Here's an example:
Middleware
You can apply middleware to routes using the middleware
method. Middleware allows you to filter HTTP requests entering your application. Here's an example:
Generating URLs
You can generate URLs for named routes using the generateUrl
method. Here's an example:
Handling Requests
You can handle incoming requests using the dispatch method of the Router class. Here's an example:
How To Use This Package in Your Custom PHP Project
Certainly! Below is an example of how you can integrate the ViragRouter package into your custom PHP Project:
Step 1: Install ViragRouter via Composer
First, install the ViragRouter package via Composer:
Step 2: Define Routes in Your Custom Project
In your custom Project, you'll need to define routes using the ViragRouter Route
class. Here's an example of how you can define routes in your Project:
Step 3: Create a Router Instance and Handle Requests
In your Project entry point (e.g., index.php
), create a router instance and handle incoming requests:
Step 4: Handle Requests in Your Custom Project
In your custom Project, ensure that you have logic to handle requests and invoke the appropriate route handlers based on the incoming requests.
Step 6: Additional Configuration (Optional)
Depending on your custom Project's architecture and requirements, you may need to configure additional features such as middleware, route groups, named routes, etc., provided by ViragRouter.
By following these steps, you should be able to integrate the ViragRouter package into your custom PHP project and define and handle routes effectively. Adjustments may be needed based on your project's specific requirements and architecture.
License
This package is open-source software licensed under the MIT license.