PHP code example of tkaratug / titan-container
1. Go to this page and download the library: Download tkaratug/titan-container 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/ */
tkaratug / titan-container example snippets
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');