forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseClientTransformer.php
More file actions
43 lines (36 loc) · 1.17 KB
/
BaseClientTransformer.php
File metadata and controls
43 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Pterodactyl\Transformers\Api\Client;
use Pterodactyl\Models\User;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server;
use Pterodactyl\Transformers\Api\Application\BaseTransformer as BaseApplicationTransformer;
abstract class BaseClientTransformer extends BaseApplicationTransformer
{
/**
* Return the user model of the user requesting this transformation.
*/
public function getUser(): User
{
return $this->request->user();
}
/**
* 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.
*
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
*/
protected function authorize(string $ability, Server $server = null): bool
{
Assert::isInstanceOf($server, Server::class);
return $this->request->user()->can($ability, [$server]);
}
/**
* {@inheritDoc}
*/
protected function makeTransformer(string $abstract)
{
Assert::subclassOf($abstract, self::class);
return parent::makeTransformer($abstract);
}
}