Download the PHP package buffalokiwi/buffalotools_ioc without Composer
On this page you can find all versions of the php package buffalokiwi/buffalotools_ioc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download buffalokiwi/buffalotools_ioc
More information about buffalokiwi/buffalotools_ioc
Files in buffalokiwi/buffalotools_ioc
Package buffalotools_ioc
Short Description IOC / Service Locator for PHP 8
License MIT
Homepage https://github.com/SixArmDonkey/buffalotools_ioc
Informations about the package buffalotools_ioc
BuffaloKiwi IOC / Service Locator
A fast, simple and straightforward inversion of control / service locator library for PHP 7.4.
MIT License
Installation
The Basics
This container will maintain a single reference to any registered service.
- Services are registered by calling addInterface(). The supplied closure contains the call to new class().
- Services are instantiated on demand, and no instance is created unless newInstance() is called.
- Calling getIntance() will call newInstance() once and cache the result.
- Subsequent calls to getIntance() will return the cached instance.
- This container is not meant to be passed around to various classes.
- All services should be registered in a single location (composition root), and should be automatically injected into constructors via some router.
- When constructing the container, specifying strict mode will test that the instance returned by the closure supplied to addInstance() matches the interface supplied to addInstance() when calling newInstance().
Example
Note: Using the ::class suffix is a shortcut to the fully namespaced class name, and will NOT trigger the autoloader.
Note 2: DO NOT add "use" statements when registering objects with the container. This WILL trigger the autoloader.
Always use the fully namespaced class or interface name (preferably an interface).
Autowire method
The container contains a method autowire(). This will attempt to automatically determine values for some class constructor. Variables can be passed in arg#2 as a named map.
Argument Mapper
An instance of IArgumentMapper may be supplioed to the constructor of class IOC. When calling autowire(), the mapper is first checked for a class/interface name matching the one supplied to autowire(). If found, the arguments contained within the mapper are merged with the $args array supplied to autowire() with $args taking precedence. This can be used to move certain configuration elements to a different location.