Overview

Packages

  • Injector

Classes

  • Horde_Injector
  • Horde_Injector_Binder_AnnotatedSetters
  • Horde_Injector_Binder_Closure
  • Horde_Injector_Binder_Factory
  • Horde_Injector_Binder_Implementation
  • Horde_Injector_DependencyFinder
  • Horde_Injector_Exception
  • Horde_Injector_TopLevel

Interfaces

  • Horde_Injector_Binder
  • Horde_Injector_Scope
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * TODO
 4:  *
 5:  * @author   Bob Mckee <bmckee@bywires.com>
 6:  * @author   James Pepin <james@jamespepin.com>
 7:  * @category Horde
 8:  * @package  Injector
 9:  */
10: class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder
11: {
12:     /**
13:      * TODO
14:      */
15:     private $_implementation;
16: 
17:     /**
18:      * @var Horde_Injector_DependencyFinder
19:      */
20:     private $_dependencyFinder;
21: 
22:     /**
23:      * TODO
24:      */
25:     public function __construct($implementation,
26:                                 Horde_Injector_DependencyFinder $finder = null)
27:     {
28:         $this->_implementation = $implementation;
29:         $this->_dependencyFinder = is_null($finder)
30:             ? new Horde_Injector_DependencyFinder()
31:             : $finder;
32:     }
33: 
34:     /**
35:      * TODO
36:      *
37:      * @return TODO
38:      */
39:     public function getImplementation()
40:     {
41:         return $this->_implementation;
42:     }
43: 
44:     /**
45:      * TODO
46:      *
47:      * @return boolean  Equality.
48:      */
49:     public function equals(Horde_Injector_Binder $otherBinder)
50:     {
51:         return (($otherBinder instanceof Horde_Injector_Binder_Implementation) &&
52:                 ($otherBinder->getImplementation() == $this->_implementation));
53:     }
54: 
55:     /**
56:      * TODO
57:      */
58:     public function create(Horde_Injector $injector)
59:     {
60:         $reflectionClass = new ReflectionClass($this->_implementation);
61:         $this->_validateImplementation($reflectionClass);
62:         return $this->_getInstance($injector, $reflectionClass);
63:     }
64: 
65:     /**
66:      * TODO
67:      */
68:     protected function _validateImplementation(ReflectionClass $reflectionClass)
69:     {
70:         if ($reflectionClass->isAbstract() || $reflectionClass->isInterface()) {
71:             throw new Horde_Injector_Exception('Cannot bind interface or abstract class "' . $this->_implementation . '" to an interface.');
72:         }
73:     }
74: 
75:     /**
76:      * TODO
77:      */
78:     protected function _getInstance(Horde_Injector $injector,
79:                                     ReflectionClass $class)
80:     {
81:         return $class->getConstructor()
82:             ? $class->newInstanceArgs($this->_dependencyFinder->getMethodDependencies($injector, $class->getConstructor()))
83:             : $class->newInstance();
84:     }
85: 
86: }
87: 
API documentation generated by ApiGen