From 2ff619b8bbca124294146d1dbc0a645dd844f7a3 Mon Sep 17 00:00:00 2001 From: Wilt Date: Fri, 18 Oct 2013 17:31:50 +0200 Subject: [PATCH 1/2] Update getIdentifier function to support $id = 0 Update getIdentifier function to support $id = 0 Changed if clause to explicitly check for $id not being false. Previously when $id is set to int 0 the getIdentifier function results in returning false which is wrong. It should return the integer 0. --- src/PhlyRestfully/ResourceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhlyRestfully/ResourceController.php b/src/PhlyRestfully/ResourceController.php index bc8498ce..b5499dfd 100644 --- a/src/PhlyRestfully/ResourceController.php +++ b/src/PhlyRestfully/ResourceController.php @@ -681,7 +681,7 @@ protected function getIdentifier($routeMatch, $request) { $identifier = $this->getIdentifierName(); $id = $routeMatch->getParam($identifier, false); - if ($id) { + if ($id !== false) { return $id; } From d4fc93e88f5c53fc5f9b7e07fe7852bc1f0a284b Mon Sep 17 00:00:00 2001 From: Wilt Date: Fri, 18 Oct 2013 18:12:48 +0200 Subject: [PATCH 2/2] Fixed typos in $identiferName: $identiferName -> $identifierName --- src/PhlyRestfully/Plugin/HalLinks.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PhlyRestfully/Plugin/HalLinks.php b/src/PhlyRestfully/Plugin/HalLinks.php index 2b191f0a..e83c27f8 100644 --- a/src/PhlyRestfully/Plugin/HalLinks.php +++ b/src/PhlyRestfully/Plugin/HalLinks.php @@ -541,21 +541,21 @@ public function createResourceFromMetadata($object, Metadata $metadata) } $data = $hydrator->extract($object); - $identiferName = $metadata->getIdentifierName(); - if (!isset($data[$identiferName])) { + $identifierName = $metadata->getIdentifierName(); + if (!isset($data[$identifierName])) { throw new Exception\RuntimeException(sprintf( 'Unable to determine identifier for object of type "%s"; no fields matching "%s"', get_class($object), - $identiferName + $identifierName )); } - $id = $data[$identiferName]; + $id = $data[$identifierName]; $resource = new HalResource($data, $id); $links = $resource->getLinks(); $this->marshalMetadataLinks($metadata, $links); if (!$links->has('self')) { - $link = $this->marshalSelfLinkFromMetadata($metadata, $object, $id, $identiferName); + $link = $this->marshalSelfLinkFromMetadata($metadata, $object, $id, $identifierName); $links->add($link); } @@ -597,7 +597,7 @@ public function createResource($resource, $route, $identifierName) * * @param HalCollection|array|object $collection * @param null|string $route - * @param string $identiferName + * @param string $identifierName * @return HalCollection */ public function createCollection($collection, $route = null)