A bare bones front-end for knockout designed for maximum compatibility with "obsolete" browsers
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

36 lignes
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. }