bakame / moyambi
a lightweight PSR-15 router using URLPattern and UriTemplate for route selection
Fund package maintenance!
Requires
- php: ^8.4
- league/uri: dev-master
- league/uri-interfaces: dev-master
- psr/http-factory: ^1.1.0
- psr/http-message: ^2.0
- psr/http-server-middleware: ^1.0.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95.27
- laminas/laminas-httphandlerrunner: ^2.14
- nyholm/psr7: ^1.8.2
- nyholm/psr7-server: ^1.1
- phpstan/phpstan: ^2.3
- phpstan/phpstan-deprecation-rules: ^2.0.5
- phpstan/phpstan-phpunit: ^2.1.1
- phpstan/phpstan-strict-rules: ^2.1
- phpunit/phpunit: ^13.4.1
- symfony/var-dumper: ^8.1.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-10 20:34:38 UTC
README
Moyambi is a simple lightweight PSR-15 router using:
You can use:
The URLPattern API via League\Uri\UrlPattern instances or string prefixed with pattern:
The URI Template API via League\Uri\UriTemplate instances or string prefixed with template:
to specify the route to select.
When using
UriTemplateONLY the URI path is considered for routing.URLPatternthe full URI object MAY be used depending on theURLPatterninstance used.
When an UriTemplate is used the route arguments are available via the League\Uri\UriTemplate\ExtractionResult instance
When an UrlPattern is used the route arguments are available via the League\Uri\UrlPattern\Result instance
You can mix both strategies in your router!!
<?php use Bakame\Moyambi\Router; use Bakame\Moyambi\StaticResponseHandler; use Laminas\HttpHandlerRunner\Emitter\SapiEmitter; use League\Uri\UriTemplate\ExtractionResult;use League\Uri\UrlPattern\Result; use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7Server\ServerRequestCreator; use Psr\Http\Message\ResponseInterface as Request; use Psr\Http\Message\ServerRequestInterface as Response; require __DIR__ . '/vendor/autoload.php'; $factory = new Psr17Factory(); $router = new Router( responseFactory: $factory, notFoundHandler: new StaticResponseHandler( $factory ->createResponse(404) ->withHeader('Content-Type', 'text/html; charset=utf-8') ->withBody($factory->createStream('<h1>Not Found</h1>')) ), ); $router->get('template:/hello/{name}', function (Request $request, Response $response, ExtractionResult $routeArgs) { $name = $routeArgs->string('name', 'World'); $body = $response->getBody(); $body->write('<h1>Hello '.$name.'!</h1>'); return $response->withBody($body); }); $request = new ServerRequestCreator( serverRequestFactory: $factory, uriFactory: $factory, uploadedFileFactory: $factory, streamFactory: $factory, )->fromGlobals() new SapiEmitter()->emit( $router->handle($request) );
To work as expected Bakame\Moyambi requires:
- PHP8.4+
league\uriv7.9+- A
PSR-7,PRS-15,PSR-17implementing libraries - an HTTP handler runner to convert and emit the response.
Happy coding!