Re: staticOptions - setting defaults for various classes...

From: Date: Fri, 21 Jun 2002 05:30:07 +0000
Subject: Re: staticOptions - setting defaults for various classes...
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-7257@lists.php.net to get a copy of this message
On Thu, 2002-06-20 at 07:16, Alan Knowles wrote: > Ive been a busy bee, building a whole app, attempting to use as many > pear classes as possible.. one of the things that appears to be missing > is a way to set the default options on various classes > > an example would be: > Mail: default factory method/host etc. > HTML_Quickforms_date: date format and range.. > > I'm sure there are a few more classes that take options of some sort for > class initiation that could do with a 'site-wide' mechanism of > pre-setting the defaults.., the mechanism below is what I have ended up > using for DB_DataObject, > > at the application start point.. > require_once('DB/DataObject.php'); > require_once('Mail.php'); > require_once('HTML_QuickForms_date'); > > $config = parse_ini_file('myconfig.ini'); > > DB_DataObject::staticOptions($config['DB_DataObject']); > Mail::staticOptions($config['Mail']); > HTML_QuickForms_date::staticOptions($config['HTML_QuickForms_date']); > > obviously this could be done using the Config class as well, using > $config->getValues('/DB/DataObject'); as well.. or any other method that > the user prefers.... > > the staticOptions method looks like this.. > > /** > * Get/Set the Options using array or object > * > * to fetch: use $options = &DB_DataObject::staticOptions(); > * to set DB_DataObject::staticOptions(); > * or DB_DataObject::staticOptions(array('database'=>'mysql.....')); > * @param object Config (Optional) or string ('realm') > * @param array Options > * @access public > * @return array Options > */ > function &staticOptions() { > static $options = array(); > if ($args = &func_get_args()) { > $options = $args[0]; > } > return $options; > } > > for something like HTML_QuickForms_date the change would look > something like this.. > > > > Function HTML_QuickForm_date ($elementName, $value=null, $new_options=array()) > { > $options = HTML_QuickForm_date::staticOptions(); // copy not reference > foreach ($new_options as $k=>$v) { > $options[$k] = $v; > } > HTML_QuickForm_element::HTML_QuickForm_element($options); > ......... > > > Anyway - anybody got any thoughts on this?? PEAR_Config could be a nice base class for this because of its layering features (which will let you keep system-wide and site-wide options, for example). And PEAR_Config is always installed. - Stig -- Stig Sæther Bakken, Fast Search & Transfer ASA, Trondheim, Norway http://pear.php.net/wishlist.php/ssb

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