[TYPO3-mvc] Casting objects

Jochen Rau jochen.rau at typoplanet.de
Wed Jul 8 08:59:46 CEST 2009


Hi Xavier,

have a look at the branch extbase/persistence_rewrite. There you find a 
modified Data Mapper with a much cleaner approach to reconstitute 
objects. Maybe this works for you.

The branch will be merged back soon.

Regards
Jochen

Xavier Perseguers wrote:
> Hi,
>
> Is there some official and more important working way of casting objects
> when using Extbase?
>
> I have a class B (in extension FooBar) extending class A (from extension
> Foo).
>
> I only want to extend it for my own purpose in EXT:FooBar, thus no use
> of XCLASS.
>
> Now, I have to override a few methods such as FindOneBy... in order to
> return a class B object instead of class A. What should I do?
>
> I tried to do this:
>
> public static function castToClass($class, $object) {
> return unserialize(preg_replace('/^O:\d+:"[^"]++"/', 'O:' .
> strlen($class) . ':"' . $class . '"', serialize($object)));
> }
>
> and
>
> public function findOneByUid($uid) {
> return FooBar_Helper::castToClass('B', parent::findOneByUid($uid));
> }
>
> But it does not work:
>
> Warning: Invalid argument supplied for foreach() in
> /path/to/extbase/Classes/DomainObject/AbstractDomainObject.php on line 58
>
> It fails after the call to unserialize in my castToClass function, when
> magic method __wakeup on AbstractDomainObject is called because
>
> $GLOBALS['Extbase']['reconstituteObject']['properties']
>
> is not defined in my case.
>
> Any better idea?
>

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list