Skip to content
Newer
Older
100644 107 lines (72 sloc) 2.64 KB
98cbcf1 @rdohms [Filter] Creating basic interfaces and filter logic
authored
1 # DMS Filter Component
2
3 This library provides a service that can be used to filter object values based on annotations
4
d523ae1 @rdohms Pushing badges
authored
5 [![Latest Stable Version](https://poser.pugx.org/dms/dms-filter/v/stable.png)](https://packagist.org/packages/dms/dms-filter) [![Total Downloads](https://poser.pugx.org/dms/dms-filter/downloads.png)](https://packagist.org/packages/dms/dms-filter) [![Latest Unstable Version](https://poser.pugx.org/dms/dms-filter/v/unstable.png)](https://packagist.org/packages/dms/dms-filter) [![License](https://poser.pugx.org/dms/dms-filter/license.png)](https://packagist.org/packages/dms/dms-filter) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/bb7f41c3-ee7c-4473-8fbf-806453a9e899/mini.png)](https://insight.sensiolabs.com/projects/bb7f41c3-ee7c-4473-8fbf-806453a9e899) [![Build Status](https://travis-ci.org/rdohms/dms-filter.png?branch=master)](https://travis-ci.org/rdohms/dms-filter)
6
84a5df6 @rdohms Updating README and fixing composer
authored
7 ## Install
8
9 Use composer to add DMS\Filter to your app
10
a997908 @rdohms Update README.md
authored
11 `composer require dms/dms-filter`
84a5df6 @rdohms Updating README and fixing composer
authored
12
13 This will get you the latest compatible version with 2.0 without BC breaks.
14
76df592 @rdohms [Filter] Finished initial implementation and documented all classes
authored
15 ## Usage
16
6bdac28 @rdohms Fixing some CS and optimizing some code.
authored
17 Your Entity:
e8369b3 @rdohms [Filter] Updating README example with more detail
authored
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 $name;
38
39 /**
40 * @Filter\StripTags()
41 * @Filter\Trim()
42 * @Filter\StripNewlines()
43 *
44 * @var string
45 */
46 public $email;
47
48 }
49 ?>
6bdac28 @rdohms Fixing some CS and optimizing some code.
authored
50 ```
e8369b3 @rdohms [Filter] Updating README example with more detail
authored
51
52 Filtering:
53
1892ca3 @rdohms [Filter] Updated README
authored
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
fcffe48 @rdohms [Filter] Added new Filters: Int, Float and Boolean
authored
68 $filter = new DMS\Filter\Filter($metadataFactory);
1892ca3 @rdohms [Filter] Updated README
authored
69
e8369b3 @rdohms [Filter] Updating README example with more detail
authored
70
71 //Get your Entity
72 $user = new App\Entity\User();
73 $user->name = "My <b>name</b>";
74 $user->email = " email@mail.com";
75
76 //Filter you entity
77 $filter->filter($user);
78
79 echo $user->name; //"My name"
80 echo $user->email; //"email@mail.com"
1892ca3 @rdohms [Filter] Updated README
authored
81 ?>
6bdac28 @rdohms Fixing some CS and optimizing some code.
authored
82 ```
e8369b3 @rdohms [Filter] Updating README example with more detail
authored
83
84 Full example: https://gist.github.com/1098352
76df592 @rdohms [Filter] Finished initial implementation and documented all classes
authored
85
86 ## Dependencies
87
88 This package relies on these external libraries:
89
6bdac28 @rdohms Fixing some CS and optimizing some code.
authored
90 * Doctrine Annotations
76df592 @rdohms [Filter] Finished initial implementation and documented all classes
authored
91
1892ca3 @rdohms [Filter] Updated README
authored
92 ## Contributing
93
94 Feel free to send pull requests, just follow these guides:
95
96 * Fork
97 * Code
98 * Test
84a5df6 @rdohms Updating README and fixing composer
authored
99 * Just create FilterTestCase and run `phpunit`
1892ca3 @rdohms [Filter] Updated README
authored
100 * Submit PR
101
98cbcf1 @rdohms [Filter] Creating basic interfaces and filter logic
authored
102 ## Credits
103
6bdac28 @rdohms Fixing some CS and optimizing some code.
authored
104 This library is inspired by the Symfony 2 Validator component and is meant to work alongside it.
98cbcf1 @rdohms [Filter] Creating basic interfaces and filter logic
authored
105
6bdac28 @rdohms Fixing some CS and optimizing some code.
authored
106 Symfony 2 Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator
Something went wrong with that request. Please try again.