contao-community-alliance / dependency-container
Dependency container based on pimple for Contao open source cms.
Installs: 127 834
Dependents: 34
Suggesters: 0
Security: 0
Stars: 1
Watchers: 10
Forks: 4
Open Issues: 2
Type:contao-bundle
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.9
- pimple/pimple: ^1.0
- symfony/config: ^4.0 || ^5.4
- symfony/dependency-injection: ^4.1.12 || ^5.4
- symfony/http-kernel: ^4.0 || ^5.4
- symfony/yaml: ^4.0 || ^5.4
Requires (Dev)
- contao/manager-bundle: ^4.4
- phpcq/runner-bootstrap: ^1.0@dev
This package is auto-updated.
Last update: 2024-11-06 01:43:07 UTC
README
This DI Container based on Pimple.
NOTE on Contao 4: This is obsolete in Contao 4 - you should use the symfony container in Contao 4.
This extension keeps compatibility for easing migration to Contao 4 - however, you should change your code to register your services using both registration ways.
For a howto of how to migrate to Contao 4, please refer to the UPGRADING-TO-CONTAO4.md
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();