Skip to content

Commit 75a3645

Browse files
committed
support custom fields
1 parent ab8e050 commit 75a3645

File tree

7 files changed

+63
-27
lines changed

7 files changed

+63
-27
lines changed

src/Issue/Issue.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,4 @@ public function jsonSerialize()
2727
{
2828
return array_filter(get_object_vars($this));
2929
}
30-
31-
public function addCustomFields($data)
32-
{
33-
if ($this->fields) {
34-
$this->fields->addCustomFields($data);
35-
}
36-
}
3730
}

src/Issue/IssueField.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function jsonSerialize()
2626
return array_filter(get_object_vars($this));
2727
}
2828

29+
public function getCustomFields()
30+
{
31+
return $this->customFields;
32+
}
33+
2934
public function getProjectKey()
3035
{
3136
return $this->project->key;
@@ -189,20 +194,6 @@ public function getIssueType()
189194
return $this->issuetype;
190195
}
191196

192-
/**
193-
* add custom field.
194-
*
195-
* @param array $data
196-
*/
197-
public function addCustomFields($data)
198-
{
199-
foreach ($data as $key => $value) {
200-
if (substr($key, 0, 12) == 'customfield_') {
201-
$this->{$key} = $value;
202-
}
203-
}
204-
}
205-
206197
/**
207198
* set parent issue.
208199
*
@@ -335,4 +326,7 @@ public function setParent(Issue $parent)
335326

336327
/** @var object|null */
337328
public $parent;
329+
330+
/** @var array|null */
331+
public $customFields;
338332
}

src/Issue/IssueService.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public function getIssueFromJSON($json)
1414
$json, new Issue()
1515
);
1616

17-
$issue->addCustomFields($issue->fields);
18-
1917
return $issue;
2018
}
2119

@@ -289,10 +287,6 @@ public function search($jql, $startAt = 0, $maxResults = 15, $fields = [])
289287
$json, new IssueSearchResult()
290288
);
291289

292-
foreach ($result->issues as $ndx => $issue_json) {
293-
$result->getIssue($ndx)->addCustomFields($json->issues[$ndx]->fields);
294-
}
295-
296290
return $result;
297291
}
298292

src/Issue/IssueStatus.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class IssueStatus implements \JsonSerializable
1919
/* @var string */
2020
public $name;
2121

22+
/* @var Statuscategory */
23+
public $statuscategory;
24+
2225
public function jsonSerialize()
2326
{
2427
return array_filter(get_object_vars($this));

src/Issue/Statuscategory.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace JiraRestApi\Issue;
3+
4+
5+
class Statuscategory
6+
{
7+
/* @var string */
8+
public $self;
9+
10+
/* @var string */
11+
public $id;
12+
13+
/* @var string|null */
14+
public $key;
15+
16+
/* @var string */
17+
public $colorName;
18+
19+
/* @var string */
20+
public $name;
21+
}

src/JiraClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public function __construct(ConfigurationInterface $configuration = null, Logger
7474
$this->configuration = $configuration;
7575
$this->json_mapper = new \JsonMapper();
7676

77+
$this->json_mapper->undefinedPropertyHandler = [\JiraRestApi\JsonMapperHelper::class, 'setUndefinedProperty'];
78+
7779
// create logger
7880
if ($logger) {
7981
$this->log = $logger;

src/JsonMapperHelper.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
namespace JiraRestApi;
3+
4+
5+
class JsonMapperHelper
6+
{
7+
/**
8+
* Handle undefined properties during JsonMapper::map()
9+
*
10+
* @param object $object Object that is being filled
11+
* @param string $propName Name of the unknown JSON property
12+
* @param mixed $jsonValue JSON value of the property
13+
*
14+
* @return void
15+
*/
16+
static function setUndefinedProperty($object, $propName, $jsonValue)
17+
{
18+
// If the property is a custom field type, assign a value to the custom Fields array.
19+
if (substr($propName, 0, 12) == 'customfield_') {
20+
if (!empty($jsonValue)) {
21+
$object->{$propName} = $jsonValue;
22+
$object->customFields[$propName] = $jsonValue;
23+
}
24+
} else {
25+
$object->{$propName} = $jsonValue;
26+
}
27+
28+
}
29+
}

0 commit comments

Comments
 (0)