Download the PHP package roy404/routes without Composer
On this page you can find all versions of the php package roy404/routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download roy404/routes
More information about roy404/routes
Files in roy404/routes
Package routes
Short Description A routing library that provides an intuitive, object-oriented way to define and manage HTTP routes in your PHP application, supporting route grouping, middleware, and custom route handling.
License MIT
Informations about the package routes
ROUTES - HTTP Handler
Install the bundle using Composer:
Route Feature Documentation
The route feature allows you to manage HTTP requests easily in your application. To set up and use this feature, follow the instructions below:
Available Methods
Http Methods
static get(string $uri, array $action)
: Defines a GET route.static post(string $uri, array $action)
: Defines a POST route.static put(string $uri, array $action)
: Defines a PUT route.static patch(string $uri, array $action)
: Defines a PATCH route.static delete(string $uri, array $action)
: Defines a DELETE route.
Route Configuration
static group(array $attributes, \Closure $action)
: Groups routes with shared configurations and middleware.static controller(string $className)
: Registers a controller to handle specific routes.static middleware(string|array $action)
: Registers middleware for a specific route.static prefix(string $prefix)
: Adds a URI prefix to a set of routes.static name(string $name)
: Assigns a name to a route for easy referencing.static domain(string|array $domain)
: Restricts a route to a specific domain (for multi-domain setups).
Example Route Configuration Methods
-
Group
static group(array $attributes, \Closure $action)
.- Description Registers a group of routes that share common configurations or middleware. This method enhances route organization and reusability by allowing you to apply settings or middleware to multiple routes at once.
-
Usage:
- Parameters
$attributes
: An array of configuration options for the group (e.g., middleware, prefix, etc.).$action
: A closure that contains all routes to be grouped.
-
Controller
static controller(string $className)
- Description Registers a controller class that will handle requests for specific routes.
-
Usage
- Parameters
$className
: The class name of the controller to handle the route.
-
Middleware:
static middleware(string|array $action)
- Description Registers middleware for a specific route. Middleware can perform various tasks, such as authentication, logging, and security checks.
-
Usage
- Parameters:
$action
: The middleware action or array of middleware to apply to the route.
-
Prefix
static prefix(string $prefix)
- Description Adds a prefix to the URI of the route, which is useful for route grouping (e.g., adding /admin for admin routes).
-
Usage
- Parameters
$prefix
: Append the prefix before the URI.
-
Name
static name(string $name)
- Description Assigns a name to a route. This makes it easier to refer to the route later in your code, especially when generating URLs.
-
Usage
- Parameters
$name
: The name to assign to the route.
-
Domain
static domain(string $domain)
- Description Restricts a route to a specific domain, useful for multi-domain applications (e.g., admin.example.com or api.example.com).
-
Usage
- Parameters
$domain
: The domain to associate with the route.
Getting Started
-
Configuring Routes: To configure and use the routing system, you need to call the Route::configure() function at the start of your application (usually in your main entry point file, like index.php or app.php).
- Using the Routes Feature After configuring your routes as described in Step 1, you can now start using the route feature to register your routes and define actions that should be taken when those routes are accessed.
In the example below, we use the Route::get() method to register a route for the homepage (/), which will echo Hello World! when visited.
How to run a single file in application?
To set up routing in your application, ensure that your web server is configured to use URL rewriting. This allows your application to route requests properly. Below are the configurations for both Apache or Nginx servers.
Apache
If you are using an Apache web server, add the following code to your .htaccess
file located in your application's root directory:
Nginx
For Nginx, you will need to configure the server block in your Nginx configuration file (usually located in /etc/nginx/sites-available/default or a similar path). Add the following rules to handle URL rewriting: