This package is abandoned and no longer maintained. No replacement package was suggested.

Simple PHP DIC Container

1.4.0 2019-12-26 00:59 UTC

This package is auto-updated.

Last update: 2020-09-26 22:28:56 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock

About

Simple PSR-11 compliant dependency injection container.

Around the the web there are many examples to be found for simple PHP DI Containers and Resolvers. From all the inspiration I have written a version to my own personal liking. Feel free to use it in your project or take it as inspiration for your own version.

For now only the object definition has been implemented but more will follow.

Getting started

    $ composer require jascha030/dic

Usage

Short example:

Class UserService with dependency User.

class UserService
{
    public $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function printUserName()
    {
        echo "My name is " . $this->user->name;
    }
}
$container = new PsrServiceContainer(); // Instantiate container

$userService = $container->get(UserService::class); // Get service or class instance.

$userService->printUserName(); // Outputs: My name is Jeff

Full example in src/example.php