| File: |
src/Ban.php |
| Role: |
Class source |
| Content type: |
text/plain |
| Description: |
Class source |
| Class: |
PHP Not Allowed
Detect and filter unwanted information |
| Author: |
By Pierre-Henry Soria |
| Last change: |
Use `self` keyword instead of enum name
Cleanup: Adding new lines after each `return` stmt
Use backed enum in combination with `match()` to get rid of `switch` statement
These changes require now PHP 8.1 or higher as enums are available only since PHP 8.1+
Cleanup: Update indentation (removed redundant new lines) in `__construct()` / `__clone()`
Refactoring: Rename `Ban::isIn()` to `doesExist`
Update docBlock `@param` comments
Fix type declations on argument
Banned contents were not loaded first, giving wrong result
Use PHP 8 `str_starts_with` instead
https://www.php.net/manual/en/function.str-starts-with.php
Cast `static::$cache` to array, making sure NULL wont be given
Fix coding style indentation
Enhancement with minor fixes (missing arg type, redundant func call, ...)
Add return type to readFile
Add curly braces
Remove property types and union types
Remove bIsEmail flag
Add support to validate that all provided values in a set are banned
- Add a `isAny(array $value, bool $email = false, bool $word = false, bool $username = false, bool $ip = false, bool $bank_accounts = false)` method
- This method returns true if any of the provided values is banned in any of the paths selected
- This method short circuits
- Add a `isAll(array $value, bool $email = false, bool $word = false, bool $username = false, bool $ip = false, bool $bank_accounts = false)` method
- This method returns true if ALL of the provided values are banned across all the paths selected
- This method short circuits
- Add unit tests accordingly
Update isEmail logic to ensure the flag does not persist across non-email validations
- It's entirely possible that a username has special characters, or @ symbol
- Ensured the isEmail flag is set to false post validation
Add support for extending banned content
- Added a way to merge value[s] and user defined/provided files
- Added unit tests accordingly
Add support for multiple value validation
- Changed each public method signature to allow intake of string or array of values
- Changed the entire Ban control flow to be more functional programming based to support
multiple value validation
- Add unit tests for intake of array of values accordingly
Add caching control flow
- Files should not be read every request, especially when the methods only
allow searching for singular matches at a given time. Subsequent requests would read the same file
- Added static variable called $cache where the filenames serve as the key to query in readFile()
Bump year to 2022
Improve readability
Fixed invalid argument
Fixed undefined variable
Cleanup. Remove unnecessary space/line
PHP8: Private methods cannot be final as they are never overridden
DRY: Add method to read file
(and add `FILE_SKIP_EMPTY_LINES` flag)
Set class constants to private visibility
Several fixes and improvements
Add Return Type Declarations to method signatures
Initial First Commit!
Code based was inspired from my other class, here
https://github.com/pH7Software/pH7-Social-Dating-CMS/blob/master/_protected/framework/Security/Ban/Ban.class.php
|
| Date: |
6 months ago |
| Size: |
7,290 bytes |
|
|
|