bit3 / contao-dependency-container
Dependency container based on pimple for Contao open source cms.
Installs: 391
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 4
Type:contao-module
Requires
- php: >=5.3
- contao-community-alliance/backports-initialize-system: ~1.0
- contao-community-alliance/composer-plugin: ~2.0
- contao/core: >=2.11,<4-dev
- pimple/pimple: ~1.0
Requires (Dev)
Replaces
- bit3/contao-dependency-container: 1.7.0
- contao-legacy/dependency-container: 1.7.0
This package is not auto-updated.
Last update: 2022-02-01 12:24:58 UTC
README
This DI Container based on Pimple.
Register parameters and services
system/modules/X/config/services.php
$container['myservice.param'] = 'value'; $container['myservice'] = function($container) { return new MyServiceClassName(); }
Access parameters and services
class MyClass { function myFunction() { global $container; $parameter = $container['myservice.param']; $service = $container['myservice']; } }
Build-in services
The config object
/** @var \Config $config */ $config = $container['config'];
The environment object
/** @var \Environment $environment */ $environment = $container['environment'];
The database connection
/** @var \Database $database */ $database = $container['database.connection'];
The input object
/** @var \Input $input */ $input = $container['input'];
The backend or frontend user, depend on TL_MODE
/** @var \BackendUser|\FrontendUser $user */ $user = $container['user'];
The session object
/** @var \Session $session */ $session = $container['session'];
Lazy access to the $objPage object
/** @var DependencyInjection\Container\PageProvider */ $pageProvider = $container['page-provider']; $page = $pageProvider->getPage();