| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
stubClassLoader::load('net::stubbles::reflection::stubReflectionClass', |
|---|
| 13 |
'net::stubbles::ioc::stubBinding', |
|---|
| 14 |
'net::stubbles::ioc::stubClassBinding', |
|---|
| 15 |
'net::stubbles::ioc::stubConstantBinding', |
|---|
| 16 |
'net::stubbles::ioc::stubInjector', |
|---|
| 17 |
'net::stubbles::ioc::stubBindingScope', |
|---|
| 18 |
'net::stubbles::ioc::stubBindingScopes', |
|---|
| 19 |
'net::stubbles::ioc::annotations::stubInjectAnnotation', |
|---|
| 20 |
'net::stubbles::ioc::annotations::stubSingletonAnnotation', |
|---|
| 21 |
'net::stubbles::ioc::annotations::stubNamedAnnotation', |
|---|
| 22 |
'net::stubbles::ioc::annotations::stubImplementedByAnnotation'); |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
class stubBinder extends stubBaseObject |
|---|
| 33 |
{ |
|---|
| 34 |
|
|---|
| 35 |
* Key for storing the binder in the registry |
|---|
| 36 |
*/ |
|---|
| 37 |
const REGISTRY_KEY = 'net.stubbles.ioc.stubBinder'; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
* Injector used by this binder |
|---|
| 41 |
* |
|---|
| 42 |
* @var stubInjector |
|---|
| 43 |
*/ |
|---|
| 44 |
protected $injector = null; |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* Create a new binder |
|---|
| 48 |
* |
|---|
| 49 |
* @param stubInjector $injector |
|---|
| 50 |
*/ |
|---|
| 51 |
public function __construct(stubInjector $injector = null) |
|---|
| 52 |
{ |
|---|
| 53 |
if ($injector === null) { |
|---|
| 54 |
$this->injector = new stubInjector(); |
|---|
| 55 |
} else { |
|---|
| 56 |
$this->injector = $injector; |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
* Bind a new interface to a class |
|---|
| 62 |
* |
|---|
| 63 |
* @param string $interface |
|---|
| 64 |
* @return stubClassBinding |
|---|
| 65 |
*/ |
|---|
| 66 |
public function bind($interface) |
|---|
| 67 |
{ |
|---|
| 68 |
$binding = new stubClassBinding($this->injector, $interface); |
|---|
| 69 |
$this->injector->addBinding($binding); |
|---|
| 70 |
return $binding; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
* Bind a new constant |
|---|
| 75 |
* |
|---|
| 76 |
* @return stubConstantBinding |
|---|
| 77 |
*/ |
|---|
| 78 |
public function bindConstant() |
|---|
| 79 |
{ |
|---|
| 80 |
$binding = new stubConstantBinding(); |
|---|
| 81 |
$this->injector->addBinding($binding); |
|---|
| 82 |
return $binding; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
* Get an injector for this binder |
|---|
| 87 |
* |
|---|
| 88 |
* @return stubInjector |
|---|
| 89 |
*/ |
|---|
| 90 |
public function getInjector() |
|---|
| 91 |
{ |
|---|
| 92 |
return $this->injector; |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
?> |
|---|