From ffdfa27a828e0077614dda3039249f4c48bcb243 Mon Sep 17 00:00:00 2001 From: Wilt Date: Wed, 21 May 2014 14:40:47 +0200 Subject: [PATCH] Add magic method __isset method to HalResource To be able to use the isset function in the getIdFromResource method (line 154 in HalLinks) we need to add the magic __isset method to the HalResource. Right now the isset always returns false even if the 'id' is set in $resource. This can be considered a bug. --- src/PhlyRestfully/HalResource.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/PhlyRestfully/HalResource.php b/src/PhlyRestfully/HalResource.php index efa110a4..36a50b97 100644 --- a/src/PhlyRestfully/HalResource.php +++ b/src/PhlyRestfully/HalResource.php @@ -34,6 +34,30 @@ 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) + { + $names = array( + 'resource' => 'resource', + 'id' => 'id', + ); + $name = strtolower($name); + if (!in_array($name, array_keys($names))) { + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid property name "%s"', + $name + )); + } + $prop = $names[$name]; + return $this->{$prop}; + } + /** * Retrieve properties *