| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Slim Framework (https://slimframework.com)
|
|
|
5 |
*
|
|
|
6 |
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
|
|
|
7 |
*/
|
|
|
8 |
|
|
|
9 |
declare(strict_types=1);
|
|
|
10 |
|
|
|
11 |
namespace Slim\Handlers\Strategies;
|
|
|
12 |
|
|
|
13 |
use Psr\Http\Message\ResponseInterface;
|
|
|
14 |
use Psr\Http\Message\ServerRequestInterface;
|
|
|
15 |
use Slim\Interfaces\RequestHandlerInvocationStrategyInterface;
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* PSR-15 RequestHandler invocation strategy
|
|
|
19 |
*/
|
|
|
20 |
class RequestHandler implements RequestHandlerInvocationStrategyInterface
|
|
|
21 |
{
|
|
|
22 |
protected bool $appendRouteArgumentsToRequestAttributes;
|
|
|
23 |
|
|
|
24 |
public function __construct(bool $appendRouteArgumentsToRequestAttributes = false)
|
|
|
25 |
{
|
|
|
26 |
$this->appendRouteArgumentsToRequestAttributes = $appendRouteArgumentsToRequestAttributes;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Invoke a route callable that implements RequestHandlerInterface
|
|
|
31 |
*
|
|
|
32 |
* @param array<string, string> $routeArguments
|
|
|
33 |
*/
|
|
|
34 |
public function __invoke(
|
|
|
35 |
callable $callable,
|
|
|
36 |
ServerRequestInterface $request,
|
|
|
37 |
ResponseInterface $response,
|
|
|
38 |
array $routeArguments
|
|
|
39 |
): ResponseInterface {
|
|
|
40 |
if ($this->appendRouteArgumentsToRequestAttributes) {
|
|
|
41 |
foreach ($routeArguments as $k => $v) {
|
|
|
42 |
$request = $request->withAttribute($k, $v);
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
return $callable($request);
|
|
|
47 |
}
|
|
|
48 |
}
|