Download the PHP package illuminatech/array-factory without Composer

On this page you can find all versions of the php package illuminatech/array-factory. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package array-factory

Laravel Array Factory


This extension allows DI aware object creation from array definition.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

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:

Imagine we have the following class defined at our project:

Instance of such class can be instantiated using array factory in the following way:

The main benefit of array object definition is lazy loading: you can define entire object configuration as a mere array without even loading the class source file, and then instantiate actual object only in case it becomes necessary.

Defined array configuration can be adjusted, applying default values for it. For example:

You may use \Illuminatech\ArrayFactory\Facades\Factory facade for quick access to the factory functionality. For example:

Service configuration

The most common use case for array factory is creation of the universal configuration for particular application service. Imagine we create a library providing geo-location by IP address detection. Since there are plenty of external services and means to solve this task, we have created some high level contract, like following:

This contract may have multiple different implementations: each per each different approach and service. Each particular implementation provides its own set of configuration parameters, which can not be unified. Using array factory, we can define a service provider for such library in following way:

This allows developer to specify any particular detector class to be used along with its configuration. The actual configuration file 'config/geoip.php' may look like following:

It can also look like following:

Both configuration will work fine with the service provider we created, and same will be for countless other possible configurations for different geo-location detectors, which may not even exist yet.

Heads up! Remember to avoid usage of \Closure, while creating application configuration, otherwise you will face the error during configuration caching.

Interaction with DI container

\Illuminatech\ArrayFactory\Factory is DI aware: it performs object instantiation via \Illuminate\Contracts\Container\Container::make(). Thus bindings set within the container will affect object creation. For example:

Note: obviously, in case there is a DI container binding for the instantiated class, the key '__construct()' inside array configuration will be ignored.

DI container is also used during configuration method invocations, allowing automatic arguments injection. For example:

Note that final handler callback ('()' configuration key) is not DI aware and does not provide binding for its arguments. However, the factory instance is always passed as its second argument, allowing you to access to its DI container if needed. Following code will produce the same result as the one from previous example:

Standalone configuration

You may use array factory to configure or re-configure already existing objects. For example:

Type ensuring

You may add extra check whether created object matches particular base class or interface, using ensure() method. For example:

Immutable methods handling

\Illuminatech\ArrayFactory\Factory handles immutable methods during object configuration, returning new object from their invocations. For example: in case we have following class:

The following configuration will be applied correctly:

Note: since there could be immutable method invocations during configuration, you should always use result of \Illuminatech\ArrayFactory\FactoryContract::configure() method instead of its argument.

Recursive make

For complex object, which stores other object as its inner property, there may be need to configure both host and resident objects using array definition and resolve them both via array factory. For this case definition like following may be created:

However, nested definitions are not resolved by array factory automatically. Following example will not instantiate engine instance:

This is done in order to allow setup of the slave internal configuration into created object, so it be can resolved in lazy way according to its own internal logic.

However, you may enforce resolving of the nested definition wrapping it into \Illuminatech\ArrayFactory\Definition instance. For example:


All versions of array-factory with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package illuminatech/array-factory contains the following files

Loading the files please wait ....