ytake / starch
Dependency Injection Container For PHP
Fund package maintenance!
ytake
Requires
- php: ^8.0
- psr/container: ^1.0
Requires (Dev)
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9.5
Provides
README
Dependency Injection Container For PHP.
Not Supported Autowiring.
Requirements
PHP 8.0 and above.
Installation
Composer is the recommended installation method.
To add Ytake\Starch to your project,
add the following to your composer.json then re-run composer:
{ "require": { "ytake/starch": "^1.0" } }
Run Composer commands using PHP like so:
$ composer install
or
$ composer require ytake/starch
Usage
First steps
Create Class
interface AnyInterface
{
}
final class Any implements AnyInterface { // any }
Bindings
use Ytake\Starch\Container; use Ytake\Starch\Scope; $container = new Container(); $container->bind(AnyInterface::class) ->to(Any::class) ->in(Scope::PROTOTYPE);
dependencies will be automatically resolved
$container->get(AnyInterface::class);
Scopes
use the Ytake\Starch\Scope
class.
Providers
use Ytake\Starch\ProviderInterface.
use Ytake\Starch\ProviderInterface; final class AnyProvider implements ProviderInterface { public function get(): AnyInterface { return new Any(); } }
$container->bind(AnyInterface::class) ->provider(new AnyProvider();