PHP code example of alizharb / hookx

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

    

alizharb / hookx example snippets


use AlizHarb\Hookx\Attributes\Hook;
use AlizHarb\Hookx\Context\HookContext;

class UserListener
{
    #[Hook('user.registered')]
    public function onRegister(HookContext $context): void
    {
        echo "User registered: " . $context->getArgument('email');
    }
}

// Register
$manager->registerObject(new UserListener());

// Dispatch
$manager->dispatch('user.registered', [
    'user' => ['name' => 'Alice', 'email' => '[email protected]']
]);

use AlizHarb\Hookx\Async\AsyncHookDispatcher;

$dispatcher = new AsyncHookDispatcher($manager);

// Dispatches in background using Fibers
$dispatcher->dispatchAsync('email.send', [
    'to' => '[email protected]',
    'subject' => 'Welcome!'
]);