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

Zend Di Laravel Package

zendframework/zend-di

zendframework/zend-di is a PHP dependency injection container for Zend Framework apps. It supports autowiring, configurable definitions, and factories to build and wire objects at runtime, helping manage dependencies and improve testability.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Note: This package is archived and unmaintained since 2019; consider modern alternatives like php-di/php-di or Symfony's Dependency Injection Container.
  • If using legacyZF2/ZF3 codebase, install via Composer: composer require zendframework/zend-di.
  • Start with basic instantiation:
    $di = new Zend\Di\Di();
    $service = $di->get('Some\Dependency\Class');
    
  • Review the Di class constructor — it supports configuration via array, allowing definitions, shared instances, and prefilters.

Implementation Patterns

  • Automatic Injection: Use constructor injection — Di scans type hints and resolves dependencies automatically:
    class Service {
        public function __construct(RepositoryInterface $repo) { /* ... */ }
    }
    // $di->get(Service::class);
    
  • Lazy Initialization: Wrap dependencies in closures or use Zend\Di\Definition\RuntimeDefinition for runtime-based conditional wiring.
  • Programmatic Configuration: Define aliasing and constructor parameters via DefinitionSource:
    $defs = new Zend\Di\Definition\DefinitionDecorator($config['di']);
    $di = new Zend\Di\Di($defs);
    
  • Integrate with ZF2/ZF3 MVC: Use Zend\Di\DiServiceManager to bridge Di with Zend\ServiceManager, enabling DI-driven service resolution in controllers and modules.

Gotchas and Tips

  • No AOT Compilation: Unlike modern DI containers, Di resolves dependencies at runtime — avoid production use without caching (DefinitionList + CompiledDefinitions).
  • Circular Dependencies: Di does not detect or handle circular references gracefully — throws Exception\InfiniteRecursionException; design dependencies carefully.
  • Performance Overhead: Repeated get() calls without caching cause repeated reflection scanning — cache definitions using DefinitionCompiler for production.
  • Limited PSR-11 Support: This package predates PSR-11 — does not implement ContainerInterface; cannot be used interchangeably with modern containers.
  • Migrate Path: If modernizing, extract service definitions into config arrays (PSR-11-compatible format), then swap Zend\Di for php-di/php-di with minimal config changes.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4