wrkflow/php-get-typed-value
php-get-typed-value
Get typed (strict mode) values from an Array / XML with basic validation.
composer require wrkflow/php-get-typed-value
Main features
- 🚀 Retrieve values from Array (JSON) / XML with correct return type with safe dot notation support.
- 🏆 Makes PHPStan / IDE happy due the type strict return types.
- 🤹 Validation: Ensures that desired value is in correct type (without additional loop validation).
- 🛠 Transformers: Ensures that values are in expected type.
- ⛑ Converts empty string values to null (can be disabled, see transformers).
use Wrkflow\GetValue\GetValue;
use Wrkflow\GetValue\DataHolders\ArrayData;
$data = new GetValue(new ArrayData([
'address' => [
'street' => [
'number' => '13',
],
'name' => '',
]
]));
$data->getInt('address.street.number') // Returns: 13 (int)
$data->getString('address.street.name') // Returns: null because value does not exists
$data->getRequiredString('address.street.name') // Returns: throws MissingValueForKeyException exception
Documentation
Documentation is hosted on GitHub Pages.
Comment
I've created this project as part of my mission to create work flow tools / libraries to make my (and yours) dev
life easier and more enjoyable.
Want more tools or want to help? Check wrk-flow.com or CONTRIBUTE. You can help me improve the documentation, add new tests and features. Are you junior developer? Don't be scared, get in touch and I will guide you in your first contribution.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| v0.9.0 | >=8.3 | MIT | |
| v0.8.4 | >=8.1 | MIT | |
| v0.8.3 | >=8.1 | MIT | |
| v0.8.2 | >=8.1 | MIT | |
| v0.8.1 | >=8.1 | MIT | |
| v0.8.0 | >=8.1 | MIT | |
| v0.7.1 | >=8.1 | MIT | |
| v0.7.0 | >=8.1 | MIT | |
| v0.6.4 | >=8.1 | MIT | |
| v0.6.3 | >=8.1 | MIT | |
| v0.6.2 | >=8.1 | MIT | |
| v0.6.1 | >=8.1 | MIT | |
| v0.6.0 | >=8.1 | MIT | |
| v0.5.1 | >=8.1 | MIT | |
| v0.5.0 | MIT | ||
| v0.4.4 | MIT | ||
| v0.4.3 | MIT | ||
| v0.4.2 | MIT | ||
| v0.4.1 | MIT | ||
| v0.4.0 | MIT | ||
| v0.3.1 | MIT | ||
| v0.3.0 | MIT | ||
| v0.2.1 | MIT | ||
| v0.2.0 | MIT | ||
| v0.1.0 | MIT |