misc_pterodactyl-panel/app/Http/Controllers/Api/Application/ApplicationApiController.php

77 lines
2.2 KiB
PHP
Raw Normal View History

2018-01-20 01:58:57 +00:00
<?php
2018-01-20 03:48:26 +00:00
namespace Pterodactyl\Http\Controllers\Api\Application;
use Illuminate\Http\Request;
2018-01-20 19:48:02 +00:00
use Illuminate\Http\Response;
2018-01-20 03:48:26 +00:00
use Illuminate\Container\Container;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
abstract class ApplicationApiController extends Controller
{
/**
* @var \Illuminate\Http\Request
*/
private $request;
/**
* @var \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal
2018-01-20 03:48:26 +00:00
*/
protected $fractal;
/**
* ApplicationApiController constructor.
*/
2018-01-20 19:48:02 +00:00
public function __construct()
2018-01-20 03:48:26 +00:00
{
2018-01-20 19:48:02 +00:00
Container::getInstance()->call([$this, 'loadDependencies']);
2018-01-20 03:48:26 +00:00
// Parse all of the includes to use on this request.
2018-01-20 19:48:02 +00:00
$includes = collect(explode(',', $this->request->input('include', '')))->map(function ($value) {
2018-01-20 03:48:26 +00:00
return trim($value);
})->filter()->toArray();
$this->fractal->parseIncludes($includes);
$this->fractal->limitRecursion(2);
}
2018-01-20 19:48:02 +00:00
/**
* Perform dependency injection of certain classes needed for core functionality
* without littering the constructors of classes that extend this abstract.
*
* @param \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal $fractal
* @param \Illuminate\Http\Request $request
*/
public function loadDependencies(Fractal $fractal, Request $request)
{
$this->fractal = $fractal;
$this->request = $request;
}
2018-01-20 03:48:26 +00:00
/**
* Return an instance of an application transformer.
*
* @param string $abstract
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
*/
public function getTransformer(string $abstract)
{
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
$transformer = Container::getInstance()->make($abstract);
$transformer->setKey($this->request->attributes->get('api_key'));
return $transformer;
}
2018-01-20 19:48:02 +00:00
/**
* Return a HTTP/204 response for the API.
*
* @return \Illuminate\Http\Response
*/
protected function returnNoContent(): Response
{
return new Response('', Response::HTTP_NO_CONTENT);
}
2018-01-20 03:48:26 +00:00
}