GithubHelp home page GithubHelp logo

Comments (11)

jkuchar avatar jkuchar commented on May 17, 2024

Isn’t this same problem as #24 where there was problems with array members?

BTW isn’t it better to use type matcher instead of property matcher?

from deepcopy.

Jan0707 avatar Jan0707 commented on May 17, 2024

I don't think it's the same problem.

Am I not using a type matcher here ?
$deepCopy->addFilter(new SetNullFilter(), new PropertyTypeMatcher('MongoId'));

from deepcopy.

jkuchar avatar jkuchar commented on May 17, 2024

Interfaces Filter and TypeFilter are different. Filter is executed only on object properties; type filter checks also arrays contained in properties.

from deepcopy.

Jan0707 avatar Jan0707 commented on May 17, 2024

Indeed, but if I were to use a TypFilter like this:

interface TypeFilter
{
    /**
     * Apply the filter to the object.
     * @param mixed $element
     */
    public function apply($element);
}

The interface clearly states that the apply function is only called with the $element. But as you can see in the example code above, I also need the property name to decide what to do.

from deepcopy.

jkuchar avatar jkuchar commented on May 17, 2024

Yep, that is true. In property filter you have to manually iterate over arrays. That’s it.

from deepcopy.

mnapoli avatar mnapoli commented on May 17, 2024

Via debugging I found out that my filter is being executed, but apparently not in every case.

Are you able to see what those cases are? @jkuchar suggested they might be in objects that are in arrays, could be it…

Also there's an option to skip uncloneable objects: https://github.com/myclabs/DeepCopy/blob/master/src/DeepCopy/DeepCopy.php#L42 It might be what you are looking for?

from deepcopy.

Jan0707 avatar Jan0707 commented on May 17, 2024

Also there's an option to skip uncloneable objects

I'll have a look into it, but I do not think that simply not copying the objects and then posting to the original object, will work well with doctrine's unit of work.

Array might also be an possibility, I'll check that.

from deepcopy.

jkuchar avatar jkuchar commented on May 17, 2024

Then please try to propose a solution and post PR. When something does not work, the best way of fixing it is to create test and describe exctly intended behaviour there.

from deepcopy.

Jan0707 avatar Jan0707 commented on May 17, 2024

I am more than glad to implement a solution, I just wanted to check back with you guys, what the best approach would be, since I would like this feature to be merged back into the repo. So I kind of need your blessing ;)

Anyway, I tried to come up with a test case that demonstrates what I am looking for:

https://gist.github.com/Jan0707/9aeb502cd72e8dbdb890

from deepcopy.

jkuchar avatar jkuchar commented on May 17, 2024

It looks like MongoId is not clone-able. So you need to do two things:

  1. implement filter to clone all instances of MongoId manually (->addTypeFilter)
  2. Filter those instances you do not want to clone (->addFilter)

from deepcopy.

Jan0707 avatar Jan0707 commented on May 17, 2024

Thanks a bunch ! I updated the gist: https://gist.github.com/Jan0707/9aeb502cd72e8dbdb890

Guess the problem was that I was not aware that you could combine TypeFilter and ordinary Filters, I assumed DeepCopy would only execute the first one it finds suitable.

from deepcopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.