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

Contract Laravel Package

hyperf/contract

Core contracts for Hyperf: a set of lightweight PHP interfaces that define common behaviors across the framework (DI, events, middleware, serialization, etc.). Helps decouple components, improve testability, and keep implementations swappable.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Misalignment with Laravel’s Ecosystem: This package is Hyperf-specific and introduces foreign architectural patterns (e.g., coroutines, RPC) into a Laravel-based system. Laravel already provides robust contracts (Illuminate\Contracts) for caching, queues, auth, etc., making this package redundant unless there’s a strategic need for Hyperf integration.
  • Decoupling Potential: If the goal is modularity (e.g., microservices, plugins), Hyperf’s contracts could complement Laravel’s by offering alternative abstractions for cross-framework communication. However, this requires dual-contract support, increasing complexity.
  • Hyperf Migration Path: Ideal if the long-term roadmap includes Hyperf adoption. The contracts serve as a pre-migration abstraction layer, reducing refactoring effort later.

Integration Feasibility

  • High Risk for Pure Laravel: Introducing Hyperf contracts without Hyperf adds unnecessary abstraction, complicates DI, and may conflict with Laravel’s built-in contracts (e.g., CacheInterface vs. Hyperf\Contract\CacheInterface).
  • Feasible for Hybrid Architectures: If Laravel and Hyperf coexist (e.g., Laravel frontend + Hyperf microservices), this package enables shared interfaces for service-to-service communication. Requires:
    • Adapter layer to bridge Laravel’s container and Hyperf’s contracts.
    • Protocol standardization (e.g., gRPC, HTTP JSON) for cross-framework calls.
  • Dependency Isolation: Since the package is interfaces-only, it avoids runtime dependencies, but concrete implementations (e.g., Hyperf’s RedisCache) would still need to be managed.

Technical Risk

  • DI Container Conflicts: Laravel’s Illuminate\Container and Hyperf’s Hyperf\Di are incompatible. Resolving Hyperf\Contract\CacheInterface in Laravel would require:
    • A custom container adapter or facade pattern.
    • Potential performance overhead from reflection-based resolution.
  • Testing Complexity: Mocking Hyperf contracts in Laravel’s testing environment (e.g., Mockery) may require custom test doubles or interface shims.
  • Breaking Changes: Hyperf’s contracts evolve independently of Laravel’s. Version pinning and backward-compatibility checks are critical to avoid runtime failures.
  • Tooling Gaps: IDE support (e.g., PHPStorm) and static analysis tools may misinterpret Hyperf contracts without configuration.

Key Questions

  1. Strategic Alignment
    • Is this package being considered for Hyperf migration, or is there a specific modularity need (e.g., plugin architecture) where Hyperf’s contracts provide unique value?
  2. Contract Overlap
    • Do Hyperf’s contracts duplicate Laravel’s existing interfaces (e.g., CacheInterface, QueueWorkerInterface)? If so, which should be the single source of truth?
  3. Implementation Strategy
    • Will we wrap Hyperf contracts in Laravel-compatible facades, or extend Laravel’s contracts to match Hyperf’s? Or use both in parallel?
  4. Performance Trade-offs
    • Are there critical paths (e.g., high-throughput APIs) where Hyperf’s contracts could introduce unnecessary indirection?
  5. Long-Term Maintenance
    • Who will sync updates between Hyperf’s contracts and Laravel’s implementations? Will this create dual-maintenance burden?
  6. Team Readiness
    • Does the team have experience with Hyperf’s design patterns (e.g., coroutines, RPC)? If not, what’s the training/ramp-up plan?

Integration Approach

Stack Fit

  • Best Fit:
    • Hybrid Laravel/Hyperf architectures (e.g., Laravel frontend + Hyperf microservices) where contracts define cross-framework service boundaries.
    • Projects planning a gradual Hyperf migration, using contracts as a pre-migration abstraction layer.
  • Partial Fit:
    • Modular Laravel monoliths where contracts are used to define plugin boundaries (e.g., auth providers, payment gateways) with Hyperf-compatible implementations.
  • Poor Fit:
    • Vanilla Laravel applications without Hyperf integration, as it adds unnecessary complexity and redundant abstractions.
    • Teams lacking Hyperf expertise, as it introduces foreign architectural patterns.

Migration Path

  1. Assessment & Gap Analysis

    • Audit existing Laravel contracts (Illuminate\Contracts) and identify gaps where Hyperf’s contracts could add value.
    • Map Hyperf contracts to Laravel’s 1:1 where possible; document mismatches requiring adapters.
    • Example: Hyperf\Contract\CacheInterface vs. Illuminate\Contracts\Cache\Store.
  2. Pilot Integration (Low-Risk Module)

    • Choose a non-critical module (e.g., logging, analytics) to test contract adoption.
    • Implement dual-contract support (e.g., a class implements both Hyperf\Contract\CacheInterface and Illuminate\Contracts\Cache\Store).
    • Use feature flags to toggle between old and new implementations.
  3. Adapter Layer Development

    • Create Laravel-compatible facades/wrappers for Hyperf contracts to resolve DI conflicts.
    • Example:
      class HyperfCache implements Illuminate\Contracts\Cache\Store {
          protected $hyperfCache;
          public function __construct(Hyperf\Contract\CacheInterface $cache) {
              $this->hyperfCache = $cache;
          }
          public function get($key) { return $this->hyperfCache->get($key); }
          // ... delegate other methods
      }
      
    • Register adapters in Laravel’s service provider:
      $this->app->bind(
          Illuminate\Contracts\Cache\Store::class,
          HyperfCache::class
      );
      
  4. Full Adoption (Phased Rollout)

    • Gradually replace Laravel-specific implementations with Hyperf-compatible ones where beneficial.
    • Prioritize high-impact modules (e.g., auth, payment processing) first.
    • Use dependency injection bindings to enforce contract usage:
      $this->app->bind(
          Hyperf\Contract\AuthInterface::class,
          App\Services\HyperfAuthService::class
      );
      
  5. Testing & Validation

    • Implement contract-specific test suites to catch breaking changes.
    • Verify mocking compatibility in unit tests (e.g., Mockery support for Hyperf contracts).
    • Load-test performance impact of adapter layers in critical paths.
  6. Documentation & Training

    • Update architecture docs with contract usage guidelines.
    • Create Laravel-specific examples for Hyperf contracts (e.g., "How to implement OnRequest in Laravel").
    • Train teams on Hyperf’s design patterns (e.g., coroutines, RPC) if adopting for cross-framework communication.

Compatibility

  • Dependency Conflicts:
    • Hyperf’s contracts may pull in PSR-15 (HTTP), PSR-16 (Cache), or ReactPHP dependencies, which could conflict with Laravel’s versions. Use composer version constraints to resolve:
      "require": {
          "psr/cache": "^1.0 || ^2.0",
          "react/event-loop": "^1.0"
      }
      
  • DI Container Bridge:
    • Laravel’s container cannot natively resolve Hyperf contracts. Solutions:
      1. Facade Pattern: Wrap Hyperf implementations in Laravel-compatible classes (as shown above).
      2. Custom Container Adapter: Extend Laravel’s container to delegate Hyperf contract resolution.
      3. Hybrid Container: Use Hyperf’s container only for Hyperf-specific modules (advanced, requires careful isolation).
  • Event System:
    • Hyperf’s event system (Hyperf\Event) differs from Laravel’s (Illuminate\Events). If using event contracts:
      • Implement cross-framework event dispatching via adapters.
      • Example: Dispatch a Laravel event from a Hyperf contract using a shared event bus (e.g., Redis, RabbitMQ).

Sequencing

Phase Task Dependencies Risks
1 Contract Mapping Audit existing Laravel contracts. Misalignment with Hyperf’s contracts.
2 Adapter Design Define facades/wrappers for critical contracts. DI resolution failures.
3 Pilot Module Integrate in a low-risk module (e.g., logging). Limited visibility into broader impact.
4 DI Integration Configure Laravel’s container to resolve Hyperf contracts. Container conflicts, performance overhead.
5 Testing Verify mocking, dependency injection, and runtime behavior. Testing gaps, edge cases.
6 Documentation Update architecture docs and
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.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
headercat/phpstan-extension-ide-helper
yosymfony/parser-utils
innmind/black-box
babenkoivan/elastic-migrations
babenkoivan/elastic-adapter
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle