Skip to content

Commit 19004c4

Browse files
committed
Merge branch 'hotfix/126'
Close #126
2 parents bcfd3eb + df5ede0 commit 19004c4

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ All notable changes to this project will be documented in this file, in reverse
1313
and HHVM.
1414
- [#107](https://github.com/phly/PhlyRestfully/pull/107) suggests using
1515
zfr/zfr-cors to provide CORS support for your API.
16+
- [#126](https://github.com/phly/PhlyRestfully/pull/126) adds an `__isset()`
17+
method to `HalResource`, ensuring you can test for the identifier and/or
18+
resource (e.g., via `isset($halResource->id)`).
1619

1720
### Deprecated
1821

src/HalResource.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public function __construct($resource, $id)
3434
$this->id = $id;
3535
}
3636

37+
/**
38+
* Check if properties are set
39+
*
40+
* @param string $name
41+
* @throws Exception\InvalidArgumentException
42+
* @return mixed
43+
*/
44+
public function __isset($name)
45+
{
46+
return in_array(strtolower($name), ['resource', 'id'], true);
47+
}
48+
3749
/**
3850
* Retrieve properties
3951
*
@@ -42,19 +54,14 @@ public function __construct($resource, $id)
4254
*/
4355
public function __get($name)
4456
{
45-
$names = [
46-
'resource' => 'resource',
47-
'id' => 'id',
48-
];
4957
$name = strtolower($name);
50-
if (!in_array($name, array_keys($names))) {
58+
if (! $this->__isset($name)) {
5159
throw new Exception\InvalidArgumentException(sprintf(
5260
'Invalid property name "%s"',
5361
$name
5462
));
5563
}
56-
$prop = $names[$name];
57-
return $this->{$prop};
64+
return $this->{$name};
5865
}
5966

6067
/**

0 commit comments

Comments
 (0)