rowner = $owner; $this->rname = $name; parent::__construct($api_url, $api_token); } protected function set_scope(string $method) { switch ($method) { case "create": if ($this->rowner instanceof Org) $this->scope = "/org/" . $this->rowner->uusername . "/repos"; elseif ($this->rowner->authenticated()) $this->scope = "/user/repos"; else $this->scope = "/admin/users/" . $this->rowner->uusername . "/repos"; break; case "delete": $this->scope = "/repos/" . $this->rowner->uusername . "/" . $this->rname; break; case "get": $this->scope = "/repos/" . ($this->rowner ? $this->rowner->uusername . "/" . $this->rname : $this->rfull_name); break; default: return false; } return true; } protected function json_set_property($obj) { foreach($obj as $key => $val) { $key = 'r' . $key; if (property_exists($this, $key)) { switch ($key) { case 'rowner': if (!$this->rowner) { $user = new User($this->url, $this->token); $user->json_set_property($val); $this->{$key} = $user; } break; default: $this->{$key} = $val; } } } $this->loaded = true; } public function search(string $q) { $searchable = sprintf("%s %s", $this->rname, $this->rdescription); return stripos($searchable, $q) !== false; } public function create(...$args) { $params = array( "name" => isset($args[0]) && is_string($args[0]) ? $args[0] : null, "description" => isset($args[1]) && is_string($args[1]) ? $args[1] : null, "private" => isset($args[2]) && is_bool($args[2]) ? $args[2] : false, "auto_init" => isset($args[3]) && is_bool($args[3]) ? $args[3] : false, "gitignores" => isset($args[4]) && is_string($args[4]) ? $args[4] : null, "licence" => isset($args[5]) && is_string($args[5]) ? $args[5] : null, "readme" => isset($args[6]) && is_string($args[6]) ? $args[6] : "Default" ); $params = array_filter($params, function($val) { return $val != null; }); parent::create($params); } } } ?>