zfcampus/zf-hal — pull request #35 by weierophinney (2014-05-22 21:24:19+00:00)
Title: [#33] Store original entity in Hal\Entity

When calling `createEntity()` we should **not** serialize the original object
to an array, as this breaks listeners on `renderEntity`; listeners can no
longer use instanceof to detect the type, as it's always an array.

However, to preserve the original behavior, which is that the returned
`ZF\Hal\Entity` object has an identifier, routing behavior, etc., we need to
use the metadata map in order to serialize the object and extract the
identifier. This leads to a situation where serialization can happen twice --
once when
`createEntity()` is called, and once when `renderEntity()` is called. To
address that situation, this patch also introduces a `serializedEntities`
object, which maps objects to their array representations. This is a fast
lookup, and prevents the double serialization operation.

Doing this allowed removing code from `createEntityFromMetadataMap()`, as the
logic for extracting the entity was largely duplicated from
`convertEntityToArray()`.

This PR fixes #33, and supercedes #34.