Comments (11)
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.
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.
Interfaces Filter
and TypeFilter
are different. Filter is executed only on object properties; type filter checks also arrays contained in properties.
from deepcopy.
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.
Yep, that is true. In property filter you have to manually iterate over arrays. That’s it.
from deepcopy.
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.
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.
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.
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.
It looks like MongoId is not clone-able. So you need to do two things:
- implement filter to clone all instances of MongoId manually (->addTypeFilter)
- Filter those instances you do not want to clone (->addFilter)
from deepcopy.
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)
- PHP 7.4: Cloning of "uninitialized" typed properties not currently possible HOT 1
- Running PHPUnit 8.5.1 got deprecation HOT 1
- Problem when using Symfony 4.4.x and Doctrine 2.7.x: Cannot bind closure to scope of internal class ReflectionProperty
- re-install Laravel website problems HOT 2
- doc\clone.png failed to open stream HOT 2
- Does not properly clone classes inherited from ArrayObject
- Deprecation warning
- error when installing laravel 6
- proc_open(): CreateProcess failed, error code - 5 HOT 1
- Support cloning objects of ArrayAccess
- Infinite loop when trying to copy "recursive" array HOT 2
- Filters are not applied to doctrine Collection values HOT 1
- What about Version 2 HOT 6
- readonly properties in constructor HOT 3
- phpspec/prophecy is now explicitely needed for tests HOT 1
- \DeepCopy\DeepCopy::$hashMap collisions HOT 1
- Clone error HOT 1
- DateInterval from_string property not copied in PHP 8.2
- DeepCopy error : The class \"ReflectionClass\" is not cloneable.
- The class \"ContainerKL2EgoF\\App_KernelDevDebugContainer\" is not cloneable. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepcopy.