illuminate/macroable but tailored for Hyperf’s coroutine-based, process-driven architecture. Ideal for teams leveraging Hyperf’s high concurrency and microservices capabilities while retaining Laravel-like developer familiarity.Order::macro('calculateTax', ...)).Model::where()->macro('byStatus', ...)).Task::macro('retryWithBackoff', ...)).Container must align with Hyperf’s singleton vs. context binding model.Macroable::macro()).Hyperf\AsyncQueue\Context.v3.1.x for production; validate against Hyperf’s container rebinding behavior.Macroable::macro() event triggers.BootServiceProvider vs. Laravel’s RegisterMacros hooks differ.hyperf/aop or decorators achieve similar goals with less overhead?go(fn() => $macro())).Str::macro() → custom StringHelper).macroable and Hyperf’s version in the same codebase.Container implements this).Collection, Request, and Response classes.Container bindings for macros.Order::macro('applyDiscount', ...)).Str::macro()).| Feature | Laravel macroable |
Hyperf macroable |
Notes |
|---|---|---|---|
| Class Macros | ✅ (Class::macro()) |
✅ | Identical syntax. |
| Static Macros | ✅ (StaticClass::macro()) |
✅ | Works via static::macro(). |
| Container Macros | ✅ (app()->bind()) |
⚠️ (Container::bind()) |
Hyperf’s DI container API differs. |
| Macro Events | ✅ (Macroable::macro() event) |
❌ | Hyperf lacks Laravel’s event system. |
| Macro Removal | ✅ (forgetMacro()) |
✅ | Same API. |
| Middleware Macros | ❌ | ✅ | Hyperf’s PSR-15 pipeline supports it. |
| Coroutine Support | ❌ | ✅ | Async macro execution via go(). |
hyperf/macroable:^3.1.MacroableServiceProvider in config/autoload/services.php.App\Helpers\StringHelper) with the Macroable trait.Str::macro() with Hyperf’s StringHelper::macro().user()->macroCall()).go()).data_get; ~5–10ms overhead per call (negligible for most use cases).How can I help you explore Laravel packages today?