Skip to content
Extraits de code Groupes Projets
Valider 10b58b36 rédigé par Matthieu Napoli's avatar Matthieu Napoli
Parcourir les fichiers

Added PHP-DI + StaticContainer class

parent d9aef0c3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -43,7 +43,8 @@
"tedivm/jshrink": "~0.5.1",
"mustangostang/spyc": "~0.5.0",
"piwik/device-detector": "~2.0",
"piwik/decompress": "~0.1.1"
"piwik/decompress": "~0.1.1",
"mnapoli/php-di": "~4.4.0"
},
"require-dev": {
"aws/aws-sdk-php": "2.7.1",
......
Ce diff est replié.
<?php
return array(
);
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik;
use DI\Container;
use DI\ContainerBuilder;
use Interop\Container\ContainerInterface;
/**
* This class provides a static access to the container.
*
* @deprecated This class is introduced only to keep BC with the current static architecture. It will be removed in 3.0.
* - it is global state (that class makes the container a global variable)
* - using the container directly is the "service locator" anti-pattern (which is not dependency injection)
*/
class StaticContainer
{
/**
* @var Container
*/
private static $container;
/**
* @return ContainerInterface
*/
public static function getContainer()
{
if (self::$container === null) {
self::$container = self::createContainer();
}
return self::$container;
}
/**
* @link http://php-di.org/doc/container-configuration.html
*/
private static function createContainer()
{
$builder = new ContainerBuilder();
// TODO add cache
// $builder->setDefinitionCache($cache);
// $builder->writeProxiesToFile(true, PIWIK_USER_PATH . '/tmp/proxies');
// Global config
$builder->addDefinitions(PIWIK_USER_PATH . '/config/global.php');
// User config
if (file_exists(PIWIK_USER_PATH . '/config/config.php')) {
$builder->addDefinitions(PIWIK_USER_PATH . '/config/config.php');
}
return $builder->build();
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter