https://github.com/phpgt/input
Encapsulated and type-safe user input.
https://github.com/phpgt/input
encapsulation encryption file-upload php-security querystring security stream user-input
Last synced: 8 months ago
JSON representation
Encapsulated and type-safe user input.
- Host: GitHub
- URL: https://github.com/phpgt/input
- Owner: phpgt
- License: mit
- Created: 2017-11-05T17:24:30.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-26T12:00:12.000Z (9 months ago)
- Last Synced: 2025-04-19T23:45:24.679Z (8 months ago)
- Topics: encapsulation, encryption, file-upload, php-security, querystring, security, stream, user-input
- Language: PHP
- Homepage: https://www.php.gt/input
- Size: 369 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Encapsulated and type-safe user input.
======================================
By default, PHP stores all user input in global arrays (`$_GET`, `$_POST`, and `$_FILES`) available for reading and _modification_ in any code, including third party libraries.
This library wraps user input in objects that promote encapsulation, allowing functions to be
passed only the user input they require, rather than having unmitigated read/write access to everything.
Type-safe functions allow more predictable functionality, such as `$input->getFileUpload("photo")`, `$input->getDateTime("date-of-birth")`, and `$input->getMultipleString("pizza-topping")`.
***
Example usage
-------------
```html
User Profile
Your name
Age
Interests
Mathematics
Cryptography
Information Security
Cyberwarfare
Photo
Save profile
```
```php
update(
$profileId,
// Use type-safe getters to help write maintainable code.
$input->getString("name"),
$input->getInt("age"),
);
// Handle multiple values with type safety.
foreach($input->getMultipleString("interest") as $interest) {
$profile->addInterest($interest);
}
// Handle file uploads with a FileUpload object.
$photoUpload = $input->getFile("photo");
if($photoUpload instanceof FailedFileUpload) {
// Handle a failed upload here.
}
$photoUpload->moveTo("data/upload/$profileId.jpg");
```
Features at a glance
--------------------
+ Type-safe getters, implementing the [TypeSafeGetter][tsg] interface.
+ Typed `multiple` getters, for working with checkboxes, multi-select elements or multiple file uploads.
+ "do" callback functions - hook up callbacks to button presses (implemented automatically in WebEngine applications).
+ "when" triggers - execute callbacks when certain user input is present.
+ `FileUploadInputData` class for easy file uploads, including functions such as `moveTo()`, `getOriginalName()`, etc.
+ Coming soon: working with huge files by streaming them to PHP, efficiently managing memory in the process.
[tsg]: https://php.gt/typesafegetter