PHP code example of pentagonal / hookable

1. Go to this page and download the library: Download pentagonal/hookable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pentagonal / hookable example snippets


$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());