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