refactor! v1.1
This commit is contained in:
@@ -1,25 +1,15 @@
|
||||
<?php
|
||||
class GiteaData{
|
||||
|
||||
private $data=null;
|
||||
protected $data=null;
|
||||
|
||||
public function __construct(Repo $repo,$data){
|
||||
$this->repo=$repo;
|
||||
$this->data=$data;
|
||||
public function __construct($data=null){
|
||||
if(!$data){
|
||||
$data=new stdClass();
|
||||
}
|
||||
$this->data=$data;
|
||||
}
|
||||
|
||||
public function save(){
|
||||
return $this->request($this->data->url,'PATCH',$this->data);
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getRepo(){
|
||||
return $this->repo;
|
||||
}
|
||||
|
||||
public function __set($k,$v){
|
||||
$this->data->$k=$v;
|
||||
}
|
||||
|
19
src/GiteaRepoData.php
Normal file
19
src/GiteaRepoData.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
class GiteaRepoData extends GiteaData{
|
||||
|
||||
private $repo;
|
||||
|
||||
public function __construct(Repo $repo,$data){
|
||||
$this->repo=$repo;
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
public function getRepo(){
|
||||
return $this->repo;
|
||||
}
|
||||
|
||||
public function save(){
|
||||
return $this->repo->request($this->url,'PATCH',$this->data);
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +1,32 @@
|
||||
<?php
|
||||
class Issue{
|
||||
class Issue extends GiteaRepoData{
|
||||
|
||||
public function __construct(Repo $repo,$data){
|
||||
$this->repo=$repo;
|
||||
$this->data=$data;
|
||||
parent::__construct($repo,$data);
|
||||
}
|
||||
|
||||
public function request($url, $type='GET', $postFields = null){
|
||||
return $this->repo->request($url, $type, $postFields);
|
||||
return $this->getRepo()->request($url, $type, $postFields);
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getRepo(){
|
||||
return $this->repo;
|
||||
}
|
||||
|
||||
public function save(){
|
||||
return $this->request($this->data->url,'PATCH',$this->data);
|
||||
}
|
||||
|
||||
public function addLabel($label){
|
||||
$args=['labels'=>[$label->getData()->id]];
|
||||
return $this->request($this->data->url.'/labels','POST',$args);
|
||||
$args=['labels'=>[$label->id]];
|
||||
return $this->request($this->url.'/labels','POST',$args);
|
||||
}
|
||||
|
||||
public function removeLabel($label){
|
||||
$id=$label->getData()->id;
|
||||
return $this->request($this->data->url."/labels/$id",'DELETE');
|
||||
$id=$label->id;
|
||||
return $this->request($this->url."/labels/$id",'DELETE');
|
||||
}
|
||||
|
||||
public function addComment($body){
|
||||
$args=['body'=>$body];
|
||||
return $this->request($this->data->url.'/comments','POST',$args);
|
||||
return $this->request($this->url.'/comments','POST',$args);
|
||||
}
|
||||
|
||||
public function hasLabel($label){
|
||||
$id=$label->getData()->id;
|
||||
foreach($this->data->labels as $label){
|
||||
$id=$label->id;
|
||||
foreach($this->labels as $label){
|
||||
if($label->id==$id){
|
||||
return true;
|
||||
}
|
||||
|
@@ -1,17 +1,4 @@
|
||||
<?php
|
||||
class Label{
|
||||
|
||||
public function __construct(Repo $repo,$data){
|
||||
$this->repo=$repo;
|
||||
$this->data=$data;
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getRepo(){
|
||||
return $this->repo;
|
||||
}
|
||||
class Label extends GiteaRepoData{
|
||||
|
||||
}
|
||||
|
@@ -33,10 +33,18 @@ class Repo{
|
||||
$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 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user