Adding Tools
Tools have to be declared into the kit's metadata file. Its name shall be a valid PHP name.
The Tool's class definition will have to be provided either by one of the kit's library files wihtin the [load_files] section, or by another kits listed as a dependancy.
You may add a cofniguration file for the Tool wich will be imported into the Tool's instance. You have to name it as the Tool's name followed by .tool.ini
.
Let's add a HttpRealmTool
tool, named realm
to the kit example
. The Tool's class is provided by the kit webappkit.httprealm
. We edit the example
kit's metadata file (which is example.wak/wak.ini
) as below :
[load_kits]
10 = "webappkit.httprealm"
[tools]
realm = "HttpRealmTool"
Then we create a config file (Which there set the users list) named realm.tool.ini
. The config file format will be specific to each Tool class. We can then use the Tool, with a kit-specific configuration, with :
// getting the "example" kit
$example=&Webappkit::getkit('example');
// using the "realm" tool
$example->realm->login();
Building Tools
Tools have to extend the WakTool
class.
They must implement the Factory method for instanciation :
class ExampleTool extends WakTool {
/**
* a Factory function : every Tool has to implement it
* this is because some PHP limitations
* @static
* @param string $kit kit's id
* @param array $cfg configuration data taken from ini file
* @return object tool's instance
*/
static function Factory($kit,$cfg) {
return new ExampleTool($kit,$cfg);
}
/**
* @var array the default configuration values
*/
protected $cfg=array(
'section'=>array(
'var'=>'value'));
}
Data from the configuration file will be dumped into $cfg.