Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Transformers/Api/Client/BaseClientTransformer.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Transformers\Api\Client;
4
5
use Pterodactyl\Models\User;
6
use Webmozart\Assert\Assert;
7
use Pterodactyl\Models\Server;
8
use Pterodactyl\Transformers\Api\Application\BaseTransformer as BaseApplicationTransformer;
9
10
abstract class BaseClientTransformer extends BaseApplicationTransformer
11
{
12
/**
13
* Return the user model of the user requesting this transformation.
14
*/
15
public function getUser(): User
16
{
17
return $this->request->user();
18
}
19
20
/**
21
* Determine if the API key loaded onto the transformer has permission
22
* to access a different resource. This is used when including other
23
* models on a transformation request.
24
*
25
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
26
*/
27
protected function authorize(string $ability, ?Server $server = null): bool
28
{
29
Assert::isInstanceOf($server, Server::class);
30
31
return $this->request->user()->can($ability, [$server]);
32
}
33
34
protected function makeTransformer(string $abstract)
35
{
36
Assert::subclassOf($abstract, self::class);
37
38
return parent::makeTransformer($abstract);
39
}
40
}
41
42