123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php namespace Client\Request;
- /**
- * Returns one or more users in the Gogs installation,
- * depending on the called method.
- *
- * @author Joachim M. Giaever (joachim[]giaever.org)
- * @package request
- */
- class Users extends Collection {
- protected function set_scope(string $method) {
- var_dump("METHOD", $method);
- switch ($method) {
- default:
- $this->scope = "/users";
- }
- }
- /**
- * 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 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);
- }
- }
- }
- }
|