[TYPO3-mvc] Where to put automatic value calculation

Jochen Rau jochen.rau at typoplanet.de
Tue Dec 8 20:47:04 CET 2009


Hi.

schrieb Steffen Ritter:
> Sebastian Kurfürst schrieb:
>> Hi,
>>
>>> If i use construktor, or better initialize Object, it will be done on
>>> every reconstitution...
>> Nope, inside constructor it is only done once. Not on reconstitution.
>>
>> Greets,
>> Sebastian
>
> how does this work? isn't construct called automatically?

Normally, yes. But the FLOW3 team has implemented a nice workaround with 
unserialize(). Have a look at the DataMapper:

	protected function createEmptyObject($className) {
		// Note: The class_implements() function also invokes autoload to 
assure that the interfaces
		// and the class are loaded. Would end up with __PHP_Incomplete_Class 
without it.
		if (!in_array('Tx_Extbase_DomainObject_DomainObjectInterface', 
class_implements($className))) throw new 
Tx_Extbase_Object_Exception_CannotReconstituteObject('Cannot create 
empty instance of the class "' . $className . '" because it does not 
implement the Tx_Extbase_DomainObject_DomainObjectInterface.', 1234386924);
		$object = unserialize('O:' . strlen($className) . ':"' . $className . 
'":0:{};');
		return $object;
	}

Regards
Jochen

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list