1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php namespace Client\Request;
- class Users extends Collection {
- protected function set_scope(string $method) {
- switch ($method) {
- default:
- $this->scope = "/users";
- }
- }
- public function new(...$args) {
- $user = new User($this->url, $this->token);
- if (count($args) != 0)
- $user->create($args);
- return $user;
- }
- public function get(string $s = "") {
- if ($this->by_key($s))
- return $this->by_key($s);
- return new User($this->url, $this->token, $s);
- }
- public function search(array $params = array()) {
- if (!isset($params["name"]) && !isset($params['q']))
- throw new SearchParamException("Missing param <name>|<q>");
- if (isset($params["name"])) {
- $params["q"] = $params["name"];
- unset($params["name"]);
- }
- $jenc = $this->method_get("/search", $params);
- $this->json_set_property($this->json_decode($jenc));
- return $this;
- }
- protected function json_set_property($obj) {
- if (isset($obj->data)) {
- foreach($obj->data as $key => $val) {
- $user = new User($this->url, $this->token, $val->login);
- $user->json_set_property($val);
- $this->add($user, $user->ulogin);
- }
- }
- }
- }
|