ilexn / slim-route-strategies
Slim 4 route strategies for parameter upcasting
0.1.2
2019-06-10 13:20 UTC
Requires
- php: ^7.2
- slim/slim: 4.x-dev
Requires (Dev)
- infection/infection: ^0.13.1
- phpstan/phpstan: ^0.11.0
- phpstan/phpstan-phpunit: ^0.11.0
- phpstan/phpstan-strict-rules: ^0.11.0
- phpunit/phpunit: ^8.0
- symplify/easy-coding-standard: ^5.4
This package is auto-updated.
Last update: 2024-11-15 02:44:21 UTC
README
Slim 4 route strategies for parameter upcasting
Install
Via Composer
$ composer require ilexn/slim-route-strategies
Usage
$resolver = new RouteArgsResolver(); $resolver->add(new Case1()); $app = AppFactory::create(); $routeCollector = $app->getRouteCollector(); $routeCollector->setDefaultInvocationStrategy($resolver); $app->get('/hello/{name}', function ($request, $response, Name $name) { $response->getBody()->write("Hello ". $name->getName()); return $response; });
final class Case1 implements RouteArgsResolverInterface { public function __invoke(string $value): int { return 1; } public function get(string $value): Name { return new Name($value); } /** * @return callable[] */ public function getArgsResolver(): array { return [ 'name' => [$this, 'get'], 'b' => static function ($value) { return $value; }, 'c' => $this, ]; } }