Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pimple Laravel Package

hyperf/pimple

hyperf/pimple 是基于 pimple/pimple 的轻量级 PSR-11 容器组件,提供简单的 ContainerFactory 创建容器与 Provider 注册机制,帮助在非 Hyperf 框架中低成本接入 Hyperf 组件(如 translation/config),便于集成与复用。

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Modular DI for Laravel: The package enables PSR-11-compliant dependency injection in Laravel, but its value is limited to integrating Hyperf-specific services (e.g., translation, config). Laravel’s native container (PHP-DI) already supports PSR-11, so this package is not a drop-in replacement but a niche solution for Hyperf interoperability.
  • Hyperf-Laravel Bridge: Acts as a translation layer to use Hyperf’s PSR-11 services (e.g., hyperf/translation) in Laravel without adopting Hyperf’s full framework. Useful for incremental modernization (e.g., adding Hyperf’s translation system to a Laravel app).
  • Provider Pattern Alignment: The ProviderInterface mirrors Laravel’s service providers, easing adoption for Laravel TPMs. However, Hyperf’s make() helper and ApplicationContext are Laravel-foreign, requiring adapters.
  • Lightweight Overhead: Pimple is ~50KB, making it suitable for microservices or background jobs where Hyperf services are needed without bloating the main Laravel container.

Integration Feasibility

  • Laravel Compatibility:
    • Medium: Requires custom binding to Laravel’s container (e.g., via a facade or container alias). Example:
      $container->bind('hyperf.translator', fn() => $pimpleContainer->get(TranslatorInterface::class));
      
    • Service Isolation: Best used for scoped services (e.g., Hyperf translation in a queue worker) rather than global Laravel bindings.
  • Hyperf Service Adoption:
    • High: Directly integrates hyperf/translation, hyperf/config, etc., reducing boilerplate for PSR-11 services.
    • Dependency Risk: Adds hyperf/pimple, hyperf/translation, and hyperf/config to composer.json, which may conflict with Laravel’s ecosystem (e.g., Laravel’s translation system).
  • Non-Laravel Use Cases:
    • High: Ideal for EasySwoole, Swoole, or standalone PHP where Hyperf services are needed without Laravel’s overhead.

Technical Risk

  • Container Collisions: Mixing Pimple with Laravel’s container risks binding conflicts or unpredictable resolution. Requires explicit delegation (e.g., prioritizing Laravel’s container for core services).
  • Hyperf-Specific Abstractions: Relies on Hyperf’s make() and ApplicationContext, which must be mocked or aliased in Laravel. Example:
    // Replace Hyperf's make() with Laravel's app()
    $container->set('make', fn($abstract) => app($abstract));
    
  • Testing Complexity: Mocking dependencies across two containers (Laravel + Pimple) complicates unit tests. May need container-aware test doubles.
  • Maintenance Burden: The package’s lightweight maintenance (last release 2023, 3 stars) introduces long-term risk. Hyperf’s components may evolve incompatibly.
  • Performance: Minimal overhead for Pimple itself, but Hyperf services (e.g., translation) may introduce unexpected latency in Laravel’s request pipeline.

Key Questions

  1. Use Case Clarity:
    • Is this for integrating Hyperf services into Laravel (e.g., translation, RPC), or for a non-Laravel project?
    • If Laravel, is the goal partial adoption (e.g., only translation) or full Hyperf migration?
  2. Container Strategy:
    • Will Pimple replace Laravel’s container for specific services, or coexist as a secondary container?
    • How will service resolution handle conflicts (e.g., duplicate bindings for ConfigInterface)?
  3. Dependency Management:
    • Will hyperf/translation and hyperf/config conflict with Laravel’s laravel/framework (e.g., duplicate translation files)?
    • How will autoloading handle namespace collisions (e.g., Hyperf\Translation vs. Illuminate\Translation)?
  4. Testing and Debugging:
    • How will dependency injection be mocked in PHPUnit if services are split across containers?
    • Are there tools (e.g., Laravel’s Mockery, Hyperf’s Mock) to simplify testing?
  5. Long-Term Viability:
    • What’s the exit strategy if Hyperf’s components diverge from PSR-11 or Laravel’s ecosystem?
    • Is the team prepared to maintain custom adapters (e.g., for make() or ApplicationContext)?
  6. Performance Impact:
    • Does the dual-container approach add measurable overhead in Laravel’s request lifecycle?
    • Are there benchmarks for Hyperf services (e.g., translation) in a Laravel context?

Integration Approach

Stack Fit

  • Primary Use Case:
    • Laravel + Hyperf Services: Integrate Hyperf’s PSR-11 services (e.g., translation, config) into specific Laravel components (e.g., API layers, queue workers, CLI tools) without adopting Hyperf’s full framework.
    • Example: Use Hyperf’s translation system in a Laravel queue job for multilingual email processing.
  • Secondary Use Case:
    • Non-Laravel PHP: Use Pimple as a standalone PSR-11 container for Hyperf services in EasySwoole, Swoole, or custom PHP apps.
  • Poor Fit:
    • Core Laravel Logic: Laravel’s native container (PHP-DI) is more mature and integrated.
    • Projects Without Hyperf Needs: Adds unnecessary complexity.

Migration Path

  1. Assessment:
    • Identify Hyperf services needed (e.g., translation, config, RPC).
    • Audit Laravel dependencies for conflicts (e.g., duplicate translation files).
  2. Container Strategy:
    • Option 1: Isolated Container (Recommended for Laravel):
      • Use Pimple only for Hyperf services, binding it to Laravel’s container via a facade.
      • Example:
        // app/Providers/HyperfServiceProvider.php
        use Hyperf\Pimple\ContainerFactory;
        use Hyperf\Contract\TranslatorInterface;
        
        class HyperfServiceProvider extends ServiceProvider
        {
            public function register()
            {
                $pimple = (new ContainerFactory([
                    \App\Providers\TranslatorProvider::class,
                )))();
        
                $this->app->singleton('hyperf.translator', fn() => $pimple->get(TranslatorInterface::class));
            }
        }
        
    • Option 2: Hybrid Container:
      • Extend Laravel’s container to delegate Hyperf-specific services to Pimple.
      • Riskier due to binding conflicts.
  3. Service Integration:
    • Register Hyperf providers (e.g., TranslatorProvider) in Pimple.
    • Bind Pimple services to Laravel’s container via facades or aliases.
  4. Testing:
    • Mock Pimple services in tests using Laravel’s Mockery or custom test doubles.
    • Example:
      $this->app->instance(TranslatorInterface::class, Mockery::mock(TranslatorInterface::class));
      
  5. Deployment:
    • Add hyperf/pimple, hyperf/translation, and hyperf/config to composer.json.
    • Configure autoloading to resolve Hyperf namespace collisions (e.g., psr-4 exclusions).

Compatibility

  • Laravel 8/9/10: Compatible, but requires custom binding logic for Pimple.
  • Hyperf 2.x: Assumes Hyperf’s PSR-11 services are stable (verify compatibility with target Hyperf version).
  • PSR-11: Fully compliant, but Laravel’s container is also PSR-11, so integration requires explicit delegation.
  • EasySwoole/Swoole: Native support (as shown in README), but not the focus for Laravel.

Sequencing

  1. Phase 1: Proof of Concept
    • Integrate one Hyperf service (e.g., translation) in a non-critical Laravel component (e.g., a queue job).
    • Validate performance, testing, and debugging workflows.
  2. Phase 2: Scoped Adoption
    • Expand to additional Hyperf services (e.g., config, RPC) in isolated Laravel modules.
  3. Phase 3: Full Integration
    • (Optional) Migrate core Laravel services to Pimple if justified (e.g., for performance or Hyperf-specific features).
  4. Phase 4: Maintenance
    • Monitor for Hyperf breaking changes and update adapters accordingly.

Operational Impact

Maintenance

  • Pros:
    • Decoupled Services: Hyperf services are isolated in Pimple, reducing risk to the main Laravel app.
    • Provider Pattern: Familiar to Laravel TPM
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky