PHP Classes

How to Use a PHP Router Package to Process HTTP Requests Using Injected Dependency Classes with the Package Attributes: Route requests based on the current URL and method

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-07-05 (Less than 1 hour ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
attributes 1.0BSD License8.1HTTP, Language, Design Patterns, PHP 8
Description 

Author

This package can route requests based on the current URL and method.

It provides a router class that checks the current HTTP request and method to look in a list of registered routes to determine what is the action that will be performed to process the current requests.

The package comes with a script that uses PHP reflection to determine which HTTP URL patterns each registered class will handle and adds to the list of supported routes.

The router class will execute the requested action by calling a class that was previously registered to process requests that match patterns of server URLs and HTTP methods.

Picture of Vitalij Mik
  Performance   Level  
Name: Vitalij Mik <contact>
Classes: 8 packages by
Country: Germany Germany
Age: 38
All time rank: 3478195 in Germany Germany
Week rank: 195 Up8 in Germany Germany Up
Innovation award
Innovation award
Nominee: 5x

Instructions

Example

<?php
error_reporting
(E_ALL);

require_once
__DIR__ . '/Router.php';
require_once
__DIR__ . '/Request.php';
require_once
__DIR__ . '/RouteNotFoundException.php';
require_once
__DIR__ . '/IndexController.php';
require_once
__DIR__ . '/ProfileController.php';
require_once
__DIR__.'/Route.php';

$container = require_once __DIR__.'/diContainer.php';

$router = $container[Router::class]();

$request = Request::createFromGlobal();

try{
    echo
$router->handle($request);
}catch (
RouteNotFoundException $exception){
    echo
$exception->getMessage();
}


  Files folder image Files (9)  
File Role Description
Accessible without login Plain text file .htaccess Data Cofiguration file
Accessible without login Plain text file diContainer.php Conf. Route configuration script
Accessible without login Plain text file index.php Example Example script
Plain text file IndexController.php Class Class source
Plain text file ProfileController.php Class Class source
Plain text file Request.php Class Class source
Plain text file Route.php Class Class source
Plain text file RouteNotFoundException.php Class Class source
Plain text file Router.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0