Re: PEAR_DelegateOwner

From: Date: Fri, 07 Nov 2003 14:13:40 +0000
Subject: Re: PEAR_DelegateOwner
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-23338@lists.php.net to get a copy of this message
LingWitt@insightbb.com escribió > I would at least appreciate Your work is shit! Give me something. Take it easy. See my comments below. >Has no one looked at this? Here are the files: > > in DelegateOwner.php: > > class PEAR_DelegateOwner extends PEAR > { > var $_delegates = array(); > var $_method_map = array(); > > public function addDelegate($variableRequired) > { > $args = array_values(func_get_args()); > > foreach ($args as $delegate) > { > if (!is_object($arg)) > $delegate = new $delegate; Shouldn't this be (is_string($delegate) and class_exists($delegate))? > if (!($delegate instanceof PEAR_DelegateInterface)) > continue; Should this fail silently? > $delegate->setOwner($this); > $this->_delegates[get_class($delegate)] = $delegate; > } > } > > //Classnames > public function getDelegate($variableRequired) Could this better be named getDelegates, since it returns an array? > { > $args = func_get_args(); > > foreach ($args as $arg) > { > foreach ($this->_delegates as $delegate) > { > if ($delegate instanceof $arg) > { > $results[$arg] = $delegate; > } > } > } > > return $results; > } > > //Classnames > public function removeDelegate($variableRequired) > { > $args = func_get_args(); > > foreach ($args as $arg) > { > if ($delegates = $this->getDelegate($arg)) > { > foreach ($delegates as $delegate) > { > unset($this->_delegates[get_class($delegate)]); > $this->_delegates = > $this->filterMethodMapWithDelegate($delegate); > } > } > } Can't you make a loop on $this->_delegates here, since the call to getDelegate() is going to make that anyway? > } > > > protected function cacheMethod($method) > { > foreach ($this->_delegates as $delegate) > { > if (method_exists($delegate, $method)) > { > $this->_method_map[$method] = $delegate; > return; > } I don't know much about delegation, so this might be just ignorance on my part. But how do you solve name conflicts, as in two delegates implementing the "same" method? > } > > throw new Exception("No Such Method: $method()"); > } > http://www.xavier-noguer.com/

« previous php.pear.dev (#23338) next »