Code cleanup & fix frontend searching servers; closes #2100
This commit is contained in:
parent
f0e18ba6f7
commit
d3c749ac56
14 changed files with 226 additions and 194 deletions
|
@ -10,6 +10,38 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
|||
|
||||
abstract class ClientApiController extends ApplicationApiController
|
||||
{
|
||||
/**
|
||||
* Returns only the includes which are valid for the given transformer.
|
||||
*
|
||||
* @param \Pterodactyl\Transformers\Api\Client\BaseClientTransformer $transformer
|
||||
* @param array $merge
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = [])
|
||||
{
|
||||
$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()
|
||||
{
|
||||
$includes = $this->request->query('include');
|
||||
|
||||
if (! is_string($includes)) {
|
||||
return $includes;
|
||||
}
|
||||
|
||||
return array_map(function ($item) {
|
||||
return trim($item);
|
||||
}, explode(',', $includes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of an application transformer.
|
||||
*
|
||||
|
|
Reference in a new issue