Feature #37276

Customizable ValueObject hash

Added by Adrian Föder over 9 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Persistence
Start date:
2012-05-18
Due date:
% Done:

100%

Estimated time:
(Total: 0.00 h)
PHP Version:
Has patch:
No
Complexity:

Description

If I understand it correctly, the hash for a Value Object is calculated/done in Persistence\Aspect\PersistenceMagicAspect::generateValueHash().
It seems (I'm just "thinking loudly"), that that hash is built from

* the object's Persistence Identifier, if one
* the concatenated representation of each constructor method argument, processed as following:
  * a serialize(), if an array
  * its actual value, if not an object
  * its Persistence Identifier, if one
  * its timestamp, if DateTime

In my use case, a Doctrine Collection should also be part of the hash. I could imagine that this is not a seldom case in general, so I have two improvement suggestions:

  • directly support the Doctrine collection case with a sub loop, for example, or the Collection->toArray() method
  • or call a magic function, for example
/**
 * @FLOW3\ValueObject
 */
class FooBar {
    public function __construct() {
            // this is the constructor of this Value Object
        $this->that = 'some';
    }

    /**
     * Generates the value object hash. Arguments are as in constructor.
     * @param mixed $argument1 
     * @param mixed $argument2 
     * @return string The value object hash
     */
    public static function generateValueObjectHash() {
        foreach (func_get_args()) ... whatever...

    }

This public static method could be, if present, called by the Aspect; else the usual process is applied to retrieve the hash.

What do you think? Should a customizable VO hash be possible altogether?


Subtasks

Feature #37286: Include object properties in Value Object hash creationClosedAdrian Föder2012-05-18

Actions
#1

Updated by Christian Müller over 9 years ago

biggest problem I would see is awareness that you can break your own data if you change or add that method...

#2

Updated by Adrian Föder over 9 years ago

hm yeah agree.

With the current implementation, objects, if having no persistence identifier and not \DateTime, are disregarded however. For these cases there should at least spl_object_hash() be used; compare to Doctrine's ArrayCollection:

    public function __toString()
    {
        return __CLASS__ . '@' . spl_object_hash($this);
    }

#3

Updated by Adrian Föder over 9 years ago

  • Status changed from New to Closed

Also available in: Atom PDF