Download the PHP package syberisle/zit without Composer
On this page you can find all versions of the php package syberisle/zit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download syberisle/zit
More information about syberisle/zit
Files in syberisle/zit
Package zit
Short Description Zit is a simple dependency injector based heavily on Pimple. It aims to provide the same simplicity as Pimple while offering a slightly more robust object interface.
License MIT
Homepage https://github.com/syberisle/Zit
Informations about the package zit
Zit
Zit is a simple dependency injector based heavily on Pimple. It aims to provide the same simplicity as Pimple while offering a slightly more robust object interface.
Installation
Zit is available via Composer:
Usage
Zit is simple to use. Like Pimple, objects are defined through anonymous functions that return an instance of the object:
All instantiation functions are passed the container as the first argument, making dependency injection possible:
Zit also provides convenient magic methods for setting instantiation functions:
Getting Objects
Getting objects are as simple as:
Or, if you prefer the shorthand:
Getting Fresh Objects
By default, all objects are shared in Zit. That is, once an object is created, that same exact object is
returned for each additional get()
. If you need a fresh object, you can do so with:
Note that because the 'new' keyword is reserved, you can only use it if you're using the magic methods.
Constructor Parameters
Sometimes you need to pass parameters to the constructor of an object, while still also injecting dependencies. Zit automatically passes all parameters on to your instantiation function:
Storing Static Content
You can also use Zit to store strings/objects/etc. Just pass it instead of a generator:
Please note: You must wrap callables with an instantiation function if you want the callable returned rather than the return value of the callable.
Custom Container
Most projects will benefit from a custom container that sets up its own injection rules. This is as simple as extending Zit:
Change Log
Version 3.0.0
- Implemented Container Interoperability. Zit was already
container-interop
compatible, but it now implements the interface and throws an exception that implementsInterop\Container\Exception\NotFoundException
when a item is not found. This exception extends\InvalidArgumentException
, so 3.0.0 should be nearly 100% backwards-compatible, but I'm bumping the major version just in case. - Dropped support for PHP 5.3
- Removed deprecated function
setParam
setFactory()
now accepts anycallable
instead of specifically aClosure
- Fixed a typo in the exception message thrown from
__call
if a method does not exist set()
is now fluent (returns the container for chaining)- Switched to md4 hashing for speed improvements (we don't need the security of md5)
- Added DocBlocks throughout the code
Version 2.0
- Removed the
setParam
method in favor of checking whether the parameter passed toset
is callable. - Added the "Factory" variant. This could cause backwards compatibility issues if you have set up objects that end with the word "factory".
- Updated the
delete
method so that it clears out objects, callbacks, and factories, which could have some abnormal BC issues as well.