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
Requires
- php: ^8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.90
- illuminate/support: ^12.40
- pestphp/pest: ^3.0
- phpstan/phpstan: ^2.1
- symfony/dependency-injection: ^7.0
- symfony/http-kernel: ^7.0
- symfony/var-dumper: ^7.0
README
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
- Basics: Core concepts, HookManager, and Priorities.
- Async & Queue: Background processing and Fibers.
- Advanced Usage: Wildcards, Regex, JIT, and Sandbox.
- CLI Tooling: Using the
hookxcommand-line tool. - Integrations:
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:
- Introduction
- Installation
- Basic Usage
- Advanced Usage
- CLI Tooling
- Async & Background Hooks
- Filters
- Framework Integrations
๐งช Testing
Run the test suite:
composer test
๐ License
The MIT License (MIT). Please see License File for more information.
Made with โค๏ธ by Ali Harb