PHP code example of renshan / tc

1. Go to this page and download the library: Download renshan/tc 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/ */

    

renshan / tc example snippets


namespace Foo;

class Foo 
{
	public function foo()
	{
		// Do anything here
	}
}

use Tc\Container;


$container = new Container;

$defKey = 'service.foo';
$defMap = 'Foo\Foo';

$container->register($defKey, $defMap);




namespace Bar;

use Foo\Foo;

class Bar
{
	/**
		* This class need a parameter whic a instance of Foo, and a parameter $bar
		*/
	public function constructor(Foo $foo, $bar)
	{
	}

	public function bar()
	{
		// Do anything here
	}
}




$container = new Container;

$defKey = 'service.bar';
$defMap = 'Bar\Bar';
$params = ['@service.foo', 'bar']; // Be sure the position of parameters

$container->register($defKey, $defMap, $params);




$foo = $container->get('service.foo');
$bar = $container->get('service.bar');



$contnainer->raw('service.foo');