jcain / router-ss
An HTTP router micro-library for PHP 7.4+.
Requires
- php: ^7.2
- jcain/asserts-lr: ^0.0.0
README
Router SS is an HTTP router micro-library for PHP 7.2+.
Installation
Router SS requires PHP 7.2 or greater.
composer require jcain/router-ss
Usage
Create a router.php
file with the following contents:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use \JCain\Router\SS\Requests\BasicRequest;
use \JCain\Router\SS\Requests\StringEvaluator;
use \JCain\Router\SS\Routers\BasicRouter;
$request = new BasicRequest([
'variables' => BasicRequest::parseRequestInfo(),
]);
$router = new BasicRouter([ 'outputExceptions' => true ]);
$router->route($request, function ($r) {
$path = new StringEvaluator($r, 'path');
$path->equals('', function ($r) {
echo '<a href="hello-world">Click here to greet the world<a><br />';
echo 'or<br />';
echo '<a href="hello-universe">Click here to greet the universe<a><br />';
});
$path->matches('^hello-(?<name>[^/]+)$', function ($r) {
$name = ucwords(urldecode($r->getVariable('name')));
echo "Hello, $name!";
});
});
Run the built-in PHP server:
php -S localhost:8080 router.php
Then visit http://localhost:8080/.
Component stability statuses
Component | Stability | Since |
---|---|---|
Fallthrough | alpha | 0.9 |
HandledException | alpha | 0.0 |
Handler | alpha | 0.0 |
HttpStatusException | alpha | 0.0 |
Request | alpha | 0.0 |
RequestProvider | alpha | 0.9 |
Router | alpha | 0.9 |
Handlers/PhpFileHandler | alpha | 0.7 |
Handlers/RawFileHandler | alpha | 0.7 |
Matchers/BasicMatchers | alpha | 0.9 |
Matchers/MethodMatchers | alpha | 0.9 |
Matchers/MethodMatchersTrait | alpha | 0.7 |
Matchers/PathMatchers | alpha | 0.9 |
Matchers/PathMatchersTrait | alpha | 0.7 |
Requests/BasicRequest | alpha | 0.9 |
Requests/RequestBase | alpha | 0.9 |
Requests/RequestWrapper | alpha | 0.9 |
Requests/TracingRequest | alpha | 0.9 |
Routers/BasicRouter | alpha | 0.9 |
The Stability column indicates the component's stability status, and the Since column indicates the package's major version when the component first achieved that stability.
Each component and its members has a stability status indicating how stable the interface and implementation is to depend on in production. The stability may be one of the following:
- alpha: The interface and implementation are unstable and may change significantly.
- beta: The interface is stable but its implementation is not sufficiently tested.
- omega: The interface and implementation are stable and considered ready for production use.
A component's stability status is the same as the highest stability status of its members. Once a member's stability is raised, it will not be reduced.
License
Router SS is licensed under the MIT license. See the LICENSE file for more information.