A flexible dependency injection container based on the modification of `illuminate/container`. - 一个灵活的基于 `illuminate/container` 修改的依赖注入容器。

Fund package maintenance!
Wechat

v1.0.2 2020-11-16 07:09 UTC

This package is auto-updated.

Last update: 2024-12-16 16:04:56 UTC


README

A flexible dependency injection container based on the modification of illuminate/container. - 一个灵活的基于 illuminate/container 修改的依赖注入容器。

Tests Check & fix styling codecov Latest Stable Version Total Downloads License

Requirement

  • PHP >= 5.6

Installation

$ composer require guanguans/di -vvv

Usage

<?php

require __DIR__.'/vendor/autoload.php';

class ConcreteStub{}

$container = new \Guanguans\Di\Container();

// Simple Bindings
$container->bind(ConcreteStub::class, function ($container) {
    return new ConcreteStub();
});

// Binding A Singleton
$container->singleton('ConcreteStub', function ($container) {
    return new ConcreteStub();
});

// Binding Interfaces To Implementations
$container->bind(
    'App\Contracts\EventPusher',
    'App\Services\RedisEventPusher'
);

// Resolving
$concreteStub = $container->make(ConcreteStub::class);

Testing

$ composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.