This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
JBZoo Event is a lightweight PHP library for event-based development, providing an EventManager with support for event listeners, priorities, namespaces, and wildcard matching.
The library consists of three main components in the src/ directory:
The core event manager class providing:
- Event subscription with priority levels (LOWEST=0, LOW=50, MID=100, HIGH=500, HIGHEST=1000)
- Namespace-based event matching with wildcards (e.g.,
item.*,*.save) - One-time event listeners with
once() - Event propagation control via
ExceptionStop - Static default manager instance
Exception.php- Base exception for the libraryExceptionStop.php- Special exception to halt event propagation
make update # Install/update dependencies via Composermake test # Run PHPUnit tests
make test-all # Run all tests and code style checks
make codestyle # Run linters (PHPStan, Psalm, PHP-CS-Fixer, etc.)make test-phpstan # Static analysis
make test-psalm # Psalm analysis
make test-phpcs # Code style check
make test-phpcsfixer-fix # Auto-fix code style
make test-phpmd # Mess detectormake report-all # Generate coverage and analysis reports
make report-coveralls # Upload coverage to CoverallsEvents are registered using dot notation with support for:
- Simple events:
user.create - Namespaced events:
user.profile.update - Wildcard matching:
user.*,*.save,*.*
Listeners execute in priority order (highest to lowest):
- Multiple listeners at same priority execute in deterministic but undefined order
- Default priority is
EventManager::MID(100)
- Listeners can throw
ExceptionStopto halt further event processing trigger()returns count of successfully executed listeners- Continue callbacks can control execution flow
Tests are located in tests/ directory:
EventTest.php- Core functionality testsEventNamespacesTest.php- Wildcard and namespace matchingEventPackageTest.php- Package-level integration testsphpbench/- Performance benchmarks
- PHP 8.2+ required
- Strict types declaration (
declare(strict_types=1)) - PSR-12 coding standard
- Full test coverage expected for new features
- Static analysis with PHPStan level max and Psalm
When working with the EventManager:
- Use descriptive namespaced event names (
entity.action.phase) - Consider priority when order matters
- Use
once()for initialization events - Throw
ExceptionStopto halt propagation when needed - Pass data via reference in arguments for listener communication