Download the PHP package graywings/instantiate without Composer
On this page you can find all versions of the php package graywings/instantiate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download graywings/instantiate
More information about graywings/instantiate
Files in graywings/instantiate
Package instantiate
Short Description Instantiate json/stdClass library
License MIT
Informations about the package instantiate
Instantiate
Instantiate is a PHP library for creating objects from various data sources with proper type handling and validation. It supports creating objects from JSON strings, stdClass objects, and associative arrays, with automatic type conversion and nested object creation.
Installation
Features
- Create objects from JSON strings, stdClass objects, or associative arrays
- Automatic type conversion based on constructor parameter types
- Support for nested objects and complex data structures
- Proper handling of default parameter values
- Type validation to ensure data integrity
- Support for nullable parameters
- Support for PHP 8.1 enum types (both backed and pure enums)
- Detailed exception messages for easier debugging
Usage
Basic Usage
Nested Objects
Instantiate automatically handles nested objects:
Type Conversion
Instantiate automatically converts values to the expected types:
Enum Types
Instantiate has full support for PHP 8.1 enums:
Default Values
Constructor default values are respected when the data doesn't include the parameter:
Exception Handling
Instantiate throws detailed exceptions when there are issues with the data:
InstantiateArgumentsException: Thrown when there are issues with the provided data, such as missing required parameters or invalid types.InstantiateException: Base exception class for all Instantiate-related exceptions.
Requirements
- PHP 8.0 or higher
- Reflection extension enabled
License
This library is released under the MIT License.