Files
panel-pelican-dev/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php

72 lines
2.0 KiB
PHP
Raw Normal View History

2018-01-13 14:08:19 -06:00
<?php
2024-03-12 22:39:16 -04:00
namespace App\Http\Requests\Api\Application\Nodes;
2018-01-13 14:08:19 -06:00
2024-03-12 22:39:16 -04:00
use App\Models\Node;
use App\Services\Acl\Api\AdminAcl;
use App\Http\Requests\Api\Application\ApplicationApiRequest;
2018-01-13 14:08:19 -06:00
class StoreNodeRequest extends ApplicationApiRequest
2018-01-13 14:08:19 -06:00
{
protected ?string $resource = AdminAcl::RESOURCE_NODES;
2018-01-13 14:08:19 -06:00
protected int $permission = AdminAcl::WRITE;
2018-01-13 14:08:19 -06:00
/**
* Validation rules to apply to this request.
*/
public function rules(array $rules = null): array
{
return collect($rules ?? Node::getRules())->only([
2018-01-13 14:08:19 -06:00
'public',
'name',
'fqdn',
'scheme',
'behind_proxy',
'maintenance_mode',
2018-01-13 14:08:19 -06:00
'memory',
'memory_overallocate',
'disk',
'disk_overallocate',
'cpu',
'cpu_overallocate',
2018-01-13 14:08:19 -06:00
'upload_size',
'daemon_listen',
'daemon_sftp',
'daemon_base',
2018-01-13 14:08:19 -06:00
])->mapWithKeys(function ($value, $key) {
$key = ($key === 'daemon_sftp') ? 'daemon_sftp' : $key;
2018-01-13 14:08:19 -06:00
return [snake_case($key) => $value];
})->toArray();
}
/**
* Fields to rename for clarity in the API response.
*/
public function attributes(): array
2018-01-13 14:08:19 -06:00
{
return [
'daemon_base' => 'Daemon Base Path',
'upload_size' => 'File Upload Size Limit',
'public' => 'Node Visibility',
];
}
/**
* Change the formatting of some data keys in the validated response data
* to match what the application expects in the services.
*/
public function validated($key = null, $default = null): array
2018-01-13 14:08:19 -06:00
{
$response = parent::validated();
$response['daemon_listen'] = $response['daemon_listen'];
$response['daemon_sftp'] = $response['daemon_sftp'];
$response['daemon_base'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemon_base');
2018-01-13 14:08:19 -06:00
unset($response['daemon_base'], $response['daemon_listen'], $response['daemon_sftp']);
return $response;
}
}