Skip to content

Commit 729183e

Browse files
committed
Merge pull request #13 from jdeniau/patch-1
Add `use` informations in README
2 parents 96fbdc0 + cabb105 commit 729183e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ composer require myclabs/deep-copy
1717
Use simply:
1818

1919
```php
20+
use DeepCopy\DeepCopy;
21+
2022
$deepCopy = new DeepCopy();
2123
$myCopy = $deepCopy->copy($myObject);
2224
```
@@ -77,6 +79,8 @@ We provide some generic filters and matchers.
7779
The `PropertyNameMatcher` will match a property by its name:
7880

7981
```php
82+
use DeepCopy\Matcher\PropertyNameMatcher;
83+
8084
$matcher = new PropertyNameMatcher('id');
8185
// will apply a filter to any property of any objects named "id"
8286
```
@@ -86,6 +90,8 @@ $matcher = new PropertyNameMatcher('id');
8690
The `PropertyMatcher` will match a specific property of a specific class:
8791

8892
```php
93+
use DeepCopy\Matcher\PropertyMatcher;
94+
8995
$matcher = new PropertyMatcher('MyClass', 'id');
9096
// will apply a filter to the property "id" of any objects of the class "MyClass"
9197
```
@@ -95,6 +101,8 @@ $matcher = new PropertyMatcher('MyClass', 'id');
95101
The `PropertyTypeMatcher` will match a property by its type (instance of a class):
96102

97103
```php
104+
use DeepCopy\Matcher\PropertyTypeMatcher;
105+
98106
$matcher = new PropertyTypeMatcher('Doctrine\Common\Collections\Collection');
99107
// will apply a filter to any property that is an instance of Doctrine\Common\Collections\Collection
100108
```
@@ -106,6 +114,10 @@ $matcher = new PropertyTypeMatcher('Doctrine\Common\Collections\Collection');
106114
Let's say for example that you are copying a database record (or a Doctrine entity), so you want the copy not to have any ID:
107115

108116
```php
117+
use DeepCopy\DeepCopy;
118+
use DeepCopy\Filter\SetNullFilter;
119+
use DeepCopy\Matcher\PropertyNameMatcher;
120+
109121
$myObject = MyClass::load(123);
110122
echo $myObject->id; // 123
111123

@@ -121,6 +133,10 @@ echo $myCopy->id; // null
121133
If you want a property to remain untouched (for example, an association to an object):
122134

123135
```php
136+
use DeepCopy\DeepCopy;
137+
use DeepCopy\Filter\KeepFilter;
138+
use DeepCopy\Matcher\PropertyMatcher;
139+
124140
$deepCopy = new DeepCopy();
125141
$deepCopy->addFilter(new KeepFilter(), new PropertyMatcher('MyClass', 'category'));
126142
$myCopy = $deepCopy->copy($myObject);
@@ -133,6 +149,10 @@ $myCopy = $deepCopy->copy($myObject);
133149
If you want to replace the value of a property:
134150

135151
```php
152+
use DeepCopy\DeepCopy;
153+
use DeepCopy\Filter\ReplaceFilter;
154+
use DeepCopy\Matcher\PropertyMatcher;
155+
136156
$deepCopy = new DeepCopy();
137157
$callback = function ($currentValue) {
138158
return $currentValue . ' (copy)'
@@ -151,6 +171,10 @@ The `$callback` parameter of the `ReplaceFilter` constructor accepts any PHP cal
151171
If you use Doctrine and want to copy an entity, you will need to use the `DoctrineCollectionFilter`:
152172

153173
```php
174+
use DeepCopy\DeepCopy;
175+
use DeepCopy\Filter\Doctrine\DoctrineCollectionFilter;
176+
use DeepCopy\Matcher\PropertyTypeMatcher;
177+
154178
$deepCopy = new DeepCopy();
155179
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
156180
$myCopy = $deepCopy->copy($myObject);
@@ -161,6 +185,10 @@ $myCopy = $deepCopy->copy($myObject);
161185
If you use Doctrine and want to copy an entity who contains a `Collection` that you want to be reset, you can use the `DoctrineEmptyCollectionFilter`
162186

163187
```php
188+
use DeepCopy\DeepCopy;
189+
use DeepCopy\Filter\Doctrine\DoctrineEmptyCollectionFilter;
190+
use DeepCopy\Matcher\PropertyMatcher;
191+
164192
$deepCopy = new DeepCopy();
165193
$deepCopy->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyMatcher('MyClass', 'myProperty'));
166194
$myCopy = $deepCopy->copy($myObject);

0 commit comments

Comments
 (0)