Skip to content

Commit f07119e

Browse files
committed
Merge pull request #16 from Art4/dot-notation
Support for dot.notation
2 parents 54eca6e + f786bfc commit f07119e

21 files changed

+448
-125
lines changed

src/Attributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @see http://jsonapi.org/format/#document-resource-object-attributes
1212
*/
13-
class Attributes extends Meta implements AccessInterface
13+
class Attributes extends Meta
1414
{
1515
/**
1616
* @var FactoryManagerInterface

src/Document.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\MetaTrait;
78
use Art4\JsonApiClient\Utils\LinksTrait;
@@ -14,7 +15,7 @@
1415
*
1516
* @see http://jsonapi.org/format/#document-top-level
1617
*/
17-
class Document implements AccessInterface
18+
class Document extends AccessAbstract
1819
{
1920
use AccessTrait;
2021

@@ -120,7 +121,7 @@ public function __construct($object, FactoryManagerInterface $manager)
120121
* @param string $key The key of the value
121122
* @return bool true if data exists, false if not
122123
*/
123-
public function has($key)
124+
protected function hasValue($key)
124125
{
125126
// data
126127
if ( $key === 'data' and $this->data !== false )
@@ -215,7 +216,7 @@ public function getKeys()
215216
* @param string $key The key of the value
216217
* @return mixed The value
217218
*/
218-
public function get($key)
219+
protected function getValue($key)
219220
{
220221
if ( ! $this->has($key) )
221222
{

src/Error.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\MetaTrait;
78
use Art4\JsonApiClient\Utils\LinksTrait;
@@ -14,7 +15,7 @@
1415
*
1516
* @see http://jsonapi.org/format/#error-objects
1617
*/
17-
class Error implements AccessInterface
18+
class Error extends AccessAbstract
1819
{
1920
use AccessTrait;
2021

@@ -135,7 +136,7 @@ public function __construct($object, FactoryManagerInterface $manager)
135136
* @param string $key The key of the value
136137
* @return bool true if data exists, false if not
137138
*/
138-
public function has($key)
139+
protected function hasValue($key)
139140
{
140141
// id
141142
if ( $key === 'id' and $this->id !== null )
@@ -254,7 +255,7 @@ public function getKeys()
254255
* @param string $key The key of the value
255256
* @return mixed The value
256257
*/
257-
public function get($key)
258+
protected function getValue($key)
258259
{
259260
if ( ! $this->has($key) )
260261
{

src/ErrorCollection.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
78
use Art4\JsonApiClient\Exception\AccessException;
@@ -12,7 +13,7 @@
1213
*
1314
* @see http://jsonapi.org/format/#error-objects
1415
*/
15-
class ErrorCollection implements AccessInterface
16+
class ErrorCollection extends AccessAbstract
1617
{
1718
use AccessTrait;
1819

@@ -61,13 +62,8 @@ public function __construct($errors, FactoryManagerInterface $manager)
6162
* @param string $key The key of the value
6263
* @return bool true if data exists, false if not
6364
*/
64-
public function has($key)
65+
protected function hasValue($key)
6566
{
66-
if ( is_object($key) or is_array($key) )
67-
{
68-
return false;
69-
}
70-
7167
if ( is_string($key) and ! ctype_digit($key) )
7268
{
7369
return false;
@@ -109,7 +105,7 @@ public function getKeys()
109105
* @param string $key The key of the value
110106
* @return mixed The value
111107
*/
112-
public function get($key)
108+
protected function getValue($key)
113109
{
114110
if ( ! $this->has($key) )
115111
{

src/ErrorSource.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
78
use Art4\JsonApiClient\Exception\AccessException;
@@ -12,7 +13,7 @@
1213
*
1314
* @see http://jsonapi.org/format/#error-objects
1415
*/
15-
class ErrorSource implements AccessInterface
16+
class ErrorSource extends AccessAbstract
1617
{
1718
use AccessTrait;
1819

@@ -70,7 +71,7 @@ public function __construct($object, FactoryManagerInterface $manager)
7071
* @param string $key The key of the value
7172
* @return bool true if data exists, false if not
7273
*/
73-
public function has($key)
74+
protected function hasValue($key)
7475
{
7576
// pointer
7677
if ( $key === 'pointer' and $this->pointer !== null )
@@ -117,7 +118,7 @@ public function getKeys()
117118
* @param string $key The key of the value
118119
* @return mixed The value
119120
*/
120-
public function get($key)
121+
protected function getValue($key)
121122
{
122123
if ( ! $this->has($key) )
123124
{

src/Jsonapi.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
78
use Art4\JsonApiClient\Utils\MetaTrait;
@@ -13,7 +14,7 @@
1314
*
1415
* @see http://jsonapi.org/format/#document-jsonapi-object
1516
*/
16-
class Jsonapi implements AccessInterface
17+
class Jsonapi extends AccessAbstract
1718
{
1819
use AccessTrait;
1920

@@ -66,7 +67,7 @@ public function __construct($object, FactoryManagerInterface $manager)
6667
* @param string $key The key of the value
6768
* @return bool true if data exists, false if not
6869
*/
69-
public function has($key)
70+
protected function hasValue($key)
7071
{
7172
// version
7273
if ( $key === 'version' and $this->version !== null )
@@ -113,7 +114,7 @@ public function getKeys()
113114
* @param string $key The key of the value
114115
* @return mixed The value
115116
*/
116-
public function get($key)
117+
protected function getValue($key)
117118
{
118119
if ( ! $this->has($key) )
119120
{

src/Link.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
78
use Art4\JsonApiClient\Utils\MetaTrait;
@@ -13,7 +14,7 @@
1314
*
1415
* @see http://jsonapi.org/format/#document-links
1516
*/
16-
class Link implements AccessInterface
17+
class Link extends AccessAbstract
1718
{
1819
use AccessTrait;
1920

@@ -64,7 +65,7 @@ public function __construct($object, FactoryManagerInterface $manager)
6465
*
6566
* @return bool true if the link is set, false if not
6667
*/
67-
public function has($key)
68+
protected function hasValue($key)
6869
{
6970
if ( $key === 'meta' )
7071
{
@@ -98,7 +99,7 @@ public function getKeys()
9899
*
99100
* @return string|Link The link
100101
*/
101-
public function get($key)
102+
protected function getValue($key)
102103
{
103104
if ( ! $this->has($key) )
104105
{

src/Meta.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
78
use Art4\JsonApiClient\Exception\AccessException;
@@ -12,7 +13,7 @@
1213
*
1314
* @see http://jsonapi.org/format/#document-meta
1415
*/
15-
class Meta implements AccessInterface
16+
class Meta extends AccessAbstract
1617
{
1718
use AccessTrait;
1819

@@ -61,7 +62,7 @@ public function __construct($object, FactoryManagerInterface $manager)
6162
*
6263
* @return bool true if the value is set, false if not
6364
*/
64-
public function has($key)
65+
protected function hasValue($key)
6566
{
6667
return array_key_exists($key, $this->_data);
6768
}
@@ -83,7 +84,7 @@ public function getKeys()
8384
*
8485
* @return mixed The value
8586
*/
86-
public function get($key)
87+
protected function getValue($key)
8788
{
8889
if ( ! $this->has($key) )
8990
{

src/Relationship.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\MetaTrait;
78
use Art4\JsonApiClient\Utils\LinksTrait;
@@ -14,7 +15,7 @@
1415
*
1516
* @see http://jsonapi.org/format/#document-resource-object-relationships
1617
*/
17-
class Relationship implements AccessInterface
18+
class Relationship extends AccessAbstract
1819
{
1920
use AccessTrait;
2021

@@ -80,7 +81,7 @@ public function __construct($object, FactoryManagerInterface $manager)
8081
* @param string $key The key of the value
8182
* @return bool true if data exists, false if not
8283
*/
83-
public function has($key)
84+
protected function hasValue($key)
8485
{
8586
// links
8687
if ( $key === 'links' and $this->hasLinks() )
@@ -139,7 +140,7 @@ public function getKeys()
139140
* @param string $key The key of the value
140141
* @return mixed The value
141142
*/
142-
public function get($key)
143+
protected function getValue($key)
143144
{
144145
if ( ! $this->has($key) )
145146
{

src/RelationshipCollection.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessAbstract;
56
use Art4\JsonApiClient\Utils\AccessTrait;
67
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
78
use Art4\JsonApiClient\Resource\ResourceInterface;
@@ -13,7 +14,7 @@
1314
*
1415
* @see http://jsonapi.org/format/#document-resource-object-relationships
1516
*/
16-
class RelationshipCollection implements AccessInterface
17+
class RelationshipCollection extends AccessAbstract
1718
{
1819
use AccessTrait;
1920

@@ -75,7 +76,7 @@ public function __construct($object, FactoryManagerInterface $manager, ResourceI
7576
*
7677
* @return bool true if the value is set, false if not
7778
*/
78-
public function has($key)
79+
protected function hasValue($key)
7980
{
8081
return array_key_exists($key, $this->_data);
8182
}
@@ -93,18 +94,18 @@ public function getKeys()
9394
/**
9495
* Get a value
9596
*
96-
* @param string $name The Name
97+
* @param string $key The Key
9798
*
9899
* @return mixed The value
99100
*/
100-
public function get($name)
101+
protected function getValue($key)
101102
{
102-
if ( ! $this->has($name) )
103+
if ( ! $this->has($key) )
103104
{
104-
throw new AccessException('"' . $name . '" doesn\'t exist in this relationship collection.');
105+
throw new AccessException('"' . $key . '" doesn\'t exist in this relationship collection.');
105106
}
106107

107-
return $this->_data[$name];
108+
return $this->_data[$key];
108109
}
109110

110111
/**

src/Resource/Collection.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Art4\JsonApiClient\Resource;
44

5-
use Art4\JsonApiClient\AccessInterface;
5+
use Art4\JsonApiClient\Utils\AccessAbstract;
66
use Art4\JsonApiClient\Utils\AccessTrait;
77
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
88
use Art4\JsonApiClient\Exception\AccessException;
@@ -13,7 +13,7 @@
1313
*
1414
* @see http://jsonapi.org/format/#document-resource-objects
1515
*/
16-
class Collection implements AccessInterface, ResourceInterface
16+
class Collection extends AccessAbstract implements ResourceInterface
1717
{
1818
use AccessTrait;
1919

@@ -57,13 +57,8 @@ public function __construct($resources, FactoryManagerInterface $manager)
5757
* @param string $key The key of the value
5858
* @return bool true if data exists, false if not
5959
*/
60-
public function has($key)
60+
protected function hasValue($key)
6161
{
62-
if ( is_object($key) or is_array($key) )
63-
{
64-
return false;
65-
}
66-
6762
if ( is_string($key) and ! ctype_digit($key) )
6863
{
6964
return false;
@@ -107,7 +102,7 @@ public function getKeys()
107102
* @param string $key The key of the value
108103
* @return mixed The value
109104
*/
110-
public function get($key)
105+
protected function getValue($key)
111106
{
112107
if ( ! $this->has($key) )
113108
{

0 commit comments

Comments
 (0)