From cf3fd824b52d646ab75f7e231366ca135ceaf801 Mon Sep 17 00:00:00 2001 From: Wilt Date: Wed, 11 Sep 2013 14:30:55 +0200 Subject: [PATCH 1/6] Update HalLinks.php Type in method getid -> getId --- src/PhlyRestfully/Plugin/HalLinks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhlyRestfully/Plugin/HalLinks.php b/src/PhlyRestfully/Plugin/HalLinks.php index 2b191f0a..3a0efb53 100644 --- a/src/PhlyRestfully/Plugin/HalLinks.php +++ b/src/PhlyRestfully/Plugin/HalLinks.php @@ -156,7 +156,7 @@ public function setEventManager(EventManagerInterface $events) } // Found public id getter on object - if (method_exists($resource, 'getid')) { + if (method_exists($resource, 'getId')) { return $resource->getId(); } From d123da1695de1c93fb06df9a913b58f97c60ffb2 Mon Sep 17 00:00:00 2001 From: Wilt Date: Thu, 12 Sep 2013 19:14:13 +0200 Subject: [PATCH 2/6] Allow HalResource without identifier if identifierName is set to false This change allows registering a single HalResource without an identifier. See for more details this issue: https://github.com/phly/PhlyRestfully/issues/109 --- src/PhlyRestfully/Plugin/HalLinks.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/PhlyRestfully/Plugin/HalLinks.php b/src/PhlyRestfully/Plugin/HalLinks.php index 3a0efb53..81e21657 100644 --- a/src/PhlyRestfully/Plugin/HalLinks.php +++ b/src/PhlyRestfully/Plugin/HalLinks.php @@ -542,15 +542,18 @@ public function createResourceFromMetadata($object, Metadata $metadata) $data = $hydrator->extract($object); $identiferName = $metadata->getIdentifierName(); - if (!isset($data[$identiferName])) { - throw new Exception\RuntimeException(sprintf( - 'Unable to determine identifier for object of type "%s"; no fields matching "%s"', - get_class($object), - $identiferName - )); + if($identifierName !== false){ + if (!isset($data[$identiferName])) { + throw new Exception\RuntimeException(sprintf( + 'Unable to determine identifier for object of type "%s"; no fields matching "%s"', + get_class($object), + $identiferName + )); + } + $id = $data[$identiferName]; + }else{ + $id = null; } - $id = $data[$identiferName]; - $resource = new HalResource($data, $id); $links = $resource->getLinks(); $this->marshalMetadataLinks($metadata, $links); From 65f8a1137c7e72758cf48920e46dcc38f10e621d Mon Sep 17 00:00:00 2001 From: Wilt Date: Thu, 12 Sep 2013 19:19:31 +0200 Subject: [PATCH 3/6] Typo in $identifierName ($identiferName-> $identifierName) Fix typos in $identifierName ($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 81e21657..9b90b6a1 100644 --- a/src/PhlyRestfully/Plugin/HalLinks.php +++ b/src/PhlyRestfully/Plugin/HalLinks.php @@ -541,16 +541,16 @@ public function createResourceFromMetadata($object, Metadata $metadata) } $data = $hydrator->extract($object); - $identiferName = $metadata->getIdentifierName(); + $identifierName = $metadata->getIdentifierName(); if($identifierName !== false){ - if (!isset($data[$identiferName])) { + 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]; }else{ $id = null; } @@ -558,7 +558,7 @@ public function createResourceFromMetadata($object, Metadata $metadata) $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); } @@ -600,7 +600,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) From 08ac0e2cc89811a78cc7fb201449f547782e9a33 Mon Sep 17 00:00:00 2001 From: Wilt Date: Fri, 18 Oct 2013 16:21:52 +0200 Subject: [PATCH 4/6] 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 function results in returning false which is wrong. It should return 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 d9176fa420c22767e7a457af8b2814bdfa19e624 Mon Sep 17 00:00:00 2001 From: Wilt Date: Fri, 18 Oct 2013 16:41:40 +0200 Subject: [PATCH 5/6] 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 1369482dc8cfd45112955e4b9acbba816cfdc366 Mon Sep 17 00:00:00 2001 From: Wilt Date: Fri, 18 Oct 2013 16:51:25 +0200 Subject: [PATCH 6/6] Rollback Rollback unwanted changes --- src/PhlyRestfully/Plugin/HalLinks.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/PhlyRestfully/Plugin/HalLinks.php b/src/PhlyRestfully/Plugin/HalLinks.php index 2b191f0a..9b90b6a1 100644 --- a/src/PhlyRestfully/Plugin/HalLinks.php +++ b/src/PhlyRestfully/Plugin/HalLinks.php @@ -156,7 +156,7 @@ public function setEventManager(EventManagerInterface $events) } // Found public id getter on object - if (method_exists($resource, 'getid')) { + if (method_exists($resource, 'getId')) { return $resource->getId(); } @@ -541,21 +541,24 @@ public function createResourceFromMetadata($object, Metadata $metadata) } $data = $hydrator->extract($object); - $identiferName = $metadata->getIdentifierName(); - if (!isset($data[$identiferName])) { - throw new Exception\RuntimeException(sprintf( - 'Unable to determine identifier for object of type "%s"; no fields matching "%s"', - get_class($object), - $identiferName - )); + $identifierName = $metadata->getIdentifierName(); + if($identifierName !== false){ + 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), + $identifierName + )); + } + $id = $data[$identifierName]; + }else{ + $id = null; } - $id = $data[$identiferName]; - $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 +600,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)