Skip to content

Commit

Permalink
Add magic method __isset method to HalResource
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Wilt committed May 21, 2014
1 parent 21d2640 commit ffdfa27
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/PhlyRestfully/HalResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit ffdfa27

Please sign in to comment.