PHP code example of lkt / hooks

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

    

lkt / hooks example snippets


use Lkt\Hooks\Hook;

Hook::register('hook-name', 'hook-action', [callable])

use Lkt\Hooks\Hook;

Hook::register('create-user', 'mail-set-up-password', [callable])
Hook::register('create-user', 'mail-admin-new-user-created', [callable])

class HookStack {

    public static function mailPassword(int $userId, string $name, string $lastname): bool
    {
        // ... your stuff
        return true;
    }

    // If we want to define another method with different code,
    // the method must have the same arguments and return type.
    // This is a valid method:
    public static function mailPassword2(int $userId, string $name, string $lastname): bool
    {
        // ... another stuff
        return true;
    }

    // This is an invalid method:
    public static function mailPassword3(int $userId, string $name): bool
    {
        // ... third stuff
        return true;
    }
}
use Lkt\Hooks\Hook;

Hook::register('create-user', 'mail-set-up-password', [HookStack::class, 'mailPassword'])
Hook::register('create-user', 'mail-set-up-password', [HookStack::class, 'mailPassword2'])
Hook::register('create-user', 'mail-set-up-password', [HookStack::class, 'mailPassword3'])

use Lkt\Hooks\Hook;

Hook::run('hook-name', ...$args)

use Lkt\Hooks\Hook;

$id = 1;
$name = 'John';
$lastname = 'Doe';

$response = Hook::register('create-user', $id, $name, $lastname);