1. Go to this page and download the library: Download ilexn/slim-route-strategies library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ilexn / slim-route-strategies example snippets
php
$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;
});
php
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,
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.