Option Conventions

Many of the CSF libraries consist of a main class which has several options specific to an instance. A standard way of supplying these options has been adopted.

  • Options are stored internally as an associative array of “option” ⇒ “value”
  • Default values for these options are stored as part of the class definition, e.g.
    class CSF_Foo {
        private $_options = array(
            'option_1' => 'default',
        );
    }
  • The constructor of the class takes a single argument, which is an array of options
  • In the constructor, the supplied options are merged with the default options, so that any supplied options override their defaults:
    $this->_options = array_merge($this->_options, $options);
  • After the options have been merged, any library-specific validation or sanitization of the options is performed

An example involving the dispatch library, where all controllers are stored in the “controllers” directory and are suffixed with “Controller”:

$dispatch = new CSF_Dispatch(array(
    'controller_path' => 'controllers',
    'class_suffix' => 'Controller',
));
csf/doc/options.txt · Last modified: 2009/07/01 16:12 by alan
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki