Skip to content

Commit

Permalink
Merge branch 'hotfix/126'
Browse files Browse the repository at this point in the history
Close #126
  • Loading branch information
weierophinney committed May 26, 2016
2 parents bcfd3eb + df5ede0 commit 19004c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ All notable changes to this project will be documented in this file, in reverse
and HHVM.
- [#107](https://github.com/phly/PhlyRestfully/pull/107) suggests using
zfr/zfr-cors to provide CORS support for your API.
- [#126](https://github.com/phly/PhlyRestfully/pull/126) adds an `__isset()`
method to `HalResource`, ensuring you can test for the identifier and/or
resource (e.g., via `isset($halResource->id)`).

### Deprecated

Expand Down
21 changes: 14 additions & 7 deletions src/HalResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ public function __construct($resource, $id)
$this->id = $id;
}

/**
* Check if properties are set
*
* @param string $name
* @throws Exception\InvalidArgumentException
* @return mixed
*/
public function __isset($name)
{
return in_array(strtolower($name), ['resource', 'id'], true);
}

/**
* Retrieve properties
*
Expand All @@ -42,19 +54,14 @@ public function __construct($resource, $id)
*/
public function __get($name)
{
$names = [
'resource' => 'resource',
'id' => 'id',
];
$name = strtolower($name);
if (!in_array($name, array_keys($names))) {
if (! $this->__isset($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid property name "%s"',
$name
));
}
$prop = $names[$name];
return $this->{$prop};
return $this->{$name};
}

/**
Expand Down

0 comments on commit 19004c4

Please sign in to comment.