Anatomy of a Module
Modules are the most powerful and general-purpose of the four types of extensions. Modules are structurally very simple – they simply extend the Modules class with a class named after the filename and its containing directory, using camelization rules.
Modules primarily interact with the Chyrp Lite environment by providing methods that correspond to trigger calls and filters.
class CamelizedFolderName extends Modules {
# Camelization accepts hyphens and underscores: foo-bar and foo_bar
public function this_is_a_callback($arg) {
# Do your thing
}
public function this_is_a_filter($target, $arg) {
# Do your thing to $target
return $target;
# You may also take $target by reference and not have to return it.
}
}
Module Functions
Modules do not have any required functions, but they can optionally implement several utility functions.
Utility Functions
public function __init()
This function is called after all modules and feathers are instantiated. This function is preferable to __construct()
for interacting with the Chyrp Lite environment, because it will be called once every extension is ready to react to triggers.
public static function __install()
This function is called when the module is enabled. Use this for setting up configuration settings, creating database tables, adding group permissions, etc.
public static function __uninstall($confirm)
This function is called when the module is disabled. If your module has a confirm
metadata item then the $confirm
argument will be true
if the user responded affirmatively.
In typical usage, __uninstall()
drops any database tables (only if $confirm
is true
– but that's up to you), removes configuration settings, and removes group permissions that the module added.
Construct Functions
The Modules class provides a few functions intended to be used in __construct()
or __init()
:
$this->setPriority()
This function is used for registering a trigger responder in your module with a numeric priority. Prioritized functions will be executed, in ascending order of priority, before all other functions for a given trigger.
A typical use of this function is ensuring your module's trigger responder is called before another:
function __init() {
$this->setPriority("markup_post_text", 8);
}
$this->addAlias()
This function is used for registering a trigger responder using a different function name in your module. The optional third parameter is the numeric priority for your trigger responder; the default is 10.
function __init() {
$this->addAlias("markup_post_text", "foo_bar", 10);
}