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

Debugging & Complex Use Cases

Version 2

This is documentation for the legacy version (2.x) of zend-di.

Debugging a DiC

It is possible to dump the information contained within both the Definition and InstanceManager for a Zend\Di\Di instance.

The easiest way is to do the following:

Zend\Di\Display\Console::export($di);

If you are using a RuntimeDefinition where upon you expect a particular definition to be resolve at the first-call, you can see that information to the console display to force it to read that class:

Zend\Di\Display\Console::export($di, ['A\ClassIWantTo\GetTheDefinitionFor']);

Complex Use Cases

Interface Injection

namespace Foo\Bar
{
    class Baz implements BamAwareInterface
    {
        public $bam;

        public function setBam(Bam $bam)
        {
            $this->bam = $bam;
        }
    }

    class Bam
    {
    }

    interface BamAwareInterface
    {
        public function setBam(Bam $bam);
    }
}

namespace {
    include 'zf2bootstrap.php';
    $di = new Zend\Di\Di;
    $baz = $di->get('Foo\Bar\Baz');
}

Setter Injection with Class Definition

namespace Foo\Bar
{
    class Baz
    {
        public $bam;

        public function setBam(Bam $bam)
        {
            $this->bam = $bam;
        }
    }

    class Bam {
    }
}

namespace {
    $di = new Zend\Di\Di;
    $di->configure(new Zend\Di\Config([
        'definition' => [
            'class' => [
                'Foo\Bar\Baz' => [
                    'setBam' => ['required' => true],
                ],
            ],
        ],
    ]));
    $baz = $di->get('Foo\Bar\Baz');
}

Multiple Injections To A Single Injection Point

namespace Application
{
    class Page
    {
        public $blocks;

        public function addBlock(Block $block)
        {
            $this->blocks[] = $block;
        }
    }

    interface Block
    {
    }
}

namespace MyModule {
    class BlockOne implements \Application\Block {}
    class BlockTwo implements \Application\Block {}
}

namespace {
    include 'zf2bootstrap.php';
    $di = new Zend\Di\Di;
    $di->configure(new Zend\Di\Config([
        'definition' => [
            'class' => [
                'Application\Page' => [
                    'addBlock' => [
                        'block' => [
                            'type' => 'Application\Block',
                            'required' => true,
                        ],
                    ],
                ],
            ],
        ],
        'instance' => [
            'Application\Page' => [
                'injections' => [
                    'MyModule\BlockOne',
                    'MyModule\BlockTwo',
                ],
            ],
        ],
    ]));
    $page = $di->get('Application\Page');
}
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
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
uri-template/tests