Skip to content

Commit 3e3bdef

Browse files
committed
Major refactoring of underlying object model for performance reasons.
- Still requires further refactoring.
1 parent f83bedc commit 3e3bdef

30 files changed

+648
-2158
lines changed

src/AbstractDefinedCollection.php renamed to src/AbstractObjectModel.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,28 @@
1717
*/
1818

1919
/**
20-
* Class AbstractResponseModel
21-
* @package DCarbone\PHPConsulAPI\Base
20+
* Class AbstractObjectModel
21+
* @package DCarbone\PHPConsulAPI
2222
*/
23-
abstract class AbstractDefinedCollection extends AbstractCollection
23+
abstract class AbstractObjectModel
2424
{
25-
/** @var array */
26-
protected $_definition = array();
27-
2825
/**
29-
* AbstractConsulConfig constructor.
26+
* AbstractObjectModel constructor.
3027
* @param array $data
3128
*/
3229
public function __construct(array $data = array())
3330
{
34-
$this->_definition = $this->getDefinition();
35-
parent::__construct($data + $this->_definition);
31+
foreach($data as $k => $v)
32+
{
33+
$this->{$k} = $v;
34+
}
3635
}
3736

3837
/**
39-
* @return array
38+
* @return string
4039
*/
41-
abstract protected function getDefinition();
40+
public function __toString()
41+
{
42+
return get_class($this);
43+
}
4244
}

src/AbstractDefinedStrictCollection.php renamed to src/AbstractStrictCollection.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,29 @@
1717
*/
1818

1919
/**
20-
* Class AbstractDefinedCollection
21-
* @package DCarbone\PHPConsulAPI\Base
20+
* Class AbstractStrictCollection
21+
* @package DCarbone\PHPConsulAPI
2222
*/
23-
abstract class AbstractDefinedStrictCollection extends AbstractDefinedCollection
23+
abstract class AbstractStrictCollection extends AbstractCollection
2424
{
25+
/** @var array */
26+
protected $_definition = array();
27+
28+
/**
29+
* AbstractConsulConfig constructor.
30+
* @param array $data
31+
*/
32+
public function __construct(array $data = array())
33+
{
34+
$this->_definition = $this->getDefinition();
35+
parent::__construct($data + $this->_definition);
36+
}
37+
38+
/**
39+
* @return array
40+
*/
41+
abstract protected function getDefinition();
42+
2543
/**
2644
* Whether a offset exists
2745
* @link http://php.net/manual/en/arrayaccess.offsetexists.php

src/Agent/AgentCheck.php

Lines changed: 19 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,100 +16,36 @@
1616
limitations under the License.
1717
*/
1818

19-
use DCarbone\PHPConsulAPI\AbstractDefinedCollection;
19+
use DCarbone\PHPConsulAPI\AbstractObjectModel;
2020

2121
/**
2222
* Class AgentCheck
2323
* @package DCarbone\PHPConsulAPI\Agent
2424
*/
25-
class AgentCheck extends AbstractDefinedCollection
25+
class AgentCheck extends AbstractObjectModel
2626
{
27-
/**
28-
* @return array
29-
*/
30-
protected function getDefinition()
31-
{
32-
return array(
33-
'Node' => null,
34-
'CheckID' => null,
35-
'Name' => null,
36-
'Status' => null,
37-
'Notes' => null,
38-
'Output' => null,
39-
'ServiceID' => null,
40-
'ServiceName' => null
41-
);
42-
}
43-
44-
/**
45-
* @return string
46-
*/
47-
public function getNode()
48-
{
49-
return $this['Node'];
50-
}
51-
52-
/**
53-
* @return string
54-
*/
55-
public function getCheckID()
56-
{
57-
return $this['CheckID'];
58-
}
59-
60-
/**
61-
* @return string
62-
*/
63-
public function getName()
64-
{
65-
return $this['Name'];
66-
}
67-
68-
/**
69-
* @return string
70-
*/
71-
public function getStatus()
72-
{
73-
return $this['Status'];
74-
}
75-
76-
/**
77-
* @return string
78-
*/
79-
public function getNotes()
80-
{
81-
return $this['Nodes'];
82-
}
83-
84-
/**
85-
* @return string
86-
*/
87-
public function getOutput()
88-
{
89-
return $this['Output'];
90-
}
91-
92-
/**
93-
* @return string
94-
*/
95-
public function getServiceID()
96-
{
97-
return $this['ServiceID'];
98-
}
99-
100-
/**
101-
* @return string
102-
*/
103-
public function getServiceName()
104-
{
105-
return $this['ServiceName'];
106-
}
27+
/** @var string */
28+
public $Node = '';
29+
/** @var string */
30+
public $CheckID = '';
31+
/** @var string */
32+
public $Name = '';
33+
/** @var string */
34+
public $Status = '';
35+
/** @var string */
36+
public $Notes = '';
37+
/** @var string */
38+
public $Output = '';
39+
/** @var string */
40+
public $ServiceID = '';
41+
/** @var string */
42+
public $ServiceName = '';
10743

10844
/**
10945
* @return string
11046
*/
11147
public function __toString()
11248
{
113-
return (string)$this['CheckID'];
49+
return (string)$this->CheckID;
11450
}
11551
}

0 commit comments

Comments
 (0)