Setup request & response filters

This commit is contained in:
Matej Bačo
2025-03-12 12:10:10 +01:00
parent ba26dd6df5
commit 796a845bcf
3 changed files with 62 additions and 0 deletions
@@ -0,0 +1,24 @@
<?php
namespace Appwrite\Utopia\Request\Filters;
use Appwrite\Utopia\Request\Filter;
class V19 extends Filter
{
// Convert 1.6 params to 1.7
public function parse(array $content, string $model): array
{
/*
Uncomment with first request filter; current is just a copy of V18
switch ($model) {
case 'functions.create':
$content['something'] = $content['somethingElse'] ?? "";
unset($content['something']);
break;
}
*/
return $content;
}
}
@@ -0,0 +1,30 @@
<?php
namespace Appwrite\Utopia\Response\Filters;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Filter;
class V19 extends Filter
{
// Convert 1.7 Data format to 1.6 format
public function parse(array $content, string $model): array
{
$parsedResponse = $content;
$parsedResponse = match($model) {
Response::MODEL_FUNCTION => $this->parseFunction($content),
Response::MODEL_FUNCTION_LIST => $this->handleList($content, 'functions', fn ($item) => $this->parseFunction($item)),
default => $parsedResponse,
};
return $parsedResponse;
}
protected function parseFunction(array $content)
{
$content['deployment'] = $content['deploymentId'] ?? '';
unset($content['deploymentId']);
return $content;
}
}