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

Usage with PSR-11 containers

zend-di is designed to utilize and work with any IoC container thet implements the PSR-11 Psr\Container\ContainerInterface. To achieve this you can pass any container instance as the second parameter to the injector:

use Zend\Di\Injector;

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

From that point forwards, the injector will use the provided $container to obtain the dependencies.

Decorating the container

In the example above, the provided container may not utilize the injector to create unknown instances, even when the classes are known to zend-di. It may fail with an exception that dependencies could not be resolved.

If you want to pair the container with the injector and use the injector for dependencies the container it is not aware of, you may decorate the original container into a zend-di-aware implementation. As an example:

namespace MyApp;

use Zend\Di\Injector;
use Psr\Container\ContainerInterface;

class MyContainer implements ContainerInterface
{
    private $container;

    private $injector;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $wrappedContainer;
        $this->injector = new Injector(null, $this);
    }

    public function has($name)
    {
        retrun $this->container->has($name) || $this->injector->canCreate($name);
    }

    public function get($name)
    {
        if ($this->container->has($name)) {
            return $this->container->get($name);
        }

        $service = $this->injector->create($name);

        // You might make the service shared via the decorated container
        // as well:
        // $this->container->set($name, $service);

        return $service;
    }
}
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