Closure
in package
implements
Binder
A binder object for binding an interface to a closure.
An interface may be bound to a closure. That closure must accept a Horde\Injector and return an object that satisfies the instance requirement. For example:
$injector->bindClosure('database', function($injector) { return new my_mysql(); });
Tags
Interfaces, Classes, Traits and Enums
- Binder
- Describes a binding class that is able to create concrete object instances.
Table of Contents
- $closure : Closure
- __construct() : mixed
- Create a new Closure instance.
- create() : mixed
- Create instance using a closure.
- equals() : bool
- Determine if one binder equals another binder
- getClosure() : callable
- Get the closure that this binder was bound to.
Properties
$closure
private
Closure
$closure
Methods
__construct()
Create a new Closure instance.
public
__construct(Closure $closure) : mixed
Parameters
- $closure : Closure
-
The closure to use for creating objects.
Return values
mixed —create()
Create instance using a closure.
public
create(Injector $injector) : mixed
If the closure depends on a Horde\Injector we want to limit its scope so it cannot change anything that effects any higher-level scope. A closure should not have the responsibility of making a higher-level scope change. To enforce this we create a new child Horde\Injector\Injector. When a Injector is requested from a Injector it will return itself. This means that the closure will only ever be able to work on the child Injector we give it now.
Parameters
- $injector : Injector
-
Injector object.
Return values
mixed —The object or value created from the closure.
equals()
Determine if one binder equals another binder
public
equals(Binder $otherBinder) : bool
Parameters
- $otherBinder : Binder
Return values
bool —Equality.
getClosure()
Get the closure that this binder was bound to.
public
getClosure() : callable
Return values
callable —The closure this binder is bound to.