Lines Matching +full:add +full:- +full:matcher

5 [![Build Status](https://travis-ci.org/myclabs/DeepCopy.png?branch=1.x)](https://travis-ci.org/mycl…
7 …ttps://scrutinizer-ci.com/g/myclabs/DeepCopy/badges/quality-score.png?s=2747100c19b275f93a777e3297…
8 …nloads](https://poser.pugx.org/myclabs/deep-copy/downloads.svg)](https://packagist.org/packages/my…
14 1. [Using simply `clone`](#using-simply-clone)
15 1. [Overridding `__clone()`](#overridding-__clone)
16 1. [With `DeepCopy`](#with-deepcopy)
17 1. [How it works](#how-it-works)
18 1. [Going further](#going-further)
20 1. [Property name](#property-name)
21 1. [Specific property](#specific-property)
24 1. [`SetNullFilter`](#setnullfilter-filter)
25 1. [`KeepFilter`](#keepfilter-filter)
26 1. [`DoctrineCollectionFilter`](#doctrinecollectionfilter-filter)
27 1. [`DoctrineEmptyCollectionFilter`](#doctrineemptycollectionfilter-filter)
28 1. [`DoctrineProxyFilter`](#doctrineproxyfilter-filter)
29 1. [`ReplaceFilter`](#replacefilter-type-filter)
30 1. [`ShallowCopyFilter`](#shallowcopyfilter-type-filter)
31 1. [Edge cases](#edge-cases)
41 composer require myclabs/deep-copy
50 $myCopy = $copier->copy($myObject);
56 - How do you create copies of your objects?
62 - How do you create **deep** copies of your objects (i.e. copying also all the objects referenced i…
67 - But how do you handle **cycles** in the association graph?
81 ![Overridding __clone](doc/deep-clone.png)
86 ![With DeepCopy](doc/deep-copy.png)
109 $copy = $copier->copy($var);
127 return $copier->copy($var);
134 You can add filters to customize the copy process.
136 The method to add a filter is `DeepCopy\DeepCopy::addFilter($filter, $matcher)`,
138 and `$matcher` implementing `DeepCopy\Matcher\Matcher`.
145 - `DeepCopy\Matcher` applies on a object attribute.
146 - `DeepCopy\TypeMatcher` applies on any element found in graph, including array elements.
154 use DeepCopy\Matcher\PropertyNameMatcher;
157 $matcher = new PropertyNameMatcher('id');
166 use DeepCopy\Matcher\PropertyMatcher;
169 $matcher = new PropertyMatcher('MyClass', 'id');
182 $matcher = new TypeMatcher('Doctrine\Common\Collections\Collection');
188 - `DeepCopy\Filter` applies a transformation to the object attribute matched by `DeepCopy\Matcher`
189 - `DeepCopy\TypeFilter` applies a transformation to any element matched by `DeepCopy\TypeMatcher`
200 use DeepCopy\Matcher\PropertyNameMatcher;
203 echo $object->id; // 123
206 $copier->addFilter(new SetNullFilter(), new PropertyNameMatcher('id'));
208 $copy = $copier->copy($object);
210 echo $copy->id; // null
221 use DeepCopy\Matcher\PropertyMatcher;
224 $copier->addFilter(new KeepFilter(), new PropertyMatcher('MyClass', 'category'));
226 $copy = $copier->copy($object);
227 // $copy->category has not been touched
238 use DeepCopy\Matcher\PropertyTypeMatcher;
241 $copier->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collect…
243 $copy = $copier->copy($object);
255 use DeepCopy\Matcher\PropertyMatcher;
258 $copier->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyMatcher('MyClass', 'myProperty'…
260 $copy = $copier->copy($object);
262 // $copy->myProperty will return an empty collection
277 use DeepCopy\Matcher\Doctrine\DoctrineProxyMatcher;
280 $copier->addFilter(new DoctrineProxyFilter(), new DoctrineProxyMatcher());
282 $copy = $copier->copy($object);
295 use DeepCopy\Matcher\PropertyMatcher;
301 $copier->addFilter(new ReplaceFilter($callback), new PropertyMatcher('MyClass', 'title'));
303 $copy = $copier->copy($object);
305 // $copy->title will contain the data returned by the callback, e.g. 'The title (copy)'
319 $copier->addTypeFilter(new ReplaceFilter($callback), new TypeMatcher('MyClass'));
321 $copy = $copier->copy([new MyClass, 'some string', new MyClass]);
340 $this->deepCopy = new DeepCopy();
341 $this->deepCopy->addTypeFilter(
353 The following structures cannot be deep-copied with PHP Reflection. As a result they are shallow cl…
356 - Implement your own `__clone()` method
357 - Use a filter with a type matcher
375 …n](https://tidelift.com/subscription/pkg/packagist-myclabs-deep-copy?utm_source=packagist-myclabs-