Download the PHP package coapsyfactor/objectfactory without Composer
On this page you can find all versions of the php package coapsyfactor/objectfactory. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coapsyfactor/objectfactory
More information about coapsyfactor/objectfactory
Files in coapsyfactor/objectfactory
Package objectfactory
Short Description Factory that provides instances of object mapped to related interface
License proprietary
Informations about the package objectfactory
Object Factory
In this document you can find proper usage of this library.
About
This library is used to easily retrieve instance of certain object without the need to provide all of its dependencies.
Requirements
- PHP: >=7.4
Overview
This library ensure to provide proper instance of object implementing certain interface, or being certain type of a class. Dependencies are required to be complex type as primitive ones (string, int, float, bool) cannot be exactly auto determined. There are two ways of defining "provider" for certain interface.
Usage
First approach is providing simple map between interface and class itself, to do so we need to call registerInterfaceClass
method.
Note: Use this only when providing class has complex typed dependencies, providing class with primitive types will cause exception to be thrown.
Note: Library handle circular dependencies by throwing exception when one is detected.
Another approach is using provider callback- function that is called when instance is requested, to achieve this we need to call registerInterfaceInstanceProvider
.
This approach is usually useful when object depends on primitive types.
There are two ways to retrieve instance of certain type. One is getInstance
which always returns new instance of requested type.
And there is also another way by using getSharedInstance
which always return signleton instance of requested model.