123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Http\Requests\API\Config;
- use App\Repositories\Enums\EmailConfigFieldEnum;
- use App\Repositories\Enums\BrowserConfigFiledEnum;
- class AllowSettingConfig
- {
- public function check(string $group, string $key, mixed $value)
- {
- if (! method_exists($this, $group)) {
- throw new \Exception(sprintf("%s configuration group is not supported", $group));
- }
- $groupRules = $this->$group();
- if (! isset($groupRules[$key])) {
- throw new \Exception(sprintf("The %s configuration field under the %s group is not supported", $key, $group));
- }
- $result = validator([$key => $value], [$key => $groupRules[$key]]);
- if ($result->fails()) {
- throw new \Exception($result->errors()->first());
- }
- }
- /**
- * email 字段验证
- *
- * @return string[]
- */
- private function email(): array
- {
- return EmailConfigFieldEnum::checkRules();
- }
- private function browser(): array
- {
- return BrowserConfigFiledEnum::checkRules();
- }
- }
|