scope = "/users"; break; case "search": $this->scope = "/users/search"; default: return false; } return true; } /** * Returns a new user object. If arguments * is specified the user will be "created". * * The arguments can be left out to "create" the * user through the user object iteself. * * @param ...$args User->create arguments * @return \User */ public function create(...$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); $user = (new User($this->url, $this->token, $s))->load(); $this->add($user, $user->ulogin); return $user; } public function search(array $params = array()) { if (!isset($params["name"]) && !isset($params['q'])) throw new Exception\SearchParamException("Missing param |"); if (isset($params["name"])) { $params["q"] = $params["name"]; unset($params["name"]); } $this->set_scope("search"); $jenc = $this->method_get($params); $old = $this->all(); $this->json_set_property($this->json_decode($jenc)); $users = new \Gogs\Lib\Collection(); $users->set(array_diff_key($this->all(), $old)); return $users; } 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); } } } } } ?>