GrocyApi/src/Objects/ApiListTransformer.php

34 lines
739 B
PHP

<?php
namespace Ardent\GrocyApi\Objects;
class ApiListTransformer
{
public static function getObjects(array $items): array
{
$objects = [];
foreach ($items as $item) {
$object = self::getObject($item);
if ($object) {
$objects[] = $object;
}
}
return $objects;
}
public static function getObject(mixed $item): mixed
{
$name = self::list($item['type']);
if ($name) {
/** @var AbstractApiObject $name */
return $name::fromApi($item);
} else {
return [];
printf('Unknown object with type "%s"' . PHP_EOL, $item['type']);
dd($item);
}
}
}