-
-
Notifications
You must be signed in to change notification settings - Fork 45
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.
}
}
Modules do not have any required functions, but they can optionally implement several utility functions.
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.
This function is called when the module is enabled. Use this for setting up configuration settings, creating database tables, adding group permissions, etc.
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.
The Modules class provides a few functions intended to be used in __construct()
or __init()
:
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 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);
}
This is the wiki for Chyrp Lite: An ultra-lightweight blogging engine, written in PHP.
- About Permissions
- Tour of a Theme
- Twig Reference
- Twig Variables
- Object Attributes
- Routes and Controllers
- Making Your First Module
- Debug and Tester Modes
- About Errors
- Introduction to Helpers
- Introduction to Translations
- Introduction to Triggers
- Anatomy of info.php Files
- Anatomy of a Feather
- Anatomy of a Module
- Anatomy of a Theme
- Anatomy of a Post
- Localizing Extensions
- Adding Ajax Functionality
- Working with JavaScript
- Working with Model
- Working with Config