PHPackages                             illuminatech/array-factory - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. illuminatech/array-factory

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

illuminatech/array-factory
==========================

Allows DI aware object creation from array definition

1.2.7(1mo ago)2159.6k↓19.7%13BSD-3-ClausePHPCI passing

Since Feb 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/illuminatech/array-factory)[ Packagist](https://packagist.org/packages/illuminatech/array-factory)[ GitHub Sponsors](https://github.com/klimov-paul)[ Patreon](https://www.patreon.com/klimov_paul)[ RSS](/packages/illuminatech-array-factory/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (12)Used By (3)

 [ ![](https://avatars1.githubusercontent.com/u/47185924) ](https://github.com/illuminatech)

Laravel Array Factory
=====================

[](#laravel-array-factory)

This extension allows DI aware object creation from array definition.

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://camo.githubusercontent.com/ac88a0b7e1a44e814f6d6f1cb25d2227fa54832453a6b43b7d3b0d0f353aafc0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d696e61746563682f61727261792d666163746f72792e737667)](https://packagist.org/packages/illuminatech/array-factory)[![Total Downloads](https://camo.githubusercontent.com/659ecc3b232ae8413d6e557f0a3ca82e4cb31d39c734479839a24cc96d76aacc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c6c756d696e61746563682f61727261792d666163746f72792e737667)](https://packagist.org/packages/illuminatech/array-factory)[![Build Status](https://github.com/illuminatech/array-factory/workflows/build/badge.svg)](https://github.com/illuminatech/array-factory/actions)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist illuminatech/array-factory

```

or add

```
"illuminatech/array-factory": "*"
```

to the require section of your composer.json.

Usage
-----

[](#usage)

This extension allows DI aware object creation from array definition. Creation is performed by factory defined via `\Illuminatech\ArrayFactory\FactoryContract` contract. `\Illuminatech\ArrayFactory\Factory` can be used for particular implementation. Such factory allows creation of any object from its array definition. Keys in definition array are processed by following rules:

- '\_\_class': string, full qualified name of the class to be instantiated.
- '\_\_construct()': array, arguments to be bound during constructor invocation.
- 'methodName()': array, list of arguments to be passed to the object method, which name defined via key.
- 'fieldOrProperty': mixed, value to be assigned to the public field or passed to the setter method.
- '()': callable, PHP callback to be invoked once object has been instantiated and all other configuration applied to it.

Imagine we have the following class defined at our project:

```
