Download the PHP package bluepsyduck/common without Composer
On this page you can find all versions of the php package bluepsyduck/common. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bluepsyduck/common
More information about bluepsyduck/common
Files in bluepsyduck/common
Package common
Short Description Some classes commonly used in other projects.
License GPL-3.0-or-later
Homepage https://github.com/BluePsyduck/Common
Informations about the package common
BluePsyduck's Common Library
This library contains some classes commonly used in other projects.
DataBuilder
The data builder is a class helping with building up an array with different values, ensuring that the values have the correct type. With all methods a default value can be specified which should be ignored and not added to the data array.
The data builder provides several methods for automatically casting the set values:
- setBoolean(): Sets a boolean value.
- setInteger(): Sets an integer number.
- setFloat(): Sets a floating point number.
- setString(): Sets a string value.
- setDateTime(): Sets a date and time value in the specified format. If the passed value is not a
DateTime
instance, the value gets ignored automatically. - setArray(): Sets an array of value, optionally with a mapping method to e.g. cast each value.
Example
DataContainer
The data container wraps around a deep array and is able to access and map the elements of the array without the need to check if any level key exists. All methods provide a default value to fall back to when a key is not defined.
The data container provides several methods to automatically map the data:
- getBoolean(): Reads a boolean value.
- getInteger(): Reads an integer number.
- getFloat(): Reads a floating point number.
- getString(): Reads a string value.
- getDateTime(): Reads a date and time value. An integer value will be interpreted as Unix timestamp, a string value as date string.
- getArray(): Reads an array value.
- getObject(): Reads the value and returns a new
DataContainer
instance with that value. - getObjectArray(): Reads an array value and casts every item to a new instance of
DataContainer
.
Example
ReflectionTrait
This trait provides some methods to easily access non-public properties and invoke non-public methods of classes to be used in tests.
- injectProperty(): Injects a value into the specified property.
- extractProperty(): Extracts the value of the specified property.
- invokeMethod(): Invokes the specified method and returns its result value.