misc_pterodactyl-panel/app/Transformers/Api/Application/UserTransformer.php

55 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\User;
use Pterodactyl\Services\Acl\Api\AdminAcl;
class UserTransformer extends BaseTransformer
{
/**
* List of resources that can be included.
*
* @var array
*/
2017-11-19 22:30:00 +00:00
protected $availableIncludes = ['servers'];
/**
* Return the resource name for the JSONAPI output.
*
* @return string
*/
public function getResourceName(): string
{
return User::RESOURCE_NAME;
}
/**
* Return a generic transformed subuser array.
*
2017-11-19 22:30:00 +00:00
* @param \Pterodactyl\Models\User $user
* @return array
*/
2017-11-19 22:30:00 +00:00
public function transform(User $user): array
{
return $user->toArray();
}
/**
* Return the servers associated with this user.
*
2017-11-19 22:30:00 +00:00
* @param \Pterodactyl\Models\User $user
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*/
public function includeServers(User $user)
{
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
return $this->null();
}
$user->loadMissing('servers');
return $this->collection($user->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');
}
}