dugajean/pouch

Tiny IoC Container with automatic resolution for your PHP project.

2.2.3 2019-06-07 08:12 UTC

This package is auto-updated.

Last update: 2024-03-20 17:12:51 UTC


README

Build Status Latest Stable Version Total Downloads License

Tiny IoC container with awesome autowiring & more - for your PHP project.

Requirements

Install

Via Composer

$ composer require dugajean/pouch

Usage

You may register your whole src/ folder with this package in order to enable automatic resolution everywhere within the namespace

<?php

use Pouch\Pouch;

Pouch::bootstrap(__DIR__);

// ...

pouch()->registerNamespaces('Foo'); // Foo corresponds to src/

You may now just typehint to the objects your method requires and it will be automatically resolved for you.

<?php

namespace Foo;

class Bar
{
    public function doSomething(Baz $baz)
    {
        $baz->doSomethingElse();
    }
}

class Baz
{
    public function doSomethingElse()
    {
        echo 'From Baz!';
    }
}

Constructor object arguments will also be automatically injected.

You can always manually bind data to the container using pouch()->bind($key, $dataClosure) and also resolve anything from the container using pouch()->get($key).

Read the wiki and the API docs for further information.

Testing

$ vendor/bin/phpunit

Changelog

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

License

Pouch is released under the MIT License.