Path: blob/1.0-develop/app/Traits/Services/ValidatesValidationRules.php
10284 views
<?php12namespace Pterodactyl\Traits\Services;34use Illuminate\Support\Str;5use Illuminate\Contracts\Validation\Factory as ValidationFactory;6use Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException;78trait ValidatesValidationRules9{10abstract protected function getValidator(): ValidationFactory;1112/**13* Validate that the rules being provided are valid for Laravel and can14* be resolved.15*16* @throws BadValidationRuleException17*/18public function validateRules(array|string $rules): void19{20try {21$this->getValidator()->make(['__TEST' => 'test'], ['__TEST' => $rules])->fails();22} catch (\BadMethodCallException $exception) {23$matches = [];24if (preg_match('/Method \[(.+)\] does not exist\./', $exception->getMessage(), $matches)) {25throw new BadValidationRuleException(trans('exceptions.nest.variables.bad_validation_rule', ['rule' => Str::snake(str_replace('validate', '', array_get($matches, 1, 'unknownRule')))]), $exception);26}2728throw $exception;29}30}31}323334