misc_pterodactyl-panel/app/Http/Controllers/Api/Client/ClientApiController.php
Matthew Penner 363c4fd49f
php-cs-fixer
2022-12-14 17:06:28 -07:00

37 lines
1 KiB
PHP

<?php
namespace Pterodactyl\Http\Controllers\Api\Client;
use Pterodactyl\Transformers\Api\Transformer;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
abstract class ClientApiController extends ApplicationApiController
{
/**
* Returns only the includes which are valid for the given transformer.
*/
protected function getIncludesForTransformer(Transformer $transformer, array $merge = []): array
{
$filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
return in_array($datum, $transformer->getAvailableIncludes());
});
return array_merge($filtered, $merge);
}
/**
* Returns the parsed includes for this request.
*/
protected function parseIncludes(): array
{
$includes = $this->request->query('include') ?? [];
if (!is_string($includes)) {
return $includes;
}
return array_map(function ($item) {
return trim($item);
}, explode(',', $includes));
}
}