pentagonal/hookable

Hook able Library like a WordPress uses

1.0 2016-11-27 17:22 UTC

This package is not auto-updated.

Last update: 2024-04-24 23:08:12 UTC


README

Hook able Library like a WordPress uses

Build Status Latest Stable Version License Total Downloads

Usage

$hook = new \Pentagonal\Hookable\Hookable();

/**
 * Add Hook into functions example
 */
function thIsIsOnHookReturn()
{
    global $hooks;
    /**
     * .... run the code
     */
    $the_result = array('array_result'); // the returning result
    return $hook->apply('callback_name', $the_result);
}

/**
 * in here
 * Calling thIsIsOnHookReturn()
 * will be returning array
 */
var_dump(thIsIsOnHookReturn());

/**
 * add filter / action on determined callback
 */
$hook->add(
    'callback_name', // the callback
    function ($returning_old_result) {
        $new_result = print_r($returning_result, true);
        return $new_result;
    },
    10, // priority
    1 // arguments accepted
);

/**
 * in here
 * Calling thIsIsOnHookReturn()
 * will be returning string of array printed
 */
var_dump(thIsIsOnHookReturn());

Install

{
   "require": {
       "pentagonal/hookable": "^1"
   }
}