tkaratug / titan-container
Simple and lightweight dependency injection container
v1.0.2
2019-05-26 15:40 UTC
Requires
- php: >=7.0.0
This package is auto-updated.
Last update: 2024-10-29 05:40:16 UTC
README
Titan-Container is a small Dependency Injection Container for PHP.
Installation
Via composer
$ composer require tkaratug/titan-container
Usage
use Titan\Container; // Create a container instance $container = new Container(); // Without alias $container->bind(Example\Foo\Bar::class); $bar = $container->resolve(Example\Foo\Bar::class); // With alias #Example-1 $container->bind(Example\Foo\Bar::class); $container->alias('bar', Example\Foo\Bar::class); $bar = $container->resolve('bar'); // With alias #Example-2 $container->bind(Example\Foo\Bar::class)->alis('bar'); $container->resolve('bar'); // Singleton without alias $container->singleton(Example\Foo\Bar::class); // Singleton with alias $container->singleton(Example\Foo\Bar::class)->alias('bar'); // Store data $container->store('key', 'data'); $data = $container->get('key');
License
The MIT License (MIT). Please see License File for more information.