Update request/response extensions for framework changes
This commit is contained in:
parent
f54aa1f4c2
commit
ce76fb58b1
2 changed files with 20 additions and 48 deletions
|
@ -9,53 +9,20 @@ use Utopia\Swoole\Request as UtopiaRequest;
|
||||||
|
|
||||||
class Request extends UtopiaRequest
|
class Request extends UtopiaRequest
|
||||||
{
|
{
|
||||||
/**
|
private static ?Filter $filter = null;
|
||||||
* @var Filter
|
private static ?Route $route = null;
|
||||||
*/
|
|
||||||
private static $filter = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Route
|
|
||||||
*/
|
|
||||||
private static $route = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(SwooleRequest $request)
|
public function __construct(SwooleRequest $request)
|
||||||
{
|
{
|
||||||
parent::__construct($request);
|
parent::__construct($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clone(): Request
|
|
||||||
{
|
|
||||||
return new self($this->swoole);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Params
|
* @inheritdoc
|
||||||
*
|
|
||||||
* Get all params of current method
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getParams(): array
|
public function getParams(): array
|
||||||
{
|
{
|
||||||
$requestParameters = [];
|
$requestParameters = parent::getParams();
|
||||||
|
|
||||||
switch ($this->getMethod()) {
|
|
||||||
case self::METHOD_GET:
|
|
||||||
$requestParameters = (!empty($this->swoole->get)) ? $this->swoole->get : [];
|
|
||||||
break;
|
|
||||||
case self::METHOD_POST:
|
|
||||||
case self::METHOD_PUT:
|
|
||||||
case self::METHOD_PATCH:
|
|
||||||
case self::METHOD_DELETE:
|
|
||||||
$requestParameters = $this->generateInput();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$requestParameters = (!empty($this->swoole->get)) ? $this->swoole->get : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::hasFilter() && self::hasRoute()) {
|
if (self::hasFilter() && self::hasRoute()) {
|
||||||
$endpointIdentifier = self::getRoute()->getLabel('sdk.namespace', 'unknown') . '.' . self::getRoute()->getLabel('sdk.method', 'unknown');
|
$endpointIdentifier = self::getRoute()->getLabel('sdk.namespace', 'unknown') . '.' . self::getRoute()->getLabel('sdk.method', 'unknown');
|
||||||
|
@ -65,15 +32,14 @@ class Request extends UtopiaRequest
|
||||||
return $requestParameters;
|
return $requestParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to set a response filter
|
* Function to set a response filter
|
||||||
*
|
*
|
||||||
* @param $filter the response filter to set
|
* @param Filter|null $filter Filter the response filter to set
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setFilter(?Filter $filter)
|
public static function setFilter(?Filter $filter): void
|
||||||
{
|
{
|
||||||
self::$filter = $filter;
|
self::$filter = $filter;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +47,7 @@ class Request extends UtopiaRequest
|
||||||
/**
|
/**
|
||||||
* Return the currently set filter
|
* Return the currently set filter
|
||||||
*
|
*
|
||||||
* @return Filter
|
* @return Filter|null
|
||||||
*/
|
*/
|
||||||
public static function getFilter(): ?Filter
|
public static function getFilter(): ?Filter
|
||||||
{
|
{
|
||||||
|
@ -101,19 +67,19 @@ class Request extends UtopiaRequest
|
||||||
/**
|
/**
|
||||||
* Function to set a request route
|
* Function to set a request route
|
||||||
*
|
*
|
||||||
* @param Route $route the request route to set
|
* @param Route|null $route the request route to set
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setRoute(?Route $route)
|
public static function setRoute(?Route $route): void
|
||||||
{
|
{
|
||||||
self::$route = $route;
|
self::$route = $route;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently get route
|
* Return the current route
|
||||||
*
|
*
|
||||||
* @return Route
|
* @return Route|null
|
||||||
*/
|
*/
|
||||||
public static function getRoute(): ?Route
|
public static function getRoute(): ?Route
|
||||||
{
|
{
|
||||||
|
|
|
@ -375,7 +375,9 @@ class Response extends SwooleResponse
|
||||||
/**
|
/**
|
||||||
* Get Model Object
|
* Get Model Object
|
||||||
*
|
*
|
||||||
|
* @param string $key
|
||||||
* @return Model
|
* @return Model
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getModel(string $key): Model
|
public function getModel(string $key): Model
|
||||||
{
|
{
|
||||||
|
@ -415,6 +417,7 @@ class Response extends SwooleResponse
|
||||||
* @param string $model
|
* @param string $model
|
||||||
*
|
*
|
||||||
* return void
|
* return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function dynamic(Document $document, string $model): void
|
public function dynamic(Document $document, string $model): void
|
||||||
{
|
{
|
||||||
|
@ -427,11 +430,11 @@ class Response extends SwooleResponse
|
||||||
|
|
||||||
switch ($this->getContentType()) {
|
switch ($this->getContentType()) {
|
||||||
case self::CONTENT_TYPE_JSON:
|
case self::CONTENT_TYPE_JSON:
|
||||||
$this->json(!empty($output) ? $output : new stdClass());
|
$this->json(!empty($output) ? $output : new \stdClass());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case self::CONTENT_TYPE_YAML:
|
case self::CONTENT_TYPE_YAML:
|
||||||
$this->yaml(!empty($output) ? $output : new stdClass());
|
$this->yaml(!empty($output) ? $output : new \stdClass());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case self::CONTENT_TYPE_NULL:
|
case self::CONTENT_TYPE_NULL:
|
||||||
|
@ -441,7 +444,7 @@ class Response extends SwooleResponse
|
||||||
if ($model === self::MODEL_NONE) {
|
if ($model === self::MODEL_NONE) {
|
||||||
$this->noContent();
|
$this->noContent();
|
||||||
} else {
|
} else {
|
||||||
$this->json(!empty($output) ? $output : new stdClass());
|
$this->json(!empty($output) ? $output : new \stdClass());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -454,6 +457,8 @@ class Response extends SwooleResponse
|
||||||
* @param string $model
|
* @param string $model
|
||||||
*
|
*
|
||||||
* return array
|
* return array
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function output(Document $document, string $model): array
|
public function output(Document $document, string $model): array
|
||||||
{
|
{
|
||||||
|
@ -553,6 +558,7 @@ class Response extends SwooleResponse
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function yaml(array $data): void
|
public function yaml(array $data): void
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue