*/
private $_dependencyFinder;
- private $_setters = array();
-
/**
*
*/
*/
public function equals(Horde_Injector_Binder $otherBinder)
{
- return false;
+ return $otherBinder instanceof Horde_Injector_Binder_AnnotatedSetters;
}
/**
$instance = $this->_binder->create($injector);
$reflectionClass = new ReflectionClass(get_class($instance));
- $this->_bindAnnotatedSetters($reflectionClass);
- $this->_callSetters($injector, $instance);
+ $setters = $this->_findAnnotatedSetters($reflectionClass);
+ $this->_callSetters($setters, $injector, $instance);
return $instance;
}
/**
- */
- private function _bindAnnotatedSetters(ReflectionClass $reflectionClass)
- {
- foreach ($this->_findAnnotatedSetters($reflectionClass) as $setter) {
- $this->_setters[] = $setter;
- }
- }
-
- /**
* Find all public methods in $reflectionClass that are annotated with
* @inject.
*
{
$setters = array();
foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
- $docBlock = $reflectionMethod->getDocComment();
- if ($docBlock) {
- if (strpos($docBlock, '@inject') !== false) {
- $setters[] = $reflectionMethod->name;
- }
+ if ($this->_isSetterMethod($reflectionMethod)) {
+ $setters[] = $reflectionMethod;
}
}
}
/**
- * TODO
+ * Is a method a setter method, by the criteria we define (has a doc comment
+ * that includes @inject).
+ *
+ * @param ReflectionMethod $reflectionMethod
+ */
+ private function _isSetterMethod(ReflectionMethod $reflectionMethod)
+ {
+ $docBlock = $reflectionMethod->getDocComment();
+ if ($docBlock) {
+ if (strpos($docBlock, '@inject') !== false) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ *
*/
- protected function _callSetters(Horde_Injector $injector, $instance)
+ private function _callSetters(array $setters, Horde_Injector $injector, $instance)
{
- foreach ($this->_setters as $setter) {
- $reflectionMethod = new ReflectionMethod($instance, $setter);
- $reflectionMethod->invokeArgs(
+ foreach ($setters as $setterMethod) {
+ $setterMethod->invokeArgs(
$instance,
- $this->_dependencyFinder->getMethodDependencies($injector, $reflectionMethod)
+ $this->_dependencyFinder->getMethodDependencies($injector, $setterMethod)
);
}
}