mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
- updated api docs - fixed top reviews endpoint - fixed reviews parsing - added "contextual" boolean query string parameters, so params without value can be interpreted as "boolean". E.g. ?sfw or ?kid in the url would add "true" value to their corresponding field in the DTO - fixed typesense issues
26 lines
596 B
PHP
26 lines
596 B
PHP
<?php
|
|
|
|
namespace App\Casts;
|
|
|
|
use Spatie\LaravelData\Casts\Cast;
|
|
use Spatie\LaravelData\Support\DataProperty;
|
|
|
|
/**
|
|
* This class ensures that "?sfw" and "?kids" boolean type query string parameters in the url would be interpreted as "true"
|
|
*/
|
|
final class ContextualBooleanCast implements Cast
|
|
{
|
|
|
|
public function cast(DataProperty $property, mixed $value, array $context): mixed
|
|
{
|
|
$propertyName = $property->name;
|
|
|
|
if (array_key_exists($propertyName, $context) && $context[$propertyName] === "")
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|