Download the PHP package rhinox/input-data without Composer
On this page you can find all versions of the php package rhinox/input-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rhinox/input-data
More information about rhinox/input-data
Files in rhinox/input-data
Package input-data
Short Description PHP library for parsing user input data with safe type casting, sensible defaults, and robust error handling
License MIT
Informations about the package input-data
InputData
InputData is a PHP library that helps parse user input data, or data from sources that could potentially be invalid, changed, or corrupted. It parses data based on expectations with sensible defaults and robust type casting. It does not replace validation or sanitization, but provides best-effort parsing with predictable behavior.
Features
- Safe type casting with fallback defaults
- Dot notation for nested data access
- Inbuilt data types: strings, integers, decimals, booleans, dates, arrays, JSON
- Easily extendable for custom data types
- Mutable and Immutable variants for different use cases
- ArrayAccess, Countable, Iterable interfaces for seamless integration
Installation
Quick Start
Use Cases
User Input Processing
API Response Handling
File Processing
API Reference
All methods accept a key parameter and optional default value. Keys support dot notation for nested data access.
Type Casting Methods
string()
Cast value to string. Non-string values are converted using PHP's string casting rules.
int()
Cast value to integer. Non-numeric values return the default.
decimal()
Cast value to float/decimal.
bool()
Cast value to boolean.
dateTime()
Parse value as DateTime with optional timezone.
Data Structure Methods
arr()
Get array data as new InputData instance.
object()
Get object data, converting arrays to objects when needed.
json()
Parse JSON string into InputData instance.
raw()
Get raw value without type casting.
Utility Methods
exists()
Check if a key exists (supports dot notation).
isEmpty(), isArray(), count()
Check data state and get count.
Static Factory Methods
JSON Processing
jsonDecode()
Parse JSON string, throws JsonException
on invalid JSON.
tryJsonDecode()
Parse JSON string, returns empty InputData on invalid JSON.
jsonDecodeFile()
Read and parse JSON file, throws FileReadException
or JsonException
on errors.
tryJsonDecodeFile()
Read and parse JSON file, returns empty InputData on any error.
Data Modification
Two variants are available for modifying data:
- MutableInputData: Methods modify the current instance
- ImmutableInputData: Methods return new instances
MutableInputData
ImmutableInputData
Modification Methods
extend()
Recursively merge arrays into existing data.
set()
Set value at path (supports dot notation).
unset()
Remove value at path (supports dot notation).
filter()
Filter data using callback. Default callback removes null values.
filterRecursive()
Recursively filter nested data.
map()
Transform values using callback.
mapRecursive()
Recursively transform nested data.
values()
Re-index array to sequential numeric keys.
merge()
Merge with another array or InputData instance.
Advanced Features
Dot Notation
Access nested data using dot-separated keys:
Array Access Interface
InputData implements ArrayAccess for convenient access:
Iteration
InputData implements IteratorAggregate:
Find Method
Search for items matching criteria:
Extending InputData
Create custom parsers by extending the base class:
Development
Requirements
- PHP 8.4 or higher
- Composer for dependency management
Development Tools
The project uses modern PHP development tools:
- PHPUnit: Testing framework with 100% code coverage
- PHP CS Fixer: Code formatting and style checking
- Psalm: Static analysis for type safety
- Infection: Mutation testing
Running Tests
Code Quality
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes with tests
- Run the quality assurance suite (
composer qa
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please ensure all tests pass and maintain 100% code coverage.
License
This project is licensed under the MIT License - see the LICENSE file for details.