Skip to content

Commit 3b7a8a8

Browse files
author
Igor Kusmitsch
committed
Update readme file
1 parent f715a53 commit 3b7a8a8

File tree

1 file changed

+6
-84
lines changed

1 file changed

+6
-84
lines changed

README.md

Lines changed: 6 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -12,79 +12,6 @@ Use composer to add DMS\Filter to your app
1212

1313
## Usage
1414

15-
### Annotation way
16-
17-
Your Entity:
18-
19-
```php
20-
<?php
21-
22-
namespace App\Entity;
23-
24-
//Import Annotations
25-
use DMS\Filter\Rules as Filter;
26-
27-
class User
28-
{
29-
30-
/**
31-
* @Filter\StripTags()
32-
* @Filter\Trim()
33-
* @Filter\StripNewlines()
34-
*
35-
* @var string
36-
*/
37-
public string $name;
38-
39-
/**
40-
* @Filter\StripTags()
41-
* @Filter\Trim()
42-
* @Filter\StripNewlines()
43-
*
44-
* @var string
45-
*/
46-
public string $email;
47-
48-
}
49-
?>
50-
```
51-
52-
Filtering:
53-
54-
```php
55-
<?php
56-
//Get Doctrine Reader
57-
$reader = new Annotations\AnnotationReader();
58-
$reader->setEnableParsePhpImports(true);
59-
60-
//Load AnnotationLoader
61-
$loader = new Mapping\Loader\AnnotationLoader($reader);
62-
$this->loader = $loader;
63-
64-
//Get a MetadataFactory
65-
$metadataFactory = new Mapping\ClassMetadataFactory($loader);
66-
67-
//Get a Filter
68-
$filter = new DMS\Filter\Filter($metadataFactory);
69-
70-
71-
//Get your Entity
72-
$user = new App\Entity\User();
73-
$user->name = "My <b>name</b>";
74-
$user->email = " [email protected]";
75-
76-
//Filter you entity
77-
$filter->filter($user);
78-
79-
echo $user->name; //"My name"
80-
echo $user->email; //"[email protected]"
81-
?>
82-
```
83-
84-
Full example: https://gist.github.com/1098352
85-
86-
### Attribute way
87-
8815
Your Entity:
8916

9017
```php
@@ -115,13 +42,15 @@ Filtering:
11542
<?php
11643
//Load AttributeLoader
11744
$loader = new Mapping\Loader\AttributeLoader();
118-
$this->loader = $loader;
11945

12046
//Get a MetadataFactory
12147
$metadataFactory = new Mapping\ClassMetadataFactory($loader);
12248

49+
//Get a FilterLoader
50+
$filterLoader = new \DMS\Filter\Filters\Loader\FilterLoader();
51+
12352
//Get a Filter
124-
$filter = new DMS\Filter\Filter($metadataFactory);
53+
$filter = new DMS\Filter\Filter($metadataFactory, $filterLoader);
12554

12655

12756
//Get your Entity
@@ -130,19 +59,12 @@ Filtering:
13059
$user->email = " [email protected]";
13160

13261
//Filter you entity
133-
$filter->filter($user);
62+
$filter->filterEntity($user);
13463

13564
echo $user->name; //"My name"
13665
echo $user->email; //"[email protected]"
13766
?>
13867
```
139-
140-
## Dependencies
141-
142-
This package relies on these external libraries:
143-
144-
* Doctrine Annotations
145-
14668
## Contributing
14769

14870
Feel free to send pull requests, just follow these guides:
@@ -157,4 +79,4 @@ Feel free to send pull requests, just follow these guides:
15779

15880
This library is inspired by the Symfony 2 Validator component and is meant to work alongside it.
15981

160-
Symfony 2 Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator
82+
Symfony Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator

0 commit comments

Comments
 (0)