PHP code example of bayfrontmedia / php-hooks

1. Go to this page and download the library: Download bayfrontmedia/php-hooks 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/ */

    

bayfrontmedia / php-hooks example snippets


composer 

$hooks->addEvent('name', function($name) {

    echo 'My name is ' . $name;

});

use Bayfront\Hooks\Hooks;

class MyClass {

    protected $hooks;

    public function __construct(Hooks $hooks) {

        $this->hooks = $hooks;

        $this->hooks->addEvent('name', [$this, 'my_name']);

    }

    public function my_name($name) {

        echo 'My name is ' . $name;

    }
}

$my_class = new MyClass($hooks);

$prefix = 'My name is ';

$hooks->addEvent('name', function($name) use ($prefix) {

    echo $prefix . $name;

});

$hooks->addFilter('name', function($name) {

    return strtoupper($name);

});

function uppercase($name) {

    return strtoupper($name);

}

$hooks->addFilter('name', 'uppercase');

use Bayfront\Hooks\Hooks;

class MyClass {

    protected $hooks;

    public function __construct(Hooks $hooks) {

        $this->hooks = $hooks;

        $this->hooks->addFilter('name', [$this, 'uppercase']);

    }

    public function uppercase($name) {

        return strtoupper($name);

    }
}

$my_class = new MyClass($hooks);

echo $hooks->doFilter('name', 'John');