DeepCopy icon indicating copy to clipboard operation
DeepCopy copied to clipboard

Add a way to get a hand on a cloned object

Open GregOriol opened this issue 7 years ago • 2 comments

We have a situation where we have objects that are somehow linked to other structures (an object references a file on disk in our case). When the deep copy of a data tree is performed, the objects are cloned inside, but we also need a hand on the old and new objects together to be able to copy the associated structure at the same time (cp files on disk here).

I don't see a way to do that currently, we thought about the type filter/type replace but we don't want to "manually" clone the object as would be with this filter, we are perfectly good with the normal cloning, we just need to know when one was cloned to perform the additional operations we need.

What would be the best way to do it? Events? Callbacks? Type filters that can be chained?

GregOriol avatar Aug 24 '18 14:08 GregOriol

what about the regular __clone for the object encapsulating that file? DeepCopy can use it instead of performing a deep clone so that regular objects would have your custom behaviour

theofidry avatar Aug 24 '18 16:08 theofidry

@theofidry I want the deep clone behavior (mostly because the data is doctrine entities), but also would like to be able to perform something after the cloning of some of the objects in the data tree

__clone would do something like that, but it would remove the deep cloning and I wouldn't use deepcopy if I could just go with the standard clone :-)

GregOriol avatar Aug 25 '18 11:08 GregOriol