owner = $owner; parent::__construct($api_url, $api_token); } protected function set_scope(string $method) { switch ($method) { case "get": $this->scope = ($this->owner == null || $this->owner->authenticated() ? "/user" : "/users/" . $this->owner->uusername) . "/orgs"; return true; } } public function create(...$args) { $org = new Org($this->url, $this->token, null, $this->owner); if (count($args) > 0) $org->create(...$args); return $org; } /** * Get an organization by indentifier. * * Method will first look through organizations * already loaded. If not found it will return a * new object. * * Method does not ensure the organization in loaded * from Gogs so the user should call `->load()` on * returned element. * * @param string $s * @return Org */ public function get(string $s) { if (($org = $this->by_key($s))) return $org; return new Org($this->url, $this->token, $s, $this->owner); } /** * Search for an organization. * * Params can be an array of * ```php * $orgs->search(array( * "name" => "name", // alt. "q". required * "limit" => 10, // not required, default: 10 * )); * ``` * By now, this method can be intensive, as it will load * every organization and then do a match on each entry. * * @param array $params * @return CollectionResult */ public function search(array $params = array()) { if (!isset($params["name"]) && !isset($params["q"])) throw new Exception\SearchParamException("Missing param |"); $q = isset($params["name"]) ? $params["name"] : $params["q"]; $l = isset($params["limit"]) ? $params["limit"] : 10; $this->load(); $orgs = new CollectionResult(); foreach ($this->all() as $key => $org) { if ($org->search($q)) $orgs->set($org); if ($orgs->len() == $l) break; } return $orgs; } protected function json_set_property($obj) { foreach($obj as $val) { $org = new Org($this->url, $this->token, null, $this->owner); $org->json_set_property($val); $this->add($org, $val->username); } } } }