2018-02-25 21:30:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Pterodactyl\Models\Server;
|
2018-02-25 21:30:56 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Application\BaseTransformer as BaseApplicationTransformer;
|
|
|
|
|
|
|
|
abstract class BaseClientTransformer extends BaseApplicationTransformer
|
|
|
|
{
|
2018-02-28 03:28:43 +00:00
|
|
|
/**
|
|
|
|
* Return the user model of the user requesting this transformation.
|
|
|
|
*/
|
|
|
|
public function getUser(): User
|
|
|
|
{
|
2022-05-22 19:37:39 +00:00
|
|
|
return $this->request->user();
|
2018-02-28 03:28:43 +00:00
|
|
|
}
|
|
|
|
|
2018-02-25 21:30:56 +00:00
|
|
|
/**
|
|
|
|
* Determine if the API key loaded onto the transformer has permission
|
|
|
|
* to access a different resource. This is used when including other
|
|
|
|
* models on a transformation request.
|
|
|
|
*
|
2022-05-22 19:37:39 +00:00
|
|
|
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
|
2018-02-25 21:30:56 +00:00
|
|
|
*/
|
2018-02-28 03:28:43 +00:00
|
|
|
protected function authorize(string $ability, Server $server = null): bool
|
2018-02-25 21:30:56 +00:00
|
|
|
{
|
2018-02-28 03:28:43 +00:00
|
|
|
Assert::isInstanceOf($server, Server::class);
|
|
|
|
|
2022-05-22 19:37:39 +00:00
|
|
|
return $this->request->user()->can($ability, [$server]);
|
2018-02-25 21:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-22 19:37:39 +00:00
|
|
|
* {@inheritDoc}
|
2018-02-25 21:30:56 +00:00
|
|
|
*/
|
2022-05-22 19:37:39 +00:00
|
|
|
protected function makeTransformer(string $abstract)
|
2018-02-25 21:30:56 +00:00
|
|
|
{
|
2022-05-22 19:37:39 +00:00
|
|
|
Assert::subclassOf($abstract, self::class);
|
2018-02-25 21:30:56 +00:00
|
|
|
|
2022-05-22 19:37:39 +00:00
|
|
|
return parent::makeTransformer($abstract);
|
2018-02-25 21:30:56 +00:00
|
|
|
}
|
|
|
|
}
|