Tiny IoC container with awesome autowiring & more - for your PHP project.
- PHP 7.1+
- PSR-4 standard with Composer
Via Composer
$ composer require dugajean/pouch
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.
$ vendor/bin/phpunit
Please see CHANGELOG for more information on what has changed recently.
Pouch is released under the MIT License.