-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRequestResponseNamedArgs.php
54 lines (47 loc) · 1.57 KB
/
RequestResponseNamedArgs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
* (c) 2017-2024 Julián Gutiérrez <juliangut@gmail.com>
*
* @license BSD-3-Clause
* @link https://github.com/juliangut/slim-routing
*/
declare(strict_types=1);
namespace Jgut\Slim\Routing\Strategy;
use Jgut\Slim\Routing\Response\Handler\ResponseTypeHandler;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use RuntimeException;
use Slim\Interfaces\RequestHandlerInvocationStrategyInterface;
/**
* Route callback strategy with route parameters as individual arguments.
*/
final class RequestResponseNamedArgs implements RequestHandlerInvocationStrategyInterface
{
use ResponseTypeStrategyTrait;
/**
* @param array<string, string|ResponseTypeHandler> $responseHandlers
*
* @throws RuntimeException
*/
public function __construct(
array $responseHandlers,
protected ResponseFactoryInterface $responseFactory,
protected ?ContainerInterface $container = null,
) {
$this->setResponseHandlers($responseHandlers);
}
/**
* @param callable(ServerRequestInterface, ResponseInterface): mixed $callable
* @param array<string, mixed> $routeArguments
*/
public function __invoke(
callable $callable,
ServerRequestInterface $request,
ResponseInterface $response,
array $routeArguments,
): ResponseInterface {
return $this->handleResponse($callable($request, $response, ...$routeArguments));
}
}