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

Quick Start

The DI component provides an auto wiring strategy which implements constructor injection.

It utilizes PSR-11 containers to obtain required services, so it can be paired with any IoC container that implements this interface, such as zend-servicemanager.

1. Installation

If you haven't already, install Composer. Once you have, you can install zend-di:

$ composer require zendframework/zend-di

2. Configuring the injector

You can now create and configure an injector instance. The injector accepts an instance of Zend\Di\ConfigInterface. This can be provided by passing Zend\Di\Config, which accepts a PHP array to its constructor:

use Zend\Di\Injector;
use Zend\Di\Config;

$injector = new Injector(new Config([
    'preferences' => [
        MyInterface::class => MyImplementation::class,
    ],
]));

This config implementation accepts a veriety of options. Refer to the Configuration chapter for full details.

3. Creating instances

Finally, you can create new instances of a specific class or alias by using the create() method:

$instance = $injector->create(MyClass::class);

The only precondition is that the class you provide to create() must exist (or be autoloadable). If this is not the case, the injector will fail with an exception.

The create() method will always create a new instance of the given class. If you need a shared instance, you can associate an IoC container implementing PSR-11 with the injector:

$injector = new Injector($config, $container);

$sharedInstance = $injector->getContainer()->get(MyClass::class);

By default, the injector creates and uses an instance of Zend\Di\DefaultContainer if no container is provided to it. This implementation is quite limited, however, and we recommend you use a more featureful container with the injector, such as zend-servicemanager. Refer to the Usage with PSR-11 containers and Usage with zend-servicemanager chapters for details.

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
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
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation