Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/contao-community-alliance/dependency-container
Dependency container for Contao Open Source CMS based on the Pimple Dependency Injection Container
https://github.com/contao-community-alliance/dependency-container
Last synced: about 2 months ago
JSON representation
Dependency container for Contao Open Source CMS based on the Pimple Dependency Injection Container
- Host: GitHub
- URL: https://github.com/contao-community-alliance/dependency-container
- Owner: contao-community-alliance
- License: lgpl-3.0
- Created: 2013-05-16T12:41:10.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-09-05T20:24:42.000Z (over 2 years ago)
- Last Synced: 2024-11-25T08:43:48.431Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 202 KB
- Stars: 1
- Watchers: 10
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
Dependency Injection Container for Contao Open Source CMS
===============================================
[![Version](http://img.shields.io/packagist/v/contao-community-alliance/dependency-container.svg?style=flat-square)](https://packagist.org/packages/contao-community-alliance/dependency-container)
[![Build Status](https://github.com/contao-community-alliance/dependency-container/actions/workflows/diagnostics.yml/badge.svg)](https://github.com/contao-community-alliance/dependency-container/actions)
[![License](http://img.shields.io/packagist/l/contao-community-alliance/dependency-container.svg?style=flat-square)](http://spdx.org/licenses/LGPL-3.0+)
[![Downloads](http://img.shields.io/packagist/dt/contao-community-alliance/dependency-container.svg?style=flat-square)](https://packagist.org/packages/contao-community-alliance/dependency-container)This DI Container based on [Pimple](http://pimple.sensiolabs.org).
***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](UPGRADING-TO-CONTAO4.md)
Register parameters and services
--------------------------------system/modules/X/config/services.php
```php
$container['myservice.param'] = 'value';
$container['myservice'] = function($container) {
return new MyServiceClassName();
}
```Access parameters and services
------------------------------```php
class MyClass
{
function myFunction()
{
global $container;$parameter = $container['myservice.param'];
$service = $container['myservice'];
}
}
```Build-in services
-----------------### The config object
```php
/** @var \Config $config */
$config = $container['config'];
```### The environment object
```php
/** @var \Environment $environment */
$environment = $container['environment'];
```### The database connection
```php
/** @var \Database $database */
$database = $container['database.connection'];
```### The input object
```php
/** @var \Input $input */
$input = $container['input'];
```### The backend or frontend user, depend on TL_MODE
```php
/** @var \BackendUser|\FrontendUser $user */
$user = $container['user'];
```### The session object
```php
/** @var \Session $session */
$session = $container['session'];
```### Lazy access to the $objPage object
```php
/** @var DependencyInjection\Container\PageProvider */
$pageProvider = $container['page-provider'];
$page = $pageProvider->getPage();
```