Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wrk-flow/php-get-typed-value
Get typed (strict mode) values from an Array / XML with basic validation.
https://github.com/wrk-flow/php-get-typed-value
array php strict-types strictmode xml
Last synced: about 24 hours ago
JSON representation
Get typed (strict mode) values from an Array / XML with basic validation.
- Host: GitHub
- URL: https://github.com/wrk-flow/php-get-typed-value
- Owner: wrk-flow
- Created: 2022-06-27T15:34:00.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-27T12:59:19.000Z (8 months ago)
- Last Synced: 2024-11-09T11:42:24.245Z (11 days ago)
- Topics: array, php, strict-types, strictmode, xml
- Language: PHP
- Homepage: https://php-get-typed-value.wrk-flow.com
- Size: 2.08 MB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# php-get-typed-value
![img](https://img.shields.io/badge/PHPStan-8-blue)
![php](https://img.shields.io/badge/PHP-8.1-B0B3D6)
![coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/pionl/11b884c06da0bf9116ae763d23438ecb/raw/coverage.json)Get typed (strict mode) values from an Array / XML with basic validation.
```bash
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).```php
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](https://php-get-typed-value.wrk-flow.com).
## 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](https://wrk-flow.com) or [CONTRIBUTE](CONTRIBUTION.md). 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.