owner = $owner; $this->name = $name; } /** * @see Base * @throws Exception\RequestErrorException on missing repo or user data */ protected function set_scope(string $method) { switch ($method) { case "create": if (!$this->owner->authenticated() && empty($this->owner->username)) throw new Exception\RequestErrorException("Missing userdata of unauthorized user 'username'"); if ($this->owner instanceof Org) $this->scope = "/org/" . $this->owner->username . "/repos"; elseif ($this->owner->authenticated()) $this->scope = "/user/repos"; else $this->scope = "/admin/users/" . $this->owner->username . "/repos"; break; case "delete": if (empty($this->owner->username)) throw new Exception\RequestErrorException("Missing userdata 'username'"); $this->scope = "/repos/" . $this->owner->username . "/" . $this->name; break; case "get": case "load": if (empty($this->owner->username) && empty($this->full_name)) throw new Exception\RequestErrorException("Missing userdata 'username' and/or 'full_name'"); $this->scope = "/repos/" . ($this->owner ? $this->owner->username . "/" . $this->name : $this->full_name); break; default: return false; } return true; } /** * @see Base */ protected function json_set_property($obj) { foreach($obj as $key => $val) { if ($this->property_exists($key)) { switch ($key) { case "owner": if (!$this->owner) { $user = new User($this->url, $this->token); $user->json_set_property($val); $this->{$key} = $user; } break; default: $this->{$key} = $val; } } } $this->loaded = true; return true; } /** * @see Base */ public function search(string $q) { $searchable = sprintf("%s %s", $this->name, $this->description); return stripos($searchable, $q) !== false; } /** * Create a new repo * * Valid paramters: * * 1. name * 2. description * 3. private (default: false) * 4. auto_init (default: false) * 5. gitignore * 6. license * 7. readme (default: "Default") * * This reflects the API v1 documentation, but is in an order * where the required fields are first. * * @param ...$args The parameter values * @return bool */ 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); } } } ?>