Download the PHP package andrew-gos/class-builder without Composer
On this page you can find all versions of the php package andrew-gos/class-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrew-gos/class-builder
More information about andrew-gos/class-builder
Files in andrew-gos/class-builder
Package class-builder
Short Description Advanced library for building objects from arrays or other types
License MIT
Informations about the package class-builder
Class Builder Library
Version 1.2.3
Description
This library provides functionality to build objects from arrays or scalars.
The library allows the construction of interfaces, abstract classes, arrays of objects. It also supports the construction of object parameters whose type is an array with typed elements. There is the possibility to build variadic parameters from arrays. Additionally, you can build classes with a single required parameter from scalar values. Parameters can also be assembled where the type is an intersection or union of types.
The library gathers information about object parameters from the constructor's parameters.
Contacts
If you encounter a bug or have an idea, please write to [email protected] and type Telegram Library Bug
or Telegram Library Idea
in the email header.
Installation
To install the library, use Composer:
Simple example
To build an object, write:
Building abstract classes and interfaces
To build an interface or an abstract class, specify the available inheritors using the AvailableInheritors
attribute. \
The first successfully built object will be returned. \
This attribute can take array of inheritors. \
Note, that if you make class parameter type as intersection of types, then this library will build inheritors, which contained in every interface or class in type
Data checkers for building
To control the building of interfaces or abstract classes, you can use the BuildIf
attribute for the inheriting classes. \
This attribute instructs the builder to check the data before building. If the check fails, the builder will not construct the object. \
BuildIf
attribute can take object of CheckerInterface
attribute.
In this example, an object of class B
will be built only if the data contains a field type
equal to b
.
Building typed arrays
To build typed arrays, use the ArrayType
attribute. The attribute can take one type, an array of types, or an ArrayType
object as a parameter.
Building objects from scalars
If an object has only one required parameter, the library allows building such objects from scalar values. Use the CanBeBuiltFromScalar
attribute.
Get values from fields with custom names
If you want, you can redefine the field from which the value for the object property assembly is taken. \
To do it, use Field
attribute.
All versions of class-builder with dependencies
ext-ctype Version *