users.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php namespace Client\Request;
  2. class Users extends Collection {
  3. protected function set_scope(string $method) {
  4. switch ($method) {
  5. default:
  6. $this->scope = "/users";
  7. }
  8. }
  9. public function new(...$args) {
  10. $user = new User($this->url, $this->token);
  11. if (count($args) != 0)
  12. $user->create($args);
  13. return $user;
  14. }
  15. public function get(string $s = "") {
  16. if ($this->by_key($s))
  17. return $this->by_key($s);
  18. return new User($this->url, $this->token, $s);
  19. }
  20. public function search(array $params = array()) {
  21. if (!isset($params["name"]) && !isset($params['q']))
  22. throw new SearchParamException("Missing param <name>|<q>");
  23. if (isset($params["name"])) {
  24. $params["q"] = $params["name"];
  25. unset($params["name"]);
  26. }
  27. $jenc = $this->method_get("/search", $params);
  28. $this->json_set_property($this->json_decode($jenc));
  29. return $this;
  30. }
  31. protected function json_set_property($obj) {
  32. if (isset($obj->data)) {
  33. foreach($obj->data as $key => $val) {
  34. $user = new User($this->url, $this->token, $val->login);
  35. $user->json_set_property($val);
  36. $this->add($user, $user->ulogin);
  37. }
  38. }
  39. }
  40. }