Skip to content

Commit

Permalink
#6816 convert given json params into php types (e.g. iso-date -> Carbon)
Browse files Browse the repository at this point in the history
  • Loading branch information
kakenbok committed Aug 26, 2024
1 parent 46bac0b commit ceaa400
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api-resources-server/src/Api/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
use Afeefa\ApiResources\DI\DependencyResolver;
use Afeefa\ApiResources\Exception\Exceptions\ApiException;
use Afeefa\ApiResources\Exception\Exceptions\InvalidConfigurationException;
use Afeefa\ApiResources\Field\Fields\DateAttribute;
use Afeefa\ApiResources\Resolver\Action\BaseActionResolver;
use Afeefa\ApiResources\Resource\Resource;
use Afeefa\ApiResources\Type\TypeClassMap;
use Afeefa\ApiResources\Validator\ValidationFailedException;
use Carbon\Carbon;
use DateTimeZone;
use JsonSerializable;

class ApiRequest implements ContainerAwareInterface, ToSchemaJsonInterface, JsonSerializable
Expand Down Expand Up @@ -119,7 +122,15 @@ public function hasParam(string $name): bool

public function getParam(string $name, $default = null)
{
return $this->params[$name] ?? $default;
$param = $this->params[$name] ?? $default;

if ($this->getAction()->getParam($name)::class === DateAttribute::class) {
$param = Carbon::parse($param);
$tz = date_default_timezone_get();
$param->setTimezone(new DateTimeZone($tz));
}

return $param;
}

public function filter(string $name, string $value): ApiRequest
Expand Down

0 comments on commit ceaa400

Please sign in to comment.