1. Go to this page and download the library: Download flytachi/winter-di library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
flytachi / winter-di example snippets
use Flytachi\Winter\DI\Container;
use Flytachi\Winter\DI\Scanner;
use Flytachi\Winter\DI\Collector\DICollector;
// bootstrap.php — once at application start
$container = Container::init();
Scanner::run(__DIR__ . '/src', cache: __DIR__ . '/var/cache/di.php')
->collect(new DICollector($container)) // auto-register #[Singleton], #[Request], #[Transient]
->execute();
$container->register(AppServiceProvider::class); // bind interfaces and factories
// Resolve anywhere
$service = Container::getInstance()->make(UserService::class);
// Call a method with full injection
$result = Container::getInstance()->call([UserController::class, 'index']);
use Flytachi\Winter\DI\Attribute\Singleton;
use Flytachi\Winter\DI\Attribute\Transient;
use Flytachi\Winter\DI\Attribute\Request;
use Flytachi\Winter\DI\Attribute\Autowired;
use Flytachi\Winter\DI\Attribute\Inject;
// Scope on class
#[Singleton]
class UserRepository { }
#[Request]
class AuthContext { }
#[Transient]
class QueryBuilder { }
// Injection overrides on constructor parameters
class UserService
{
public function __construct(
private UserRepository $repo, // autowired by type (no attribute needed)
#[Inject(FileCache::class)]
private CacheInterface $fallback, // specific implementation
#[Inject('config.timeout')]
private int $timeout, // named value
) {}
}
// Property injection (when constructor is unavailable)
class SomeCommand
{
#[Autowired] // by declared type — idiomatic choice
private UserService $service;
#[Inject(FileCache::class)] // specific implementation override
private CacheInterface $cache;
}