PHP code example of magdicom / laravel-hooks

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

    

magdicom / laravel-hooks example snippets


use Magdicom\LaravelHooks\Facade\Hooks;

Hooks::register("HookName", function($vars){}, 1);

hooks()->register("HookName", function($vars){}, 1);

# Register our functions
Hooks::register("Greetings", function($vars){
    return "Hi There,";
}, 1);

Hooks::register("Greetings", function($vars){
    return "This is the second line of greetings!";
}, 2);

# Later we run it
echo Hooks::all("Greetings")->toString("<br>");

Hooks::register("Callback", function($vars) {
    return "Closure";
});

function simple_function_name($vars){
    //
}

Hooks::register("Callback", "simple_function_name");

class FooBar {
    public function methodName($vars){
        //
    }
}

$object = new FooBar;

Hooks::register("Callback", [$object, 'methodName']);

Hooks::register("Callback", [(new FooBar), 'methodName']);

class FooBar {
    public static function staticMethodName($vars){
        //
    }
}

Hooks::register("Callback", ['FooBar', 'staticMethodName']);

Hooks::register(string $hookName, array|callable $callback, ?int $priority): self

Hooks::all(string $hookName, ?array $parameters): self

Hooks::first(string $hookName, ?array $parameters): self

Hooks::last(string $hookName, ?array $parameters): self

Hooks::toArray(): array

Hooks::toString(?string $separator): string

Hooks::setParameter(string $name, mixed $value): self

Hooks::setParameters(array $parameters): self