PHP code example of bit3 / contao-dependency-container

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

    

bit3 / contao-dependency-container example snippets


$container['myservice.param'] = 'value';
$container['myservice'] = function($container) {
	return new MyServiceClassName();
}

class MyClass
{
	function myFunction()
	{
		global $container;

		$parameter = $container['myservice.param'];
		$service = $container['myservice'];
	}
}

/** @var \Config $config */
$config = $container['config'];

/** @var \Environment $environment */
$environment = $container['environment'];

/** @var \Database $database */
$database = $container['database.connection'];

/** @var \Input $input */
$input = $container['input'];

/** @var \BackendUser|\FrontendUser $user */
$user = $container['user'];

/** @var \Session $session */
$session = $container['session'];

/** @var DependencyInjection\Container\PageProvider */
$pageProvider = $container['page-provider'];
$page         = $pageProvider->getPage();