Sanitize your objects with attributes.
Add sanitizer attributes to your class:
use Jawira\Sanitizer\Attribute as Filter;
class User {
#[Filter\Trim]
#[Filter\Title]
public string $name;
}
Call Sanitizer::sanitize
method to apply sanitizers:
use Jawira\Sanitizer\Sanitizer;
$user = new User();
$user->name = ' BOB ';
$sanitizer = new Sanitizer();
$sanitizer->sanitize($user);
echo $user->name; // 'Bob'
Interface SanitizerInterface
is also available.
https://jawira.github.io/sanitizer/
composer require jawira/sanitizer
Warning
Sanitization is not a replacement for a proper data validation mechanism and database constraints.
This library is licensed under the MIT license.
- jawira/doctrine-diagram-bundle
- Symfony Bundle to generate database diagrams.
- jawira/case-converter
- Convert strings between 13 naming conventions: Snake case, Camel case, Pascal case, Kebab case, Ada case, Train case, Cobol case, Macro case, Upper case, Lower case, Sentence case, Title case and Dot notation.
- jawira/emoji-catalog
- Get access to +3000 emojis as class constants.
- more...