Skip to content

Commit 1aa72bf

Browse files
committed
Allowed Client to be passed as a construct parameter
1 parent d236f41 commit 1aa72bf

File tree

14 files changed

+57
-37
lines changed

14 files changed

+57
-37
lines changed

lib/Gitlab/Model/AbstractModel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public function getClient()
1919

2020
public function setClient(Client $client)
2121
{
22-
$this->_client = $client;
22+
if (null !== $client) {
23+
$this->_client = $client;
24+
}
2325

2426
return $this;
2527
}

lib/Gitlab/Model/Branch.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class Branch extends AbstractModel
1515

1616
public static function fromArray(Client $client, Project $project, array $data)
1717
{
18-
$branch = new Branch($project, $data['name']);
19-
$branch->setClient($client);
18+
$branch = new Branch($project, $data['name'], $client);
2019

2120
if (isset($data['commit'])) {
2221
$data['commit'] = Commit::fromArray($client, $project, $data['commit']);
@@ -25,8 +24,10 @@ public static function fromArray(Client $client, Project $project, array $data)
2524
return $branch->hydrate($data);
2625
}
2726

28-
public function __construct(Project $project, $name = null)
27+
public function __construct(Project $project, $name = null, Client $client = null)
2928
{
29+
$this->setClient($client);
30+
3031
$this->project = $project;
3132
$this->name = $name;
3233
}

lib/Gitlab/Model/Commit.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class Commit extends AbstractModel
2525

2626
public static function fromArray(Client $client, Project $project, array $data)
2727
{
28-
$commit = new Commit($project, $data['id']);
29-
$commit->setClient($client);
28+
$commit = new Commit($project, $data['id'], $client);
3029

3130
if (isset($data['parents'])) {
3231
$parents = array();
@@ -48,8 +47,10 @@ public static function fromArray(Client $client, Project $project, array $data)
4847
return $commit->hydrate($data);
4948
}
5049

51-
public function __construct(Project $project, $id = null)
50+
public function __construct(Project $project, $id = null, Client $client = null)
5251
{
52+
$this->setClient($client);
53+
5354
$this->project = $project;
5455
$this->id = $id;
5556
}

lib/Gitlab/Model/Group.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ class Group extends AbstractModel
1616

1717
public static function fromArray(Client $client, array $data)
1818
{
19-
$group = new Group($data['id']);
20-
$group->setClient($client);
19+
$group = new Group($data['id'], $client);
2120

2221
if (isset($data['projects'])) {
2322
$projects = array();
@@ -37,8 +36,10 @@ public static function create(Client $client, $name, $path)
3736
return Group::fromArray($client, $data);
3837
}
3938

40-
public function __construct($id)
39+
public function __construct($id, Client $client = null)
4140
{
41+
$this->setClient($client);
42+
4243
$this->id = $id;
4344
}
4445

lib/Gitlab/Model/Hook.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class Hook extends AbstractModel
1414

1515
public static function fromArray(Client $client, array $data)
1616
{
17-
$hook = new Hook($data['id']);
18-
$hook->setClient($client);
17+
$hook = new Hook($data['id'], $client);
1918

2019
return $hook->hydrate($data);
2120
}
@@ -27,8 +26,10 @@ public static function create(Client $client, $url)
2726
return Hook::fromArray($client, $data);
2827
}
2928

30-
public function __construct($id)
29+
public function __construct($id, Client $client = null)
3130
{
31+
$this->setClient($client);
32+
3233
$this->id = $id;
3334
}
3435

lib/Gitlab/Model/Issue.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class Issue extends AbstractModel
2424

2525
public static function fromArray(Client $client, Project $project, array $data)
2626
{
27-
$issue = new Issue($project, $data['id']);
28-
$issue->setClient($client);
27+
$issue = new Issue($project, $data['id'], $client);
2928

3029
if (isset($data['author'])) {
3130
$data['author'] = User::fromArray($client, $data['author']);
@@ -38,8 +37,10 @@ public static function fromArray(Client $client, Project $project, array $data)
3837
return $issue->hydrate($data);
3938
}
4039

41-
public function __construct(Project $project, $id = null)
40+
public function __construct(Project $project, $id = null, Client $client = null)
4241
{
42+
$this->setClient($client);
43+
4344
$this->project = $project;
4445
$this->id = $id;
4546
}

lib/Gitlab/Model/Key.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ class Key extends AbstractModel
1515

1616
public static function fromArray(Client $client, array $data)
1717
{
18-
$key = new Key();
19-
$key->setClient($client);
18+
$key = new Key($client);
2019

2120
return $key->hydrate($data);
2221
}
22+
23+
public function __construct(Client $client = null)
24+
{
25+
$this->setClient($client);
26+
}
2327
}

lib/Gitlab/Model/MergeRequest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class MergeRequest extends AbstractModel
2121

2222
public static function fromArray(Client $client, Project $project, array $data)
2323
{
24-
$mr = new MergeRequest($project, $data['id']);
25-
$mr->setClient($client);
24+
$mr = new MergeRequest($project, $data['id'], $client);
2625

2726
if (isset($data['author'])) {
2827
$data['author'] = User::fromArray($client, $data['author']);
@@ -35,8 +34,10 @@ public static function fromArray(Client $client, Project $project, array $data)
3534
return $mr->hydrate($data);
3635
}
3736

38-
public function __construct(Project $project, $id = null)
37+
public function __construct(Project $project, $id = null, Client $client = null)
3938
{
39+
$this->setClient($client);
40+
4041
$this->project = $project;
4142
$this->id = $id;
4243
}

lib/Gitlab/Model/Milestone.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ class Milestone extends AbstractModel
2121

2222
public static function fromArray(Client $client, Project $project, array $data)
2323
{
24-
$milestone = new Milestone($project, $data['id']);
25-
$milestone->setClient($client);
24+
$milestone = new Milestone($project, $data['id'], $client);
2625

2726
return $milestone->hydrate($data);
2827
}
2928

30-
public function __construct(Project $project, $id)
29+
public function __construct(Project $project, $id, Client $client = null)
3130
{
31+
$this->setClient($client);
32+
3233
$this->id = $id;
3334
$this->project = $project;
3435
}

lib/Gitlab/Model/Note.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class Note extends AbstractModel
1919

2020
public static function fromArray(Client $client, $type, array $data)
2121
{
22-
$comment = new Note($type);
23-
$comment->setClient($client);
22+
$comment = new Note($type, $data['id'], $client);
2423

2524
if (isset($data['author'])) {
2625
$data['author'] = User::fromArray($client, $data['author']);
@@ -29,11 +28,12 @@ public static function fromArray(Client $client, $type, array $data)
2928
return $comment->hydrate($data);
3029
}
3130

32-
public function __construct($type, $id = null)
31+
public function __construct($type, $id = null, Client $client = null)
3332
{
33+
$this->setClient($client);
34+
3435
$this->parent_type = get_class($type);
3536
$this->parent = $type;
36-
3737
$this->id = $id;
3838
}
3939

0 commit comments

Comments
 (0)