Skip to content

Commit 1ffade4

Browse files
authored
Merge pull request #10 from larruda/master
Fix PHP 7 issue and mismatch with ProjectIssue API response.
2 parents cf08062 + 80a8936 commit 1ffade4

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/DrupalClient.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ public function getNode($id) {
5656
return $this->getResource('node', $id);
5757
}
5858

59+
/**
60+
* @param $id
61+
* @return \EclipseGc\DrupalOrg\Api\Resources\Node\ProjectIssue;
62+
*/
63+
public function getProjectIssue($id) {
64+
return $this->getResource('project_issue', $id);
65+
}
66+
5967
/**
6068
* @param $id
6169
* @return \EclipseGc\DrupalOrg\Api\Resources\TaxonomyTerm
6270
*/
6371
public function getTaxonomyTerm($id) {
6472
return $this->getResource('taxonomy_term', $id);
6573
}
66-
}
74+
}

src/Factory.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Factory implements FactoryInterface {
1414
'user' => '\EclipseGc\DrupalOrg\Api\Resources\User',
1515
'node' => '\EclipseGc\DrupalOrg\Api\Resources\Node',
1616
'taxonomy_term' => '\EclipseGc\DrupalOrg\Api\Resources\TaxonomyTerm',
17+
'project_issue' => '\EclipseGc\DrupalOrg\Api\Resources\Node\ProjectIssue',
1718
);
1819

1920
function __construct(Client $client) {
@@ -29,6 +30,7 @@ public function getObjectTypeClass($type, array $data) {
2930
}
3031

3132
public function createObjectType($type, array $data = array()) {
33+
$data = (isset($data['list'])) ? $data['list'][0] : $data;
3234
$objectClass = $this->getObjectTypeClass($type, $data);
3335
$reflector = new \ReflectionClass($objectClass);
3436
if (!isset($data['factory'])) {
@@ -51,7 +53,14 @@ public function createObjectType($type, array $data = array()) {
5153
* @throws \Exception
5254
*/
5355
public function request($entity_type, $id) {
54-
$request = $this->client()->get(['{entity_type}/{id}', ['entity_type' => $entity_type, 'id' => $id]]);
56+
switch ($entity_type) {
57+
case 'project_issue':
58+
$request = $this->client()->get(['node.json?type={entity_type}&nid={id}', ['entity_type' => $entity_type, 'id' => $id]]);
59+
break;
60+
default:
61+
$request = $this->client()->get(['{entity_type}/{id}', ['entity_type' => $entity_type, 'id' => $id]]);
62+
break;
63+
}
5564
if ($request->getStatusCode() != 200) {
5665
throw new \Exception(sprintf('Status code was not OK. %d returned instead.', $request->getStatusCode()));
5766
}
@@ -76,4 +85,4 @@ protected function client(Client $new_client = NULL) {
7685
return $client;
7786
}
7887

79-
}
88+
}

src/Resources/GetResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait GetResource {
1313
*/
1414
protected $factory;
1515

16-
protected function getResource($resource_type, $id) {
16+
public function getResource($resource_type, $id) {
1717
$response = $this->factory->request($resource_type, $id);
1818
return $this->factory->createObjectType($resource_type, $response->json());
1919
}

src/Resources/Node/ProjectIssue.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ class ProjectIssue extends Node {
3636

3737
protected $issueVersion;
3838

39-
public function __construct(FactoryInterface $factory, $body, $taxonomy_vocabulary_9, $field_issue_status, $field_issue_priority, $field_issue_category, $field_issue_component, $field_issue_assigned, $field_project, $field_issue_files, $field_issue_parent, $field_issue_related, $field_issue_version, $nid, $vid, $is_new, $type, $title, $language, $url, $edit_url, $status, $promote, $sticky, $created, $changed, $author, $book_ancestors, $comment, $comments, $comment_count, $comment_count_new, $has_new_content, $last_comment_timestamp) {
39+
public function __construct($taxonomy_vocabulary_9, $body, $field_issue_status, $field_issue_priority, $field_issue_category, $field_issue_component, $field_project, $field_issue_files, $field_issue_related, $field_issue_version, $field_issue_credit, $flag_drupalorg_node_spam_user, $flag_project_issue_follow_user, $nid, $vid, $is_new, $type, $title, $language, $url, $edit_url, $status, $promote, $sticky, $created, $changed, $author, $book_ancestors, $comment, $comments, $comment_count, $comment_count_new, $feed_nid, $flag_flag_tracker_follow_user, $has_new_content, $last_comment_timestamp, FactoryInterface $factory) {
4040
$this->taxonomy = $taxonomy_vocabulary_9;
4141
$this->issueStatus = $field_issue_status;
4242
$this->issuePriority = $field_issue_priority;
4343
$this->issueCategory = $field_issue_category;
4444
$this->issueComponent = $field_issue_component;
45-
$this->issueAssigned = $field_issue_assigned;
4645
$this->project = $field_project;
4746
$this->issueFiles = $field_issue_files;
48-
$this->issueParent = $field_issue_parent;
4947
$this->issueRelated = $field_issue_related;
5048
$this->issueVersion = $field_issue_version;
5149
$this->bookAncestors = $book_ancestors;

0 commit comments

Comments
 (0)