1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JiraRestApi\Component; |
4
|
|
|
|
5
|
|
|
use JiraRestApi\JiraException; |
6
|
|
|
use JiraRestApi\Project\Component; |
7
|
|
|
|
8
|
|
|
class ComponentService extends \JiraRestApi\JiraClient |
9
|
|
|
{ |
10
|
|
|
private $uri = '/component'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Function to create a new compoonent. |
14
|
|
|
* |
15
|
|
|
* @param Component|array $component |
16
|
|
|
* |
17
|
|
|
* @throws \JiraRestApi\JiraException |
18
|
|
|
* @throws \JsonMapper_Exception |
19
|
|
|
* |
20
|
|
|
* @return Component class |
21
|
|
|
*/ |
22
|
|
|
public function create($component) |
23
|
|
|
{ |
24
|
|
|
$data = json_encode($component); |
25
|
|
|
|
26
|
|
|
$this->log->info("Create Component=\n".$data); |
27
|
|
|
|
28
|
|
|
$ret = $this->exec($this->uri, $data, 'POST'); |
29
|
|
|
|
30
|
|
|
return $this->json_mapper->map( |
31
|
|
|
json_decode($ret), |
32
|
|
|
new Component() |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* get component. |
38
|
|
|
* |
39
|
|
|
* @param $id component id |
40
|
|
|
* |
41
|
|
|
* @return Component |
42
|
|
|
*/ |
43
|
|
|
public function get($id) |
44
|
|
|
{ |
45
|
|
|
$ret = $this->exec($this->uri.'/'.$id); |
46
|
|
|
|
47
|
|
|
$this->log->info('Result='.$ret); |
48
|
|
|
|
49
|
|
|
return $this->json_mapper->map( |
50
|
|
|
json_decode($ret), |
51
|
|
|
new Component() |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Component $component |
57
|
|
|
* |
58
|
|
|
* @throws JiraException |
59
|
|
|
* |
60
|
|
|
* @return Component |
61
|
|
|
*/ |
62
|
|
|
public function update(Component $component) |
63
|
|
|
{ |
64
|
|
|
if (!$component->id || !is_numeric($component->id)) { |
65
|
|
|
throw new JiraException($component->id.' is not a valid component id.'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$data = json_encode($component); |
69
|
|
|
$ret = $this->exec($this->uri.'/'.$component->id, $data, 'PUT'); |
70
|
|
|
|
71
|
|
|
return $this->json_mapper->map( |
72
|
|
|
json_decode($ret), |
73
|
|
|
new Component() |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Component $component |
79
|
|
|
* @param Component|false $moveIssuesTo |
80
|
|
|
* |
81
|
|
|
* @throws JiraException |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function delete(Component $component, $moveIssuesTo = false) |
86
|
|
|
{ |
87
|
|
|
if (!$component->id || !is_numeric($component->id)) { |
88
|
|
|
throw new JiraException($component->id.' is not a valid component id.'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$data = []; |
92
|
|
|
$paramArray = []; |
93
|
|
|
|
94
|
|
|
if ($moveIssuesTo && $moveIssuesTo instanceof Component) { |
95
|
|
|
$paramArray['moveIssuesTo'] = $moveIssuesTo->id; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$ret = $this->exec($this->uri.'/'.$component->id.$this->toHttpQueryParameter($paramArray), json_encode($data), 'DELETE'); |
99
|
|
|
|
100
|
|
|
return $ret; |
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|