Download the PHP package paysera/lib-object-wrapper without Composer
On this page you can find all versions of the php package paysera/lib-object-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download paysera/lib-object-wrapper
More information about paysera/lib-object-wrapper
Files in paysera/lib-object-wrapper
Download paysera/lib-object-wrapper
More information about paysera/lib-object-wrapper
Files in paysera/lib-object-wrapper
Vendor paysera
Package lib-object-wrapper
Short Description Wrapper around JSON-decoded data that lets easily get structured items
License
Package lib-object-wrapper
Short Description Wrapper around JSON-decoded data that lets easily get structured items
License
Please rate this library. Is it a good library?
Informations about the package lib-object-wrapper
ObjectWrapper
This library provides class that lets easily get structured items from JSON-decoded data.
Why?
So that it would be easier and quicker to:
- check correct data types. This allows to use PHP7 static type-hints easily;
- check required keys/items;
- give defaults to missing items;
- provide information about exact place in object tree where the data fails your requirements.
Usage
Methods
$data[$key]
- use array accessor to get any value inside, returnsnull
if it's unavailable. If value is object, instance ofObjectWrapper
will be returned;getRequired
. Returns mixed value, but checks that it is provided;getRequiredBool
. Returnsbool
;getBool
. Returnsbool
ornull
;getRequiredFloat
. Returnsfloat
. Acceptsint
, but casts it tofloat
;getFloat
. Returnsfloat
ornull
. Acceptsint
, but casts it tofloat
;getRequiredInt
. Returnsint
;getInt
. Returnsint
ornull
;getRequiredObject
. Returns anotherObjectWrapper
instance;getObject
. Returns anotherObjectWrapper
instance ornull
;getRequiredString
. Returnsstring
;getString
. Returnsstring
ornull
;getArray
. Returnsarray
. If no item is provided, returns empty array, so nogetRequiredArray
is available;getArrayOfBool
. Returnsarray
, all it's items arebool
(or it's empty);getArrayOfFloat
. Returnsarray
, all it's items arefloat
(or it's empty);getArrayOfInt
. Returnsarray
, all it's items areint
(or it's empty);getArrayOfString
. Returnsarray
, all it's items arestring
(or it's empty);getArrayOfObject
. Returnsarray
, all it's items are instances ofObjectWrapper
(or it's empty).getDataAsArray
. Returnsarray
, all it's items arearray
or primitive types.getOriginalData
. ReturnsstdClass
, the original data passed to constructor.
Some things to keep in mind
stdClass
is used for objects - this is default forjson_decode
. This is to easily check where the data was an object and where it was an array. For example, if empty object or empty array is passed as JSON and you denormalize to an array, there is no way to check what was the type of original data;null
values are treated the same as it would not be provided at all:- it will not throw
InvalidItemTypeException
if you providenull
and some type was expected (even array or object); - it will throw
MissingItemException
even if you provide the value but it isnull
;
- it will not throw
- the object cannot be modified - setting or unsetting anything is not supported.
All versions of lib-object-wrapper with dependencies
PHP Build Version
Package Version
Requires
php Version
^7.1 || ^8.0
The package paysera/lib-object-wrapper contains the following files
Loading the files please wait ....