Download the PHP package gp/router without Composer

On this page you can find all versions of the php package gp/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package router

GP Router

The GP Router is a lightweight and flexible routing solution for PHP applications. It simplifies the process of mapping HTTP requests to specific controllers or callbacks, enabling developers to build clean, organized, and scalable web applications. With its modular design, the library supports dynamic route parameters, middleware (filters) for pre- and post-processing, and API-specific routes. It is suitable for a wide range of applications, from simple websites to complex RESTful APIs.

This library focuses on:

Whether you are building a small project or a large-scale application, the GP Router library provides the tools you need to manage your application's routing efficiently.


Table of Contents


Requirements


Installation

You can install gp_router using Composer. Run the following command in your terminal:


Getting Started

After installation, you can start using the package by including the autoloader:


Features

The GP Router library provides a comprehensive set of features to handle routing efficiently in PHP applications:

These features make the GP Router library a powerful and versatile choice for managing routing in your PHP projects.


Classes

Router

Handles routing functionality.

Key Methods:


Route

Represents a single route.

Key Properties:


APIRoute

Handles API-specific routes.

Method Description Parameters
__construct() Create a necessary REST API route for the entity $rule, $apiClass, $filters =[], $name

Wrapper

Wraps multiple routes together.

Method Description Parameters
getRoutes() Retrieves the list of routes within the wrapper. None

Request

Handles HTTP request details.

Method Description Parameters
get() Retrieves all GET parameters from the request. $key - the key name (if empty fetch all), $default - default value to be returned null by default
urlParam() Retrieves all url parameters from the request. $key - the key name (if empty fetch all), $default - default value to be returned null by defaultNone
post() Retrieves all POST parameters from the request. $key - the key name (if empty fetch all), $default - default value to be returned null by defaultNone
data() Retrieves JSON request body for REST API $key - the key name (if empty fetch all), $default - default value to be returned null by defaultNone
session() Retrieves all SESSION parameters from the request. $key - the key name, $default - default value to be returned null by default
cookies() Retrieves all COOKIES parameters from the request. $key - the key name, $default - default value to be returned null by default
headers() Retrieves all header values $key - the key name (if empty fetch all), $default - default value to be returned null by default
server() Retrieves all server values $key - the key name, $default - default value to be returned null by default

Response

Handles HTTP response generation.

Method Description Parameters
setStatusCode() Sets the HTTP status code for the response. $code (int)
setBody() Sets the body content of the response. $body (string)

Filter

Represents middleware for routes.

Method Description Parameters
apply() Applies the filter logic to the given request and response. $request (Request), $response (Response)

Usage

Basic Route Definition

Using Route Class

Dynamic Parameters in Routes

In this example, {id} is a dynamic parameter. You can access it in your controller using the Request object.

Using Filters (Middleware)

Auto Resolve params

Resolving the Request & Response class

The request & response class object will be resolved and passed automatically to the controller consturctor or action method without any additional config, you can use them by adding them as param in the constructor or method, please ensure that you have added exact type for the params.

In constructor Param
In Method Param

Resolving the url params

You can also add the url param values as the part of the param in the constructor or in class method.

Resolving the Modal class

You can configure the modal class to capture the request data and it's instance will be passed as the param

Resolving the other service/model

In the same way we can resolve other service modal class instances.

Example

Initializing the Router

You can initialize the router and define routes in your application:

Using Request object

once the request object is passed as the param to the action method, we can use this method to get all the required details of the request using available methods in the request class.

Using Response object

once the response object is passed as the param to the action method, we can use this to handle the response.

The response content will be captured by

we can also change the response type by using the setType method in response class as follows

Available response types are as follows


Contributing

Contributions are welcome! If you would like to contribute to gp_validator, please follow these steps:


License

This package is licensed under the MIT License. See the LICENSE file for more information.


Contact

For questions or issues, please reach out to the development team or open a ticket.


Author



All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
gp/loader Version ^2.0.10
symfony/yaml Version ^6.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gp/router contains the following files

Loading the files please wait ...