alizharb/hookx

A next-generation, high-performance PHP 8.3+ hook and event system with async support.

Fund package maintenance!
alizharb

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/alizharb/hookx

v1.1.0 2025-11-29 12:52 UTC

This package is auto-updated.

Last update: 2025-11-29 12:54:24 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads License

HookX is a next-generation, high-performance PHP hook and event system designed for modern applications. Built on PHP 8.3+, it leverages Attributes, Fibers, and Strong Typing to deliver a developer experience that is both powerful and elegant.

โœจ Features

  • Zero-Dependency: Pure PHP implementation, no external bloat.
  • Async & Background Hooks: Run hooks in Fibers or push them to a Queue (Redis/Sync) using #[Async] and #[Background] attributes.
  • Framework Integrations: Native support for Laravel and Symfony.
  • Developer Experience: CLI tool (bin/hookx), REPL, and global helpers (hook(), filter()).
  • Advanced Matching: Wildcards (user.*) and Regex (#^order\.(created|updated)$#) support.
  • Safety: Immutable context, strict mode, and sandbox execution with time/memory limits.
  • Performance: JIT compilation (experimental) and Zero-Copy dispatching.

๐Ÿ“‹ Requirements

  • PHP 8.3 or higher

๐Ÿ“ฆ Installation

Install the package via Composer:

composer require alizharb/hookx

Documentation

Quick Start

Installation

composer require alizharb/hookx

Basic Usage

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' => 'alice@example.com']
]);

โšก Async & Background Hooks

HookX supports both concurrent execution (Fibers) and true background processing (Queues).

use AlizHarb\Hookx\Async\AsyncHookDispatcher;

$dispatcher = new AsyncHookDispatcher($manager);

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

For true background processing via Redis, check the Async Documentation.

๐Ÿ“š Documentation

For comprehensive documentation, check the docs/ directory:

๐Ÿงช Testing

Run the test suite:

composer test

๐Ÿ“„ License

The MIT License (MIT). Please see License File for more information.

Made with โค๏ธ by Ali Harb