@@ -186,6 +186,9 @@ $matcher = new TypeMatcher('Doctrine\Common\Collections\Collection');
186
186
- ` DeepCopy\Filter ` applies a transformation to the object attribute matched by ` DeepCopy\Matcher `
187
187
- ` DeepCopy\TypeFilter ` applies a transformation to any element matched by ` DeepCopy\TypeMatcher `
188
188
189
+ By design, matching a filter will stop the chain of filters (i.e. the next ones will not be applied).
190
+ Using the ([ ` ChainableFilter ` ] ( #chainablefilter-filter ) ) won't stop the chain of filters.
191
+
189
192
190
193
#### ` SetNullFilter ` (filter)
191
194
@@ -226,6 +229,34 @@ $copy = $copier->copy($object);
226
229
```
227
230
228
231
232
+ #### ` ChainableFilter ` (filter)
233
+
234
+ If you use cloning on proxy classes, you might want to apply two filters for:
235
+ 1 . loading the data
236
+ 2 . applying a transformation
237
+
238
+ You can use the ` ChainableFilter ` as a decorator of the proxy loader filter, which won't stop the chain of filters (i.e.
239
+ the next ones may be applied).
240
+
241
+
242
+ ``` php
243
+ use DeepCopy\DeepCopy;
244
+ use DeepCopy\Filter\ChainableFilter;
245
+ use DeepCopy\Filter\Doctrine\DoctrineProxyFilter;
246
+ use DeepCopy\Filter\SetNullFilter;
247
+ use DeepCopy\Matcher\Doctrine\DoctrineProxyMatcher;
248
+ use DeepCopy\Matcher\PropertyNameMatcher;
249
+
250
+ $copier = new DeepCopy();
251
+ $copier->addFilter(new ChainableFilter(new DoctrineProxyFilter()), new DoctrineProxyMatcher());
252
+ $copier->addFilter(new SetNullFilter(), new PropertyNameMatcher('id'));
253
+
254
+ $copy = $copier->copy($object);
255
+
256
+ echo $copy->id; // null
257
+ ```
258
+
259
+
229
260
#### ` DoctrineCollectionFilter ` (filter)
230
261
231
262
If you use Doctrine and want to copy an entity, you will need to use the ` DoctrineCollectionFilter ` :
@@ -268,14 +299,16 @@ Doctrine proxy class (...\\\_\_CG\_\_\Proxy).
268
299
You can use the ` DoctrineProxyFilter ` to load the actual entity behind the Doctrine proxy class.
269
300
** Make sure, though, to put this as one of your very first filters in the filter chain so that the entity is loaded
270
301
before other filters are applied!**
302
+ We recommend to decorate the ` DoctrineProxyFilter ` with the ` ChainableFilter ` to allow applying other filters to the
303
+ cloned lazy loaded entities.
271
304
272
305
``` php
273
306
use DeepCopy\DeepCopy;
274
307
use DeepCopy\Filter\Doctrine\DoctrineProxyFilter;
275
308
use DeepCopy\Matcher\Doctrine\DoctrineProxyMatcher;
276
309
277
310
$copier = new DeepCopy();
278
- $copier->addFilter(new DoctrineProxyFilter(), new DoctrineProxyMatcher());
311
+ $copier->addFilter(new ChainableFilter(new DoctrineProxyFilter() ), new DoctrineProxyMatcher());
279
312
280
313
$copy = $copier->copy($object);
281
314
0 commit comments