Download the PHP package holgerk/jiggle without Composer
On this page you can find all versions of the php package holgerk/jiggle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package jiggle
php-jiggle
Jiggle is a depency injection container for php 5.3+
By default every dependency is a singleton. If you assign an function to to the container it is considered as an singleton factory. So the function is only called once when the dependency is required the first time.
Methods
singleton($class)
Create a singleton factory for the given class
- param string $class the class which should be instantiated
- return callable
create($class)
Create an object of the given class
If the class constructor has arguments they are injected from the current jiggle instance.
- param string $class the class to instantiate
- return object the newly created instance
inject($callable, $overloadedDeps = array())
Executes the given callable
If the callable has arguments they are injected from the current jiggle instance.
- param callable $callable the callable to invoke
- param array $overloadedDeps optional additional or overloaded dependencies
- return mixed return value of the invoked callable
replace($name, $value)
Replace an existing dependency
Usefull if one would like to mock some part of a bigger system or for clients to replace an unwanted implementation.
- param string $name of the dependency to replace
- param mixed $value replacement implementation
resolver($callable)
Let one provide a callable which is called if a dependency is not resolvable
If the provided resolver can resolve the dependency it should simply return it. If the dependency could not resolved the resolver needs to throw an exception, otherwise the dependency would be resolved to null.
- param callable $callable the resolver callabe
Examples
Set and get dependencies
Lazy loading with factory functions
Basic wiring of dependencies
Implicit injection of depencies into singleton factory functions
Explicit injection of depencies into any function
Explicit injection with dependency overloading
Basic instantiation
Instantiation with implicit constructor injection
Short form of implicit constructor injection
Basic function dependency
Existing deps could not replaced by accident
Existing deps could be replaced implicitly
Isset support
Resolver is called for unresolvable deps
Composer
License
The MIT License (MIT)
Copyright (c) 2013 Holger Kohnen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.