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) 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; }