diff --git a/src/GiteaData.php b/src/GiteaData.php index 19f521b..254c608 100644 --- a/src/GiteaData.php +++ b/src/GiteaData.php @@ -3,12 +3,12 @@ class GiteaData{ protected $data=null; - public function __construct($data=null){ + public function __construct($data=null){ if(!$data){ $data=new stdClass(); } $this->data=$data; - } + } public function __set($k,$v){ $this->data->$k=$v; diff --git a/src/GiteaRepoData.php b/src/GiteaRepoData.php index 6766aa3..acc4df6 100644 --- a/src/GiteaRepoData.php +++ b/src/GiteaRepoData.php @@ -1,19 +1,19 @@ repo=$repo; - parent::__construct($data); - } + public function __construct(Repo $repo,$data){ + $this->repo=$repo; + parent::__construct($data); + } - public function getRepo(){ - return $this->repo; - } + public function getRepo(){ + return $this->repo; + } - public function save(){ - return $this->repo->request($this->url,'PATCH',$this->data); - } + public function save(){ + return $this->repo->request($this->url,'PATCH',$this->data); + } } diff --git a/src/Issue.php b/src/Issue.php index fce3225..b72e64b 100644 --- a/src/Issue.php +++ b/src/Issue.php @@ -1,36 +1,36 @@ getRepo()->request($url, $type, $postFields); + public function request($url, $type='GET', $postFields = null){ + return $this->getRepo()->request($url, $type, $postFields); + } + + public function addLabel($label){ + $args=['labels'=>[$label->id]]; + return $this->request($this->url.'/labels','POST',$args); + } + + public function removeLabel($label){ + $id=$label->id; + return $this->request($this->url."/labels/$id",'DELETE'); + } + + public function addComment($body){ + $args=['body'=>$body]; + return $this->request($this->url.'/comments','POST',$args); + } + + public function hasLabel($label){ + $id=$label->id; + foreach($this->labels as $label){ + if($label->id==$id){ + return true; + } } - - public function addLabel($label){ - $args=['labels'=>[$label->id]]; - return $this->request($this->url.'/labels','POST',$args); - } - - public function removeLabel($label){ - $id=$label->id; - return $this->request($this->url."/labels/$id",'DELETE'); - } - - public function addComment($body){ - $args=['body'=>$body]; - return $this->request($this->url.'/comments','POST',$args); - } - - public function hasLabel($label){ - $id=$label->id; - foreach($this->labels as $label){ - if($label->id==$id){ - return true; - } - } - return false; - } + return false; + } } diff --git a/src/Repo.php b/src/Repo.php index 59a1e53..0fdd6f4 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -1,57 +1,57 @@ client=$client; - $this->user=$user; - $this->repo=$repo; - } + public function __construct(Client $client,$user,$repo){ + $this->client=$client; + $this->user=$user; + $this->repo=$repo; + } - public function request($url, $type='GET', $postFields = null){ - return $this->client->request($url, $type, $postFields); - } + public function request($url, $type='GET', $postFields = null){ + return $this->client->request($url, $type, $postFields); + } - public function forIssues($callback,$args=null){ - $page=1; - while(1){ - $url="repos/{$this->user}/{$this->repo}/issues?page=$page"; - if($args){ - $url.='&'.http_build_query($args); - } - $issues=$this->client->request($url); - if(!$issues) break; - foreach($issues as $data){ - $issue=new Issue($this,$data); - call_user_func($callback,$issue); - } - $page++; - } - } - - public function getLabelByName($name){ - $url="repos/{$this->user}/{$this->repo}/labels"; - $data=$this->client->request($url); - foreach($data as $datum){ - if($datum->name==$name){ - $datum->url=$url."/".$datum->id; // not set by api for some reason (bug?) - return new Label($this,$datum); - } + public function forIssues($callback,$args=null){ + $page=1; + while(1){ + $url="repos/{$this->user}/{$this->repo}/issues?page=$page"; + if($args){ + $url.='&'.http_build_query($args); } - return null; - } + $issues=$this->client->request($url); + if(!$issues) break; + foreach($issues as $data){ + $issue=new Issue($this,$data); + call_user_func($callback,$issue); + } + $page++; + } + } - public function createLabel($args){ - $url="repos/{$this->user}/{$this->repo}/labels"; - $data=$this->client->request($url,'POST',$args); - $data->url=$url."/".$data->id; // not set by api for some reason (bug?) - return new Label($this,$data); - } + public function getLabelByName($name){ + $url="repos/{$this->user}/{$this->repo}/labels"; + $data=$this->client->request($url); + foreach($data as $datum){ + if($datum->name==$name){ + $datum->url=$url."/".$datum->id; // not set by api for some reason (bug?) + return new Label($this,$datum); + } + } + return null; + } - public function createIssue($args){ - $url="repos/{$this->user}/{$this->repo}/issues"; - $data=$this->client->request($url,'POST',$args); - //$data->url=$url."/".$data->id; // not set by api for some reason (bug?) - return new Issue($this,$data); - } + public function createLabel($args){ + $url="repos/{$this->user}/{$this->repo}/labels"; + $data=$this->client->request($url,'POST',$args); + $data->url=$url."/".$data->id; // not set by api for some reason (bug?) + return new Label($this,$data); + } + + public function createIssue($args){ + $url="repos/{$this->user}/{$this->repo}/issues"; + $data=$this->client->request($url,'POST',$args); + //$data->url=$url."/".$data->id; // not set by api for some reason (bug?) + return new Issue($this,$data); + } }