hyperf/tappable package is a port of Laravel’s illuminate/tappable, which provides the macroable trait and tappable contract—core components for Laravel’s service container and macro system. If the existing Laravel codebase relies on macros (e.g., Str::macro(), Collection::macro()) or tappable services, this package could be a direct replacement in a Hyperf migration or a dual-stack integration (Laravel + Hyperf).app()->bind() or app()->extend().tappable features (e.g., custom string/collection macros), this package allows seamless porting to Hyperf.define() in config/autoload.php or middlewares/bindings in container.php. This package may duplicate functionality unless macros are explicitly needed.Macroable trait (for adding static methods at runtime).Tappable contract (for resolving services with custom logic).MacroableServiceProvider (for registering macros).Container class (extends Illuminate\Container\Container in some Hyperf versions).autoload configuration (e.g., autoloads/macros.php).define() in config/autoload.php for bindings. The package may require a custom service provider to register macros.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Container Incompatibility | High | Verify Hyperf’s Container class extends Illuminate\Container\Container or patch if needed. |
| Macro Leakage | Medium | Ensure macros don’t pollute global namespace (e.g., scope macros to specific classes). |
| Performance Regression | Medium | Benchmark macro-heavy operations in Hyperf’s coroutine vs. swoole contexts. |
| Dependency Bloat | Low | Only adopt if macros are critical; otherwise, use Hyperf’s native DI. |
| Long-Term Maintenance | Low | MIT license is permissive; monitor Hyperf’s native macro support (if added). |
Why Macros?
Str::macro(), Collection::macro(), or custom tappable services?Order::calculateTax())?Hyperf-Specific Constraints
ProcessManager) or RPC services?illuminate/tappable be polyfilled?Alternatives
define(), bind()) replace macros?hyperf/extender) that achieves the same goal?Testing Strategy
Future-Proofing
illuminate/tappable in favor of native solutions?Hyperf Core Compatibility:
Container extends Illuminate\Container\Container (common in older versions). For newer Hyperf (PHP-DI), a shim layer may be needed.define() in config/autoload.php. Macros should be registered in a custom ServiceProvider (extending Hyperf\Di\Container).Swoole\Coroutine).Laravel Interop:
if (app()->runningInHyperf())).Tooling Integration:
Assessment Phase:
Str::macro(), Collection::macro()).AppServiceProvider).Proof of Concept (PoC):
hyperf/tappable.Incremental Rollout:
hyperf/tappable in non-critical modules.app()->bind() logic).Str::macro()) to scoped macros (e.g., App\Extensions\StrMacros).Fallback Plan:
define(), bind()) or a custom macro system built on PHP’s spl_object_hash().| Component | Compatibility Notes |
|---|---|
| Hyperf Container | Works if using illuminate/container; otherwise, requires shim. |
| Service Providers | Must extend Hyperf\Di\Container or use Hyperf\Di\DefinitionConfigurable. |
| Macroable Classes | Any class using Macroable trait will work, but Hyperf’s PSR-11 may need adjustment. |
| Coroutines | Macros must be stateless or use coroutine-local storage to avoid leaks. |
| Testing Frameworks | May require custom test doubles for macro-heavy classes. |
Prerequisites:
illuminate/container (or implement a shim).Core Integration:
hyperf/tappable via Composer.MacroServiceProvider to register macros:
namespace App\Providers;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Contract\ContainerInterface;
use Hyperf\Framework\ServiceProvider;
use Hyperf\Tappable\Macroable;
class MacroServiceProvider extends ServiceProvider
{
public function register()
{
if (method_exists(Macroable::class, 'macroable')) {
Macroable::macroable($this->
How can I help you explore Laravel packages today?