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', ));