misc_pterodactyl-panel/app/Http/Requests/Admin/Api/StoreApplicationApiKeyRequest.php

43 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2018-01-19 03:36:15 +00:00
<?php
namespace Pterodactyl\Http\Requests\Admin\Api;
use Pterodactyl\Models\ApiKey;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class StoreApplicationApiKeyRequest extends AdminFormRequest
{
/**
* @return array
2021-01-23 20:33:34 +00:00
*
2018-05-13 16:30:53 +00:00
* @throws \ReflectionException
* @throws \ReflectionException
2018-01-19 03:36:15 +00:00
*/
public function rules()
{
$modelRules = ApiKey::getRules();
2018-01-19 03:36:15 +00:00
return collect(AdminAcl::getResourceList())->mapWithKeys(function ($resource) use ($modelRules) {
2018-05-13 14:50:56 +00:00
return [AdminAcl::COLUMN_IDENTIFIER . $resource => $modelRules['r_' . $resource]];
2018-01-19 03:36:15 +00:00
})->merge(['memo' => $modelRules['memo']])->toArray();
}
/**
* @return array
*/
public function attributes()
{
return [
'memo' => 'Description',
];
}
public function getKeyPermissions(): array
{
return collect($this->validated())->filter(function ($value, $key) {
2018-05-13 14:50:56 +00:00
return substr($key, 0, strlen(AdminAcl::COLUMN_IDENTIFIER)) === AdminAcl::COLUMN_IDENTIFIER;
2018-01-19 03:36:15 +00:00
})->toArray();
}
}