2018-01-11 22:49:46 -06:00
|
|
|
<?php
|
|
|
|
|
2018-01-19 21:47:06 -06:00
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
2018-01-11 22:49:46 -06:00
|
|
|
|
|
|
|
use Illuminate\Container\Container;
|
2021-08-07 13:06:45 -07:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2018-02-25 15:30:56 -06:00
|
|
|
use Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException;
|
2018-01-11 22:49:46 -06:00
|
|
|
|
2021-08-07 13:06:45 -07:00
|
|
|
abstract class BaseTransformer extends Transformer
|
2018-01-11 22:49:46 -06:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new instance of the transformer and pass along the currently
|
|
|
|
* set API key.
|
|
|
|
*
|
2018-01-19 21:47:06 -06:00
|
|
|
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
2018-02-25 15:30:56 -06:00
|
|
|
*
|
2021-01-01 15:55:30 -07:00
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
2018-02-25 15:30:56 -06:00
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
2018-01-11 22:49:46 -06:00
|
|
|
*/
|
2018-02-25 15:30:56 -06:00
|
|
|
protected function makeTransformer(string $abstract, array $parameters = [])
|
2018-01-11 22:49:46 -06:00
|
|
|
{
|
2018-01-19 21:47:06 -06:00
|
|
|
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
|
2018-01-11 22:49:46 -06:00
|
|
|
$transformer = Container::getInstance()->makeWith($abstract, $parameters);
|
|
|
|
|
2021-01-23 18:17:35 -07:00
|
|
|
if (!$transformer instanceof self) {
|
2018-02-25 15:30:56 -06:00
|
|
|
throw new InvalidTransformerLevelException('Calls to ' . __METHOD__ . ' must return a transformer that is an instance of ' . __CLASS__);
|
|
|
|
}
|
|
|
|
|
2018-01-11 22:49:46 -06:00
|
|
|
return $transformer;
|
|
|
|
}
|
|
|
|
}
|