Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2023-07-06 (2 months ago) | | Not yet rated by the users | | Total: 53 This week: 1 | | All time: 10,478 This week: 108 |
|
Description | | Author Jawira Portugal
Contributor
|
This package can process class variables with rules from comments.
It can take an object of a given class and parses the class file to extract sanitization rules defined in the class code comments.
This package can process the class variables and change their values according to the sanitization rules.
Currently, it supports the following sanitization rules:
- Contain only ASCII characters
- Capitalize the letters of sentence strings
- Numbers above zero
- String only with integer characters
- Numbers below zero
- String with lowercase letters
- String with padding characters
- String without HTML tags
- Trimmed string
- Upper case letters Innovation Award
July 2023
Winner |
Secure PHP applications need to be careful with the values passed to the PHP code from external sources that they do not control, such as the parameters passed to PHP via HTTP requests.
When the user enters the values, for instance, in a form, it may be necessary to tell the user to fix invalid values submitted via forms so that the values can comply with applicable rules.
For simple user mistakes, such as incorrect use of the case of words of a person's name, it may be more user-friendly to make the PHP code fix the issue of the letters rather than making the user select the case of the person's name.
This package can do that kind of automatic fixing of values passed to the PHP application by sanitizing the importance of data object classes according to the rules defined in the comments of those classes.
This way, the user will not be bothered to fix the values entered in the forms, and those values will be compliant with the PHP application rules.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 9x
Winner: 2x |
|
Details
? 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.
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.