Feature #3588

Support value objects in the Object Factory

Added by Robert Lemke over 10 years ago. Updated about 9 years ago.

Status:
Accepted
Priority:
Should have
Assignee:
Category:
Object
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
12.00 h
PHP Version:
Has patch:
Complexity:

Description

The Object Factory should have special support for value objects.

Value objects are in fact a mixture of protoype and singleton - although multiple instances of a class may exist, we should only create one instance with the same constructor arguments. The Object Factory (and Object Manager) should return an existing value object if a new one with exactly the same arguments (properties) is requested.


Related issues

Related to TYPO3.Flow - Major Feature #3585: Implement support for value objects New 2009-06-05

History

#1 Updated by Robert Lemke over 10 years ago

  • Target version changed from 1.0 alpha 2 to 283

#2 Updated by Robert Lemke over 10 years ago

  • Target version changed from 283 to 1.0 alpha 3

#3 Updated by Robert Lemke over 10 years ago

  • Target version changed from 1.0 alpha 3 to 1.0 alpha 4

#4 Updated by Robert Lemke about 10 years ago

  • Target version deleted (1.0 alpha 4)

#5 Updated by Karsten Dambekalns almost 10 years ago

  • Target version set to 1.0 alpha 8

#6 Updated by Robert Lemke over 9 years ago

  • Status changed from New to Accepted
  • Priority changed from Could have to Should have
  • Start date deleted (2009-06-05)
  • Estimated time set to 12.00 h
  • value objects are immutable because they must not have setters
  • values are passed through the constructor
  • calculate hash over constructor arguments + object name and use them in the registry / unit of works
  • what about arrays / objects as parameters?

#7 Updated by Robert Lemke over 9 years ago

/**
     * After returning advice, generates the value hash for the object
     *
     * @param \F3\FLOW3\AOP\JoinPointInterface $joinPoint The current join point
     * @return void
     * @afterreturning classTaggedWith(valueobject) && method(.*->__construct())
     * @author Karsten Dambekalns <karsten@typo3.org>
     */
    public function generateValueHash(\F3\FLOW3\AOP\JoinPointInterface $joinPoint) {
        $proxy = $joinPoint->getProxy();
        $hashSource = '';
        foreach (array_keys($this->reflectionService->getClassSchema($joinPoint->getClassName())->getProperties()) as $propertyName) {
            if (is_array($proxy->FLOW3_AOP_Proxy_getProperty($propertyName))) {
                $hashSource .= serialize($proxy->FLOW3_AOP_Proxy_getProperty($propertyName));
            } elseif (!is_object($proxy->FLOW3_AOP_Proxy_getProperty($propertyName))) {
                $hashSource .= $proxy->FLOW3_AOP_Proxy_getProperty($propertyName);
            } elseif (property_exists($proxy->FLOW3_AOP_Proxy_getProperty($propertyName), 'FLOW3_Persistence_Entity_UUID')) {
                $hashSource .= $proxy->FLOW3_AOP_Proxy_getProperty($propertyName)->FLOW3_Persistence_Entity_UUID;
            } elseif (property_exists($proxy->FLOW3_AOP_Proxy_getProperty($propertyName), 'FLOW3_Persistence_ValueObject_Hash')) {
                $hashSource .= $proxy->FLOW3_AOP_Proxy_getProperty($propertyName)->FLOW3_Persistence_Entity_UUID;
            }
        }
        $proxy->FLOW3_Persistence_ValueObject_Hash = sha1($hashSource);
    }

#8 Updated by Robert Lemke over 9 years ago

  • Target version changed from 1.0 alpha 8 to 1.0 alpha 9

#9 Updated by Robert Lemke over 9 years ago

  • Target version deleted (1.0 alpha 9)

Also available in: Atom PDF