coccoto / dotrouter
Installs: 32
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/coccoto/dotrouter
Requires
- php: ^7.4
This package is auto-updated.
Last update: 2025-10-29 02:23:51 UTC
README
It does a very simple routing.
Prerequisites
- PHP 7.4
Installation
$ composer require coccoto/dotrouter
Usage
require_once 'vendor/autoload.php'; $map = [ '/' => [ 'controller' => 'IndexController', 'method' => 'indexMethod', ], ]; $namespace = 'app\\controllers\\'; $dotRouter = new coccoto\dotrouter\DotRouter(); $dotRouter->push($map, $namespace);
Set the namespace.
$namespace = 'app\\controllers\\';
Create a routing map.
Path parameters can be used by preceding them with a colon.
$map = [ '/' => [ 'controller' => 'IndexController', 'method' => 'indexMethod', ], '/animal/page/:id' => [ 'controller' => 'CatController', 'method' => 'foodMethod', ], ];
Create a class to load.
PathParameter is placed in the property because it is inserted into the constructor argument of the loading class.
- app/controllers/FooController.php
namespace app\controllers; class CatController { public array $pathParameter; public function __construct(array $pathParameter) { $this->pathParameter = $pathParameter; } public function foodMethod() { echo $this->pathParameter['id']; } }
Perform routing.
There are no more features and it's easy. Then start it.
~~~ $dotRouter = new coccoto\dotrouter\DotRouter(); $dotRouter->push($map, $namespace); $dotRouter->run();
License
MIT License