Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaytaph/typearray
Typed Array
https://github.com/jaytaph/typearray
Last synced: 22 days ago
JSON representation
Typed Array
- Host: GitHub
- URL: https://github.com/jaytaph/typearray
- Owner: jaytaph
- License: bsd-3-clause
- Created: 2022-12-11T10:24:36.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-08T08:21:12.000Z (over 1 year ago)
- Last Synced: 2024-09-18T18:46:59.948Z (about 2 months ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Typed Array
Simple wrapper around property-accessor to fetch elements in a typed way. This package is created because I was fiddling around with a lot of json-arrays
that were not typed and phpstan had a big issue with that.So, instead of having `mixed[] $myarray`, we can use `TypeArray`, and fetch elements with:
```
$arr = new TypeArray(['foo' => 'string', 'bar' => 4 ]);$arr->getString('[foo]'); // always returns a string
$arr->getString('[notexists]', 'defaultval'); // Returns default val when not found$arr->getInt('[bar]'); // returns int(4)
$arr->getInt('[foo]'); // Returns InvalidTypeException as this element is a string, not an int```
See symfony propertyaccess component for the path syntax used.