2018-02-25 21:30:56 +00:00
|
|
|
<?php
|
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client;
|
2018-02-25 21:30:56 +00:00
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
use Webmozart\Assert\Assert;
|
2018-02-25 21:30:56 +00:00
|
|
|
use Illuminate\Container\Container;
|
2019-07-28 03:23:51 +00:00
|
|
|
use Pterodactyl\Transformers\Daemon\BaseDaemonTransformer;
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
2018-02-25 21:30:56 +00:00
|
|
|
|
|
|
|
abstract class ClientApiController extends ApplicationApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Return an instance of an application transformer.
|
|
|
|
*
|
|
|
|
* @param string $abstract
|
|
|
|
* @return \Pterodactyl\Transformers\Api\Client\BaseClientTransformer
|
|
|
|
*/
|
|
|
|
public function getTransformer(string $abstract)
|
|
|
|
{
|
|
|
|
/** @var \Pterodactyl\Transformers\Api\Client\BaseClientTransformer $transformer */
|
|
|
|
$transformer = Container::getInstance()->make($abstract);
|
2019-07-28 03:23:51 +00:00
|
|
|
Assert::isInstanceOfAny($transformer, [
|
|
|
|
BaseClientTransformer::class,
|
|
|
|
BaseDaemonTransformer::class,
|
|
|
|
]);
|
2018-02-25 21:30:56 +00:00
|
|
|
|
2019-07-28 03:23:51 +00:00
|
|
|
if ($transformer instanceof BaseClientTransformer) {
|
|
|
|
$transformer->setKey($this->request->attributes->get('api_key'));
|
|
|
|
$transformer->setUser($this->request->user());
|
|
|
|
}
|
2018-02-25 21:30:56 +00:00
|
|
|
|
|
|
|
return $transformer;
|
|
|
|
}
|
|
|
|
}
|