bearsunday /
BEAR.Resource
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace BEAR\Resource; |
||||
| 6 | |||||
| 7 | use Override; |
||||
| 8 | |||||
| 9 | use function strtoupper; |
||||
| 10 | |||||
| 11 | /** |
||||
| 12 | * @method HttpResourceObject get(AbstractUri|string $uri, Query $params = []) |
||||
| 13 | * @method HttpResourceObject head(AbstractUri|string $uri, Query $params = []) |
||||
| 14 | * @method HttpResourceObject put(AbstractUri|string $uri, Query $params = []) |
||||
| 15 | * @method HttpResourceObject post(AbstractUri|string $uri, Query $params = []) |
||||
| 16 | * @method HttpResourceObject patch(AbstractUri|string $uri, Query $params = []) |
||||
| 17 | * @method HttpResourceObject delete(AbstractUri|string $uri, Query $params = []) |
||||
| 18 | * @property-read int $code |
||||
| 19 | * @property-read Headers $headers |
||||
| 20 | * @property-read HttpBody $body |
||||
| 21 | * @property-read string $view |
||||
| 22 | * @psalm-import-type Query from Types |
||||
| 23 | * @psalm-import-type Headers from Types |
||||
| 24 | * @psalm-import-type HttpBody from Types |
||||
| 25 | */ |
||||
| 26 | final class HttpResourceObject extends ResourceObject implements InvokeRequestInterface |
||||
| 27 | { |
||||
| 28 | public function __construct( |
||||
| 29 | private readonly HttpRequestInterface $httpRequest, |
||||
| 30 | ) { |
||||
| 31 | } |
||||
| 32 | |||||
| 33 | /** @SuppressWarnings(PHPMD.CamelCaseMethodName) Underscore prefix indicates internal API method */ |
||||
| 34 | #[Override] |
||||
| 35 | public function _invokeRequest(InvokerInterface $invoker, AbstractRequest $request): ResourceObject |
||||
| 36 | { |
||||
| 37 | unset($invoker); |
||||
| 38 | |||||
| 39 | return $this->request($request); |
||||
| 40 | } |
||||
| 41 | |||||
| 42 | public function request(AbstractRequest $request): ResourceObject |
||||
| 43 | { |
||||
| 44 | $uri = $request->resourceObject->uri; |
||||
| 45 | $method = strtoupper($uri->method); |
||||
| 46 | [ |
||||
| 47 | 'code' => $this->code, |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 48 | 'headers' => $this->headers, |
||||
|
0 ignored issues
–
show
|
|||||
| 49 | 'body' => $this->body, |
||||
|
0 ignored issues
–
show
|
|||||
| 50 | 'view' => $this->view, |
||||
|
0 ignored issues
–
show
|
|||||
| 51 | ] = $this->httpRequest->request($method, (string) $uri, $uri->query); |
||||
|
0 ignored issues
–
show
$uri->query of type BEAR\Resource\Query is incompatible with the type array expected by parameter $query of BEAR\Resource\HttpRequestInterface::request().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 52 | |||||
| 53 | return $this; |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | public function __toString(): string |
||||
| 57 | { |
||||
| 58 | return $this->view; |
||||
| 59 | } |
||||
| 60 | } |
||||
| 61 |