PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of jawira   PHP Sanitize Object   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Sanitize Object
Process class variables with rules from comments
Author: By
Last change:
Date: 11 months ago
Size: 2,256 bytes
 

Contents

Class file image Download

? jawira/sanitizer

Sanitize your classes using attributes.

Usage

Add sanitizer attributes to your class:

use Jawira\Sanitizer\Filters as Sanitizer;

class User {
    #[Sanitizer\Trim]
    #[Sanitizer\Capitalize]
    public string $name;
}

Call SanitizerService::sanitize method to apply sanitizers:

use Jawira\Sanitizer\SanitizerService;

$sanitizer = new SanitizerService();
$user = new User();
$user->name = ' BOB ';

$sanitizer->sanitize($user);
echo $user->name; // After: 'Bob'

Available sanitizers

| Sanitizer | Works with | Description | |------------------|----------------|-----------------------------------------------------------------------------------------| | Ascii | _string_ | Remove all characters except ascii characters. | | Capitalize | _string_ | Converts the first letter of each word to uppercase and leaves the others as lowercase. | | GteZero | _int_, _float_ | Ensures number is greater than or equal to zero. | | IntegerChars | _string_ | Remove all characters except digits, plus and minus sign. | | Lowercase | _string_ | Make a string lowercase. | | LteZero | _int_, _float_ | Ensures number is lower than or equal to zero. | | Pad | _string_ | Pad a string to a certain length with another string. | | StripTags | _string_ | Strip HTML and PHP tags from a string. | | Trim | _string_ | Strip whitespace (or other characters) from the beginning and end of a string. | | Uppercase | _string_ | Make a string uppercase. |

Install

composer require jawira/sanitizer

Security

You must not solely rely on sanitization, you must implement a proper data validation mechanism.