@@ -12,79 +12,6 @@ Use composer to add DMS\Filter to your app
12
12
13
13
## Usage
14
14
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
-
88
15
Your Entity:
89
16
90
17
``` php
@@ -115,13 +42,15 @@ Filtering:
115
42
<?php
116
43
//Load AttributeLoader
117
44
$loader = new Mapping\Loader\AttributeLoader();
118
- $this->loader = $loader;
119
45
120
46
//Get a MetadataFactory
121
47
$metadataFactory = new Mapping\ClassMetadataFactory($loader);
122
48
49
+ //Get a FilterLoader
50
+ $filterLoader = new \DMS\Filter\Filters\Loader\FilterLoader();
51
+
123
52
//Get a Filter
124
- $filter = new DMS\Filter\Filter($metadataFactory);
53
+ $filter = new DMS\Filter\Filter($metadataFactory, $filterLoader );
125
54
126
55
127
56
//Get your Entity
@@ -130,19 +59,12 @@ Filtering:
130
59
$user->email = "
[email protected] ";
131
60
132
61
//Filter you entity
133
- $filter->filter ($user);
62
+ $filter->filterEntity ($user);
134
63
135
64
echo $user->name; //"My name"
136
65
echo $user->email; //"
[email protected] "
137
66
?>
138
67
```
139
-
140
- ## Dependencies
141
-
142
- This package relies on these external libraries:
143
-
144
- * Doctrine Annotations
145
-
146
68
## Contributing
147
69
148
70
Feel free to send pull requests, just follow these guides:
@@ -157,4 +79,4 @@ Feel free to send pull requests, just follow these guides:
157
79
158
80
This library is inspired by the Symfony 2 Validator component and is meant to work alongside it.
159
81
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