Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 991
Zeile 184... Zeile 184...
184
### Filters
184
### Filters
Zeile 185... Zeile 185...
185
 
185
 
186
- `DeepCopy\Filter` applies a transformation to the object attribute matched by `DeepCopy\Matcher`
186
- `DeepCopy\Filter` applies a transformation to the object attribute matched by `DeepCopy\Matcher`
Zeile -... Zeile 187...
-
 
187
- `DeepCopy\TypeFilter` applies a transformation to any element matched by `DeepCopy\TypeMatcher`
-
 
188
 
-
 
189
By design, matching a filter will stop the chain of filters (i.e. the next ones will not be applied).
Zeile 187... Zeile 190...
187
- `DeepCopy\TypeFilter` applies a transformation to any element matched by `DeepCopy\TypeMatcher`
190
Using the ([`ChainableFilter`](#chainablefilter-filter)) won't stop the chain of filters.
Zeile 188... Zeile 191...
188
 
191
 
189
 
192
 
Zeile 224... Zeile 227...
224
$copy = $copier->copy($object);
227
$copy = $copier->copy($object);
225
// $copy->category has not been touched
228
// $copy->category has not been touched
226
```
229
```
Zeile -... Zeile 230...
-
 
230
 
-
 
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
```
227
 
258
 
Zeile 228... Zeile 259...
228
 
259
 
Zeile 229... Zeile 260...
229
#### `DoctrineCollectionFilter` (filter)
260
#### `DoctrineCollectionFilter` (filter)
Zeile 266... Zeile 297...
266
If you use Doctrine and use cloning on lazy loaded entities, you might encounter errors mentioning missing fields on a
297
If you use Doctrine and use cloning on lazy loaded entities, you might encounter errors mentioning missing fields on a
267
Doctrine proxy class (...\\\_\_CG\_\_\Proxy).
298
Doctrine proxy class (...\\\_\_CG\_\_\Proxy).
268
You can use the `DoctrineProxyFilter` to load the actual entity behind the Doctrine proxy class.
299
You can use the `DoctrineProxyFilter` to load the actual entity behind the Doctrine proxy class.
269
**Make sure, though, to put this as one of your very first filters in the filter chain so that the entity is loaded
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
before other filters are applied!**
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.
Zeile 271... Zeile 304...
271
 
304
 
272
```php
305
```php
273
use DeepCopy\DeepCopy;
306
use DeepCopy\DeepCopy;
274
use DeepCopy\Filter\Doctrine\DoctrineProxyFilter;
307
use DeepCopy\Filter\Doctrine\DoctrineProxyFilter;
Zeile 275... Zeile 308...
275
use DeepCopy\Matcher\Doctrine\DoctrineProxyMatcher;
308
use DeepCopy\Matcher\Doctrine\DoctrineProxyMatcher;
276
 
309
 
Zeile 277... Zeile 310...
277
$copier = new DeepCopy();
310
$copier = new DeepCopy();
Zeile 278... Zeile 311...
278
$copier->addFilter(new DoctrineProxyFilter(), new DoctrineProxyMatcher());
311
$copier->addFilter(new ChainableFilter(new DoctrineProxyFilter()), new DoctrineProxyMatcher());
279
 
312