Files
pterodactyl-panel/app/Http/Requests/Base/LocaleRequest.php
T

52 lines
1.3 KiB
PHP
Raw Normal View History

2025-06-15 19:40:22 -06:00
<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2025-06-15 19:40:22 -06:00
namespace Pterodactyl\Http\Requests\Base;
use Illuminate\Foundation\Http\FormRequest;
class LocaleRequest extends FormRequest
{
2026-10-27 11:42:22 +00:00
private const string LOCALE = '[a-z]{2}(?:_[A-Z]{2})?';
private const string NAMESPACE = '(?:[a-z]{1,191}|ext-[a-z][a-z0-9-]{0,47}::[a-z][a-z0-9_-]{0,63})';
2026-10-05 18:10:18 -04:00
/**
* @return ValidationRules
*/
2025-06-15 19:40:22 -06:00
public function rules(): array
{
return [
2026-10-27 11:42:22 +00:00
'locale' => ['required', 'string', 'regex:/^'.self::LOCALE.'(?:[+ ]'.self::LOCALE.'){0,7}$/D'],
'namespace' => ['required', 'string', 'regex:/^'.self::NAMESPACE.'(?:[+ ]'.self::NAMESPACE.'){0,31}$/D'],
// The revision of an extension's translations, which only makes the URL unique.
2026-10-06 13:59:43 -04:00
'revision' => ['sometimes', 'string', 'regex:/^[a-f0-9]{32}$/D'],
2025-06-15 19:40:22 -06:00
];
}
2026-10-27 11:42:22 +00:00
/**
* @return list<string>
*/
public function locales(): array
{
return $this->listed('locale');
}
/**
* @return list<string>
*/
public function namespaces(): array
{
return $this->listed('namespace');
}
/**
* @return list<string>
*/
private function listed(string $key): array
{
return array_values(array_unique(preg_split('/[+ ]/', $this->string($key)->toString(), flags: PREG_SPLIT_NO_EMPTY) ?: []));
}
2025-06-15 19:40:22 -06:00
}