Dependency injection container and autowiring for Switon Framework.
composer require switon/diRequirements: PHP 8.3+, ext-json
use Switon\Core\Attribute\Autowired;
use Switon\Di\Container;
use Switon\Di\ServiceProvider;
interface CacheInterface {}
class Cache implements CacheInterface {}
class ProductService
{
#[Autowired] protected CacheInterface $cache;
}
$container = new Container();
(new ServiceProvider())->register($container);
$productService = $container->get(ProductService::class);Docs: https://docs.switon.dev/latest/di
MIT.