AllowSettingConfig.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Requests\API\Config;
  3. class AllowSettingConfig
  4. {
  5. public function check(string $group, string $key, mixed $value)
  6. {
  7. if (! method_exists($this, $group)) {
  8. throw new \Exception(sprintf("%s configuration group is not supported", $group));
  9. }
  10. $groupRules = $this->$group();
  11. if (! isset($groupRules[$key])) {
  12. throw new \Exception(sprintf("The %s configuration field under the %s group is not supported", $key, $group));
  13. }
  14. $result = validator([$key => $value], [$key => $groupRules[$key]]);
  15. if ($result->fails()) {
  16. throw new \Exception($result->errors()->first());
  17. }
  18. }
  19. /**
  20. * email 字段验证
  21. *
  22. * @return string[]
  23. */
  24. private function email(): array
  25. {
  26. return [
  27. "email_notification" => "in:on,off",
  28. "async_sender" => "in:yes,no",
  29. "sender_email" => "nullable|email",
  30. "sender" => "nullable|min:1",
  31. "domain" => "nullable|url",
  32. "smtp_server" => "nullable|min:1",
  33. "smtp_account" => "nullable|min:1",
  34. "smtp_validation" => "in:yes,no",
  35. "smtp_port" => "nullable|numeric",
  36. "encryption" => "in:ssl,plain,tls",
  37. "smtp_password" => "nullable|min:6",
  38. "debug" => "in:off,normal,high",
  39. "charset" => "in:utf8,gbk"
  40. ];
  41. }
  42. }