First inital test commit

This commit is contained in:
Tim
2021-10-03 19:13:41 +02:00
commit c823696937
14 changed files with 1560 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php
namespace Ardent\GrocyApi\Objects;
class ApiListTransformer
{
private static function list(string $type): ?string
{
return match ($type) {
Category::getType() => Category::class,
SingleArticle::getType() => SingleArticle::class,
SingleArticleDetails::getType() => SingleArticleDetails::class,
Order::getType() => Order::class,
OrderLine::getType() => OrderLine::class,
OrderArticle::getType() => OrderArticle::class,
Delivery::getType() => Delivery::class,
default => null,
};
}
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);
}
}
}