A bare bones front-end for knockout designed for maximum compatibility with "obsolete" browsers
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

36 行
879B

  1. <?php
  2. namespace App\Knockout;
  3. use Illuminate\Support\Facades\Cache;
  4. class UserBan {
  5. private static function requestAll(int $userId): Dataset
  6. {
  7. $data = (new AbstractData)->httpGet(sprintf('/user/%u/bans', $userId));
  8. $json = json_decode($data);
  9. $records = array_map(function($user) {
  10. return Ban::unwrap($user);
  11. }, $json);
  12. return (new Dataset($records));
  13. }
  14. public static function updateAll(int $userId): Dataset
  15. {
  16. $key = sprintf('user-bans-%u', $userId);
  17. $data = self::requestAll($userId);
  18. Cache::put($key, $data, 300);
  19. return $data;
  20. }
  21. public static function all(int $userId): Dataset
  22. {
  23. $key = sprintf('user-bans-%u', $userId);
  24. return Cache::get($key, function() use($userId) {
  25. return self::updateAll($userId);
  26. });
  27. }
  28. }