-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallbackEndpoint.php
More file actions
38 lines (31 loc) · 917 Bytes
/
CallbackEndpoint.php
File metadata and controls
38 lines (31 loc) · 917 Bytes
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
<?php declare(strict_types=1);
/*
* This file is part of Polymorphine/Routing package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Polymorphine\Routing\Route\Endpoint;
use Polymorphine\Routing\Route\Endpoint;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Endpoint passing request to given callback.
*/
class CallbackEndpoint extends Endpoint
{
private $callback;
/**
* @param callable $callback fn(ServerRequestInterface) => ResponseInterface
*/
public function __construct(callable $callback)
{
$this->callback = $callback;
}
protected function execute(ServerRequestInterface $request, ResponseInterface $prototype): ResponseInterface
{
return ($this->callback)($request);
}
}