designs2 / dependency-container
Dependency container based on pimple for Contao open source cms.
Installs: 70
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 4
Type:contao-module
Requires
- php: >=5.3
- contao-community-alliance/composer-plugin: ~2.0
- contao/core: >=3.2,<3.6-dev
- pimple/pimple: ~1.0
Requires (Dev)
- phpcq/all-tasks: ~1.0
Replaces
- bit3/contao-dependency-container: 1.8.1
- contao-legacy/dependency-container: 1.8.1
This package is not auto-updated.
Last update: 2024-10-02 18:34:29 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();