UserId.php 590 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Module\User\Validator;
  3. use App\Module\App\SessionApp;
  4. use UCore\Exception\LogicException;
  5. use UCore\Validator;
  6. /**
  7. * 用户ID注入
  8. *
  9. */
  10. class UserId extends Validator
  11. {
  12. public function validate(mixed $value, array $data): bool
  13. {
  14. // 必须在app下
  15. $s3name = substr(request()->getPathInfo(),1,3);
  16. if($s3name !== 'app'){
  17. throw new LogicException("代码错误-1");
  18. }
  19. $user_id = SessionApp::getUserId();
  20. $this->validation->setRaw('user_id', $user_id);
  21. //
  22. return true;
  23. }
  24. }