mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
- added user animelist/mangalist endpoints back - fixed issues with the container image - improved club model factory - fixed ordering while searching when search engine is disabled (mongodb based search)
35 lines
892 B
PHP
35 lines
892 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Spatie\Enum\Laravel\Enum;
|
|
use Spatie\LaravelData\Optional;
|
|
|
|
final class DefaultPrivateFieldMapperService implements PrivateFieldMapperService
|
|
{
|
|
public function map($instance, array $values): mixed
|
|
{
|
|
$cls = get_class($instance);
|
|
|
|
foreach ($values as $fieldName => $fieldValue) {
|
|
if ($fieldValue instanceof Optional) {
|
|
continue;
|
|
}
|
|
|
|
if ($fieldValue instanceof Enum) {
|
|
$fieldValue = $fieldValue->label;
|
|
}
|
|
|
|
if (!property_exists($cls, $fieldName)) {
|
|
continue;
|
|
}
|
|
|
|
$reflection = new \ReflectionProperty($cls, $fieldName);
|
|
// note: ->setAccessible call would be required under php version 8.1
|
|
$reflection->setValue($instance, $fieldValue);
|
|
}
|
|
|
|
return $instance;
|
|
}
|
|
}
|