Documentation
Usage Instruction
require_once '/path/to/witty.php';
Witty::init();
$log = Witty::factory('Log');
$log->error('something wrong happened!');
Witty Class provides factory and instance function, so module self don't need to implenment these methods. it also makes a unified class creation.
Configuration
some module may need configuration, there are two ways to do this
// method 1
// pass config when init class
require_once '/path/to/witty.php';
Witty::init();
$log_config = array(
'key1' => 'val1',
'key2' => 'val2',
);
$log = Witty::factory('Log', $log_config);
// method 2
// set config path, let witty find and load config automaticly
// config path may looks like this: config/cache.php
// within cache.php
// array( // key is class name
// 'key1' => 'val1',
// 'key2' => 'val2',
// ),
// );
require_once '/path/to/witty.php';
Witty::init();
Witty::set_config_path('/path/to/witty/config');
// witty will look for /path/to/witty/config/cache.php
// if return array has 'Cache' key , its value will be used for config
Witty::instance('Cache');
Extend
class My_Request
{
public function foo(&parent, $param)
{
// even $parent's protected/private method
$url = $parent->url;
//...
}
}
$request = Witty::instance('Request');
$request->attach_behavior('My_Request');
$request->foo('hello world');