dms / dms-filter
DMS Filter provides Annotation based entity filtering.
Installs: 420 749
Dependents: 2
Suggesters: 0
Security: 0
Stars: 94
Watchers: 6
Forks: 19
Open Issues: 6
Requires
- php: ^8.2
Requires (Dev)
- ext-pcov: *
- laminas/laminas-filter: ^2.37
- phpunit/phpunit: ^11
- squizlabs/php_codesniffer: 3.*
- symfony/cache: ^6.4 | ^7.0
Suggests
- ext-mbstring: for encoding safety
- laminas/laminas-filter: Use Laminas Filters via DMS Filter
This package is auto-updated.
Last update: 2024-10-25 23:53:54 UTC
README
This library provides a service that can be used to filter object values based on annotations
Install
Use composer to add DMS\Filter to your app
composer require dms/dms-filter
Usage
Your Entity:
<?php namespace App\Entity; //Import Attributes use DMS\Filter\Rules as Filter; class User { #[Filter\StripTags] #[Filter\Trim] #[Filter\StripNewlines] public string $name; #[Filter\StripTags] #[Filter\Trim] #[Filter\StripNewlines] public string $email; } ?>
Filtering:
<?php //Load AttributeLoader $loader = new Mapping\Loader\AttributeLoader(); //Get a MetadataFactory $metadataFactory = new Mapping\ClassMetadataFactory($loader); //Get a FilterLoader $filterLoader = new \DMS\Filter\Filters\Loader\FilterLoader(); //Get a Filter $filter = new DMS\Filter\Filter($metadataFactory, $filterLoader); //Get your Entity $user = new App\Entity\User(); $user->name = "My <b>name</b>"; $user->email = " email@mail.com"; //Filter you entity $filter->filterEntity($user); echo $user->name; //"My name" echo $user->email; //"email@mail.com" ?>
Contributing
Feel free to send pull requests, just follow these guides:
- Fork
- Code
- Test
- Just create FilterTestCase and run
phpunit
- Just create FilterTestCase and run
- Submit PR
Credits
This library is inspired by the Symfony 2 Validator component and is meant to work alongside it.
Symfony Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator