mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-01 11:55:51 -05:00
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pterodactyl\Validation;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
use Pterodactyl\Models\Mount;
|
|
use Pterodactyl\Rules\NotInPathHierarchy;
|
|
|
|
final class MountRules
|
|
{
|
|
/**
|
|
* Validation rules for the mount requests.
|
|
*
|
|
* @param Mount|null $ignore the mount being updated
|
|
* @return NormalizedValidationRules
|
|
*/
|
|
public static function rules(?Mount $ignore = null): array
|
|
{
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
'string',
|
|
'min:2',
|
|
'max:64',
|
|
Rule::unique('mounts', 'name')->ignore($ignore),
|
|
],
|
|
'description' => ['nullable', 'string', 'max:191'],
|
|
|
|
'source' => [
|
|
'required',
|
|
'string',
|
|
'starts_with:/',
|
|
new NotInPathHierarchy(Mount::$protectedSourcePaths),
|
|
new NotInPathHierarchy(Mount::$invalidSourcePaths, includeDescendants: false),
|
|
],
|
|
|
|
'target' => [
|
|
'required',
|
|
'string',
|
|
'starts_with:/',
|
|
new NotInPathHierarchy(Mount::$invalidTargetPaths, includeDescendants: false),
|
|
],
|
|
|
|
'read_only' => ['sometimes', 'boolean'],
|
|
'user_mountable' => ['sometimes', 'boolean'],
|
|
];
|
|
}
|
|
}
|