Feature #37276

Customizable ValueObject hash

Added by Adrian Föder about 3 years ago. Updated about 3 years ago.

Status:Closed Start date:2012-05-18
Priority:Should have Due date:
Assigned To:- % Done:

100%

Category:Persistence
Target version:TYPO3 Flow Base Distribution - 2.0 beta 1
PHP Version: Complexity:
Has patch:No

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
 1/**
 2 * @FLOW3\ValueObject
 3 */
 4class FooBar {
 5    public function __construct() {
 6            // this is the constructor of this Value Object
 7        $this->that = 'some';
 8    }
 9
10    /**
11     * Generates the value object hash. Arguments are as in constructor.
12     * @param mixed $argument1 
13     * @param mixed $argument2 
14     * @return string The value object hash
15     */
16    public static function generateValueObjectHash() {
17        foreach (func_get_args()) ... whatever...
18
19    }

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öder

History

#1 Updated by Christian Müller about 3 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 about 3 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 about 3 years ago

  • Status changed from New to Closed

Also available in: Atom PDF