- Added SearchRequest compatibilty and began working on QueryBuilder processing
This commit is contained in:
1 parent
ce4d6cdf7c
commit
4e120cea6c
20 files changed
+510
-141
No files matched your search
+122
-9
@@ -2,13 +2,11 @@
|
||||
|
||||
namespace Ulmus\Api\Request;
|
||||
|
||||
use League\CommonMark\Block\Element\StringContainerInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Ulmus\Api\Common\{MethodEnum, Message, Stream, Uri};
|
||||
use Ulmus\Api\Common\{MethodEnum, Message, Uri, };
|
||||
use Ulmus\Api\Stream\{JsonStream, Stream};
|
||||
use Psr\Http\Message\{MessageInterface, ServerRequestInterface, UriInterface, RequestInterface, StreamInterface};
|
||||
|
||||
class Request extends Message implements RequestInterface
|
||||
class Request extends Message implements ServerRequestInterface
|
||||
{
|
||||
protected int $code;
|
||||
|
||||
@@ -20,6 +18,10 @@ class Request extends Message implements RequestInterface
|
||||
|
||||
protected MethodEnum $method;
|
||||
|
||||
protected array $cookies = [];
|
||||
|
||||
protected array $files = [];
|
||||
|
||||
public function __construct(string|UriInterface $uri, MethodEnum $method, null|StreamInterface $stream = null, array $headers = [])
|
||||
{
|
||||
$this->method = $method;
|
||||
@@ -70,9 +72,9 @@ class Request extends Message implements RequestInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUri()
|
||||
public function getUri() : UriInterface
|
||||
{
|
||||
return (string) $this->uri;
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function withUri(UriInterface $uri, $preserveHost = false)
|
||||
@@ -101,4 +103,115 @@ class Request extends Message implements RequestInterface
|
||||
$fromUri->getHost(), $port && ! in_array($port, Uri::IGNORE_HTTP_PORT) ? ":{$port}" : ""
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function withQueryParams(array $query) : static
|
||||
{
|
||||
return (clone $this)->addQueryParams($query);
|
||||
}
|
||||
|
||||
protected function addQueryParams(array $query) : static
|
||||
{
|
||||
$rebuilt = http_build_query(array_merge($this->getQueryParams(), $query), "", null, PHP_QUERY_RFC3986);
|
||||
|
||||
$this->getUri()->withQuery($rebuilt);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getServerParams() : array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getCookieParams() : array
|
||||
{
|
||||
return $this->cookies;
|
||||
}
|
||||
|
||||
public function withCookieParams(array $cookies) : static
|
||||
{
|
||||
return (clone $this)->setCookies($cookies);
|
||||
}
|
||||
|
||||
protected function setCookies(array $cookies) : static
|
||||
{
|
||||
$this->cookies = $cookies;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQueryParams() : array
|
||||
{
|
||||
parse_str($this->getUri()->getQuery(), $query);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getUploadedFiles() : array
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
public function withUploadedFiles(array $uploadedFiles) : static
|
||||
{
|
||||
return (clone $this)->setUploadedFiles($uploadedFiles);
|
||||
}
|
||||
|
||||
protected function setUploadedFiles(array $uploadedFiles) : static
|
||||
{
|
||||
$this->files = $uploadedFiles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParsedBody() : null|array|object
|
||||
{
|
||||
$raw = $this->getBody()->getContents();
|
||||
|
||||
$contentType = $this->getHeader('Content-Type')[0] ?? "application/x-www-form-urlencoded";
|
||||
|
||||
switch($contentType) {
|
||||
case "application/x-www-form-urlencoded":
|
||||
parse_str($raw, $result);
|
||||
|
||||
return $result;
|
||||
|
||||
case "multipart/form-data":
|
||||
|
||||
return [];
|
||||
|
||||
case "application/json":
|
||||
return JsonStream::fromJsonEncoded( $raw )->decode();
|
||||
|
||||
}
|
||||
|
||||
return [ sprintf("Unsupported content type: %s", $contentType) ];
|
||||
}
|
||||
|
||||
public function withParsedBody(mixed $data) : static
|
||||
{
|
||||
return (clone $this)->setBody(
|
||||
JsonStream::fromContent($data)
|
||||
);
|
||||
}
|
||||
|
||||
public function getAttributes() : array
|
||||
{
|
||||
// TODO: Implement getAttributes() method.
|
||||
}
|
||||
|
||||
public function getAttribute($name, $default = null) : mixed
|
||||
{
|
||||
// TODO: Implement getAttribute() method.
|
||||
}
|
||||
|
||||
public function withAttribute($name, $value) : static
|
||||
{
|
||||
// TODO: Implement withAttribute() method.
|
||||
}
|
||||
|
||||
public function withoutAttribute($name): static
|
||||
{
|
||||
// TODO: Implement withoutAttribute() method.
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user