Files
panel/app/Transformers/Api/Application/ServerVariableTransformer.php

49 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2024-03-12 22:39:16 -04:00
namespace App\Transformers\Api\Application;
use League\Fractal\Resource\Item;
2024-03-12 22:39:16 -04:00
use App\Models\EggVariable;
use League\Fractal\Resource\NullResource;
2024-03-12 22:39:16 -04:00
use App\Services\Acl\Api\AdminAcl;
class ServerVariableTransformer extends BaseTransformer
{
/**
* List of resources that can be included.
*/
protected array $availableIncludes = ['parent'];
/**
* Return the resource name for the JSONAPI output.
*/
public function getResourceName(): string
{
2024-03-16 14:19:40 -04:00
return EggVariable::RESOURCE_NAME;
}
/**
* Return a generic transformed server variable array.
*/
public function transform(EggVariable $variable): array
{
return $variable->toArray();
}
/**
* Return the parent service variable data.
*
2024-03-12 22:39:16 -04:00
* @throws \App\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeParent(EggVariable $variable): Item|NullResource
{
2021-01-23 12:33:34 -08:00
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
$variable->loadMissing('variable');
return $this->item($variable->getRelation('variable'), $this->makeTransformer(EggVariableTransformer::class), 'variable');
}
}