|
@@ -2,105 +2,105 @@
|
|
|
|
|
|
namespace Gogs\API\Request {
|
|
|
|
|
|
-class Repos extends Collection {
|
|
|
+ final class Repos extends Collection {
|
|
|
|
|
|
- protected $owner;
|
|
|
+ protected $owner;
|
|
|
|
|
|
- public function __construct(string $api_url, string $api_token, User $owner = null) {
|
|
|
- $this->owner = $owner;
|
|
|
- parent::__construct($api_url, $api_token);
|
|
|
- }
|
|
|
-
|
|
|
- protected function set_scope(string $method) {
|
|
|
- switch ($method) {
|
|
|
- case "get":
|
|
|
- if ($this->owner instanceof Org)
|
|
|
- $this->scope = "/orgs/" . $this->owner->uusername . "/repos";
|
|
|
- else
|
|
|
- $this->scope = ($this->owner == null || $this->owner->authenticated() ? "/user" : "/users/" . $this->owner->uusername ) . "/repos";
|
|
|
- break;
|
|
|
- case "search":
|
|
|
- $this->scope = "/repos/search";
|
|
|
- break;
|
|
|
- default:
|
|
|
- return false;
|
|
|
+ public function __construct(string $api_url, string $api_token, User $owner = null) {
|
|
|
+ $this->owner = $owner;
|
|
|
+ parent::__construct($api_url, $api_token);
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
- }
|
|
|
+ protected function set_scope(string $method) {
|
|
|
+ switch ($method) {
|
|
|
+ case "get":
|
|
|
+ if ($this->owner instanceof Org)
|
|
|
+ $this->scope = "/orgs/" . $this->owner->uusername . "/repos";
|
|
|
+ else
|
|
|
+ $this->scope = ($this->owner == null || $this->owner->authenticated() ? "/user" : "/users/" . $this->owner->uusername ) . "/repos";
|
|
|
+ break;
|
|
|
+ case "search":
|
|
|
+ $this->scope = "/repos/search";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- public function create(...$args) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- $repo = new Repo($this->url, $this->token, $this->owner);
|
|
|
+ public function create(...$args) {
|
|
|
|
|
|
- if (count($args) > 0)
|
|
|
- $repo->create(...$args);
|
|
|
+ $repo = new Repo($this->url, $this->token, $this->owner);
|
|
|
|
|
|
- return $repo;
|
|
|
- }
|
|
|
+ if (count($args) > 0)
|
|
|
+ $repo->create(...$args);
|
|
|
|
|
|
- public function search(array $params = array()) {
|
|
|
- $scope = substr($this->scope, 1, strpos($this->scope, "/", 1)-1);
|
|
|
+ return $repo;
|
|
|
+ }
|
|
|
|
|
|
- if (!isset($params["name"]) && !isset($params["q"]))
|
|
|
- throw new Exception\SearchParamException("Missing param <name>|<q>");
|
|
|
+ public function search(array $params = array()) {
|
|
|
+ $scope = substr($this->scope, 1, strpos($this->scope, "/", 1)-1);
|
|
|
|
|
|
- if (isset($params["name"])) {
|
|
|
- $params["q"] = $params["name"];
|
|
|
- unset($params["name"]);
|
|
|
- }
|
|
|
+ if (!isset($params["name"]) && !isset($params["q"]))
|
|
|
+ throw new Exception\SearchParamException("Missing param <name>|<q>");
|
|
|
|
|
|
- if (!isset($params["user"]))
|
|
|
- $params["user"] = 0;
|
|
|
-
|
|
|
- if (!isset($params["limit"]))
|
|
|
- $params["limit"] = 10;
|
|
|
-
|
|
|
- $repos = new \Gogs\Lib\Collection();
|
|
|
-
|
|
|
- switch ($scope) {
|
|
|
- case "user":
|
|
|
- case "users":
|
|
|
- case "org":
|
|
|
- $this->load();
|
|
|
-
|
|
|
- foreach($this->all() as $key => $repo) {
|
|
|
- if ($repo->search($params["q"]))
|
|
|
- $repos->set($repo);
|
|
|
- if ($repos->len() == $params["limit"])
|
|
|
- break;
|
|
|
+ if (isset($params["name"])) {
|
|
|
+ $params["q"] = $params["name"];
|
|
|
+ unset($params["name"]);
|
|
|
}
|
|
|
|
|
|
- default:
|
|
|
- $this->set_scope("search");
|
|
|
- $jenc = $this->method_get($params);
|
|
|
- $jdec = $this->json_decode($jenc);
|
|
|
+ if (!isset($params["user"]))
|
|
|
+ $params["user"] = 0;
|
|
|
|
|
|
- foreach($this->json_set_property($jdec) as $key)
|
|
|
- $repos->set($this->by_key($key), $key);
|
|
|
+ if (!isset($params["limit"]))
|
|
|
+ $params["limit"] = 10;
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- return $repos;
|
|
|
- }
|
|
|
+ $repos = new \Gogs\Lib\Collection();
|
|
|
+
|
|
|
+ switch ($scope) {
|
|
|
+ case "user":
|
|
|
+ case "users":
|
|
|
+ case "org":
|
|
|
+ $this->load();
|
|
|
+
|
|
|
+ foreach($this->all() as $key => $repo) {
|
|
|
+ if ($repo->search($params["q"]))
|
|
|
+ $repos->set($repo);
|
|
|
+ if ($repos->len() == $params["limit"])
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- protected function json_set_property($obj) {
|
|
|
- if (isset($obj->data))
|
|
|
- return $this->json_set_property($obj->data);
|
|
|
+ default:
|
|
|
+ $this->set_scope("search");
|
|
|
+ $jenc = $this->method_get($params);
|
|
|
+ $jdec = $this->json_decode($jenc);
|
|
|
|
|
|
- $rnames = array();
|
|
|
+ foreach($this->json_set_property($jdec) as $key)
|
|
|
+ $repos->set($this->by_key($key), $key);
|
|
|
|
|
|
- if (is_array($obj)) {
|
|
|
- foreach ($obj as $key => $val) {
|
|
|
- $repo = new Repo($this->url, $this->token);
|
|
|
- $repo->json_set_property($val);
|
|
|
- $this->add($repo, $repo->rfull_name);
|
|
|
- array_push($rnames, $repo->rfull_name);
|
|
|
}
|
|
|
+
|
|
|
+ return $repos;
|
|
|
}
|
|
|
|
|
|
- return $rnames;
|
|
|
+ protected function json_set_property($obj) {
|
|
|
+ if (isset($obj->data))
|
|
|
+ return $this->json_set_property($obj->data);
|
|
|
+
|
|
|
+ $rnames = array();
|
|
|
+
|
|
|
+ if (is_array($obj)) {
|
|
|
+ foreach ($obj as $key => $val) {
|
|
|
+ $repo = new Repo($this->url, $this->token);
|
|
|
+ $repo->json_set_property($val);
|
|
|
+ $this->add($repo, $repo->rfull_name);
|
|
|
+ array_push($rnames, $repo->rfull_name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $rnames;
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
}
|