Mecha CMS

Mecha CMS blog and documentation.

Class Weapon

Updated: Sunday, 07 August 2016

Function hooks.

Apply a Weapon

At certain place in your page, declare this function:

Weapon::fire('my_hook');

Add a Weapon

Then, in the other place (such as in functions.php), declare this function:

Weapon::add('my_hook', function() {
    echo 'Yo!';
}, 10);

Now, on the page where you put the Weapon::fire('my_hook') function should outputs a ‘Yo!’ text.

Add more weapon to my_hook like this:

Weapon::add('my_hook', function() {
    echo ' + another yo!';
}, 11);

10 is the function execution priority. The smaller the value, the earlier the function will be executed. And functions with the same priority are executed in the order in which they were added to the weapon. Default is 10.

Now, on the page where you put the Weapon::fire('my_hook') function should outputs ‘Yo! + another yo!’ text.

Check if Weapon Already Mounted

Added since version 1.0.3.

if(Weapon::exist('bazooka')) {
    echo 'OK.';
}

Eject a Weapon

Added since version 1.0.3.

Weapon::eject('bazooka');
Weapon::fire('bazooka');

The function that declared in the second line above will not be able to be executed because your bazooka already ejected.

Eject Weapon by Priority

Weapon::eject('my_hook', 4);

Eject Weapon by Function Name

Weapon::eject('my_hook', 'my_hook_fn');

Using Arguments

// Add
Weapon::add('gun', function($a, $b, $c) {
    echo $a . ' ' . $b . ' ' . $c;
});

// Fire
Weapon::fire('gun', array('Test 1', 'Test 2', 'Test 3'));
Donation and Email Subscription