From 765be7d8bdb7c411000fbb3df4f8bd9ce1fb2605 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 1 Feb 2010 16:47:01 -0700 Subject: [PATCH] phpdoc; coding style --- .../Injector/lib/Horde/Injector/Binder/Factory.php | 90 ++++++++++++---------- .../lib/Horde/Injector/Binder/Implementation.php | 90 ++++++++++++++-------- 2 files changed, 110 insertions(+), 70 deletions(-) diff --git a/framework/Injector/lib/Horde/Injector/Binder/Factory.php b/framework/Injector/lib/Horde/Injector/Binder/Factory.php index 1a38630d4..6a1e1a520 100644 --- a/framework/Injector/lib/Horde/Injector/Binder/Factory.php +++ b/framework/Injector/lib/Horde/Injector/Binder/Factory.php @@ -1,32 +1,43 @@ getInstance('Collaborator'), new MyOtherClass(17)); - * } - * ... + * object that satisfies the instance requirement. For example: * - * @author Bob Mckee - * @author James Pepin + * class MyFactory { + * ... + * public function create(Horde_Injector $injector) + * { + * return new MyClass($injector->getInstance('Collaborator'), new MyOtherClass(17)); + * } + * ... + * } + * + * @author Bob Mckee + * @author James Pepin * @category Horde - * @package Horde_Injector + * @package Horde_Injector */ class Horde_Injector_Binder_Factory implements Horde_Injector_Binder { + /** + * TODO + */ private $_factory; + + /** + * TODO + */ private $_method; /** - * create a new Horde_Injector_Binder_Factory instance + * Create a new Horde_Injector_Binder_Factory instance. * - * @param string $factory The factory class to use for creating objects - * @param string $method The method on that factory to use for creating objects + * @param string $factory The factory class to use for creating objects. + * @param string $method The method on that factory to use for creating + * objects. */ public function __construct($factory, $method) { @@ -34,27 +45,20 @@ class Horde_Injector_Binder_Factory implements Horde_Injector_Binder $this->_method = $method; } + /** + * TODO + */ public function equals(Horde_Injector_Binder $otherBinder) { - if (!$otherBinder instanceof Horde_Injector_Binder_Factory) { - return false; - } - - if ($otherBinder->getFactory() != $this->_factory) { - return false; - } - - if ($otherBinder->getMethod() != $this->_method) { - return false; - } - - return true; + return (($otherBinder instanceof Horde_Injector_Binder_Factory) && + ($otherBinder->getFactory() == $this->_factory) && + ($otherBinder->getMethod() == $this->_method)); } /** - * get the factory classname that this binder was bound to + * Get the factory classname that this binder was bound to. * - * @return string The factory classname this binder is bound to + * @return string The factory classname this binder is bound to. */ public function getFactory() { @@ -62,9 +66,9 @@ class Horde_Injector_Binder_Factory implements Horde_Injector_Binder } /** - * get the method that this binder was bound to + * Get the method that this binder was bound to. * - * @return string The method this binder is bound to + * @return string The method this binder is bound to. */ public function getMethod() { @@ -74,21 +78,27 @@ class Horde_Injector_Binder_Factory implements Horde_Injector_Binder /** * Create instance using a factory method * - * If the factory depends on a Horde_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. + * If the factory depends on a Horde_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 Horde_Injector. When a - * Horde_Injector is requested from a Horde_Injector it will return itself. - * This means that the factory will only ever be able to work on the child - * Horde_Injector we give it now. + * Horde_Injector is requested from a Horde_Injector it will return + * itself. This means that the factory will only ever be able to work on + * the child Horde_Injector we give it now. * - * @param Horde_Injector $injector + * @param Horde_Injector $injector Injector object. + * + * @return TODO */ public function create(Horde_Injector $injector) { $childInjector = $injector->createChildInjector(); - // we use getInstance here because we don't want to have to create this - // factory more than one time to create more objects of this type. + + /* We use getInstance() here because we don't want to have to create + * this factory more than one time to create more objects of this + * type. */ return $childInjector->getInstance($this->_factory)->{$this->_method}($childInjector); } + } diff --git a/framework/Injector/lib/Horde/Injector/Binder/Implementation.php b/framework/Injector/lib/Horde/Injector/Binder/Implementation.php index 96f3b5a79..66928a321 100644 --- a/framework/Injector/lib/Horde/Injector/Binder/Implementation.php +++ b/framework/Injector/lib/Horde/Injector/Binder/Implementation.php @@ -1,46 +1,62 @@ - * @author James Pepin + * @author Bob Mckee + * @author James Pepin * @category Horde - * @package Horde_Injector + * @package Horde_Injector */ class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder { + /** + * TODO + */ private $_implementation; + + /** + * TODO + */ private $_setters; + /** + * TODO + */ public function __construct($implementation) { $this->_implementation = $implementation; $this->_setters = array(); } + /** + * TODO + */ public function getImplementation() { return $this->_implementation; } + /** + * TODO + */ public function bindSetter($method) { $this->_setters[] = $method; return $this; } + /** + * TODO + */ public function equals(Horde_Injector_Binder $otherBinder) { - if (!$otherBinder instanceof Horde_Injector_Binder_Implementation) { - return false; - } - - if ($otherBinder->getImplementation() != $this->_implementation) { - return false; - } - - return true; + return (($otherBinder instanceof Horde_Injector_Binder_Implementation) && + ($otherBinder->getImplementation() == $this->_implementation)); } + /** + * TODO + */ public function create(Horde_Injector $injector) { $reflectionClass = new ReflectionClass($this->_implementation); @@ -50,47 +66,60 @@ class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder return $instance; } + /** + * TODO + */ private function _validateImplementation(ReflectionClass $reflectionClass) { if ($reflectionClass->isAbstract() || $reflectionClass->isInterface()) { - throw new Horde_Injector_Exception('Cannot bind interfaces or abstract classes "' . - $this->_implementation . '" to an interface.'); + throw new Horde_Injector_Exception('Cannot bind interfaces or abstract classes "' . $this->_implementation . '" to an interface.'); } } - private function _getInstance(Horde_Injector $injector, ReflectionClass $class) + /** + * TODO + */ + private function _getInstance(Horde_Injector $injector, + ReflectionClass $class) { - if ($class->getConstructor()) { - return $class->newInstanceArgs( - $this->_getMethodDependencies($injector, $class->getConstructor()) - ); - } - return $class->newInstance(); + return $class->getConstructor() + ? $class->newInstanceArgs($this->_getMethodDependencies($injector, $class->getConstructor())) + : $class->newInstance(); } - private function _getMethodDependencies(Horde_Injector $injector, ReflectionMethod $method) + /** + * TODO + */ + private function _getMethodDependencies(Horde_Injector $injector, + ReflectionMethod $method) { $dependencies = array(); + foreach ($method->getParameters() as $parameter) { $dependencies[] = $this->_getParameterDependency($injector, $parameter); } + return $dependencies; } - private function _getParameterDependency(Horde_Injector $injector, ReflectionParameter $parameter) + /** + * TODO + */ + private function _getParameterDependency(Horde_Injector $injector, + ReflectionParameter $parameter) { if ($parameter->getClass()) { - $dependency = $injector->getInstance($parameter->getClass()->getName()); + return $injector->getInstance($parameter->getClass()->getName()); } elseif ($parameter->isOptional()) { - $dependency = $parameter->getDefaultValue(); - } else { - throw new Horde_Injector_Exception('Unable to instantiate class "' . $this->_implementation . - '" because a value could not be determined untyped parameter "$' . - $parameter->getName() . '"'); + return $parameter->getDefaultValue(); } - return $dependency; + + throw new Horde_Injector_Exception('Unable to instantiate class "' . $this->_implementation . '" because a value could not be determined untyped parameter "$' . $parameter->getName() . '"'); } + /** + * TODO + */ private function _callSetters(Horde_Injector $injector, $instance) { foreach ($this->_setters as $setter) { @@ -101,4 +130,5 @@ class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder ); } } + } -- 2.11.0