1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| static public function singleton($pluginName, $config, $fwmode = false, $useProfil = false, $useLanguage = false, $id = null) {
try{
if ($pluginName == '') {
throw new ApplicationControllerException("ServiceLoader > singleton() : parametres introuvables pour le plugin [ $pluginName ], mode [ $fwmode ] !", E_USER_ERROR);
return false;
}
$pluginName = trim( $pluginName );
$signature = array ($pluginName, $config, $fwmode);
$signature[] = ($useProfil) ? ApplicationController :: getProfil() : '';
$signature[] = ($useLanguage) ? ApplicationController :: getLanguage() : '';
$signature[] = $id ;
$signature = serialize($signature);
if (!isset ( self :: $_instances[$signature]) ) {
self::$keepInstance[] = $signature;
self::$_instances[$signature] = self::factory($pluginName, $config, $fwmode);
echo $pluginName.'--'.self::$_instances[$signature].'<br/>';
}
if( ! self::$_instances[$signature] instanceof $pluginName){
throw new ApplicationControllerException('erreur lors de la creation de l\'instance du plugin '.$pluginName, E_USER_FATAL);
}
}catch(ApplicationControllerException $epe){}
return self::$_instances[$signature];
}
static protected function factory($pluginName, $config, $fwmode) {
if ($pluginName == '') {
throw new ApplicationControllerException("ServiceLoader > factory() : parametres introuvables pour le plugin [ $pluginName ] !", E_USER_ERROR);
return false;
}
$filePlugin = ServiceLoader :: searchPlugin($pluginName);
if ( !$filePlugin) {
throw new ApplicationControllerException("ServiceLoader > factory() : Plugin [ $pluginName ] introuvable !<br/>$filePlugin", E_USER_ERROR);
}
if (isset ($config) && ($config != '')) {
$tabconf = ServiceLoader :: searchConfigPlugin($pluginName, $filePlugin, $config, $fwmode);
} else {
$tabconf = array ();
}
if ( isset ($tabconf)) {
return new $pluginName($tabconf);
} else {
throw new ApplicationControllerException("ServiceLoader > factory() : configuration [ $config ] et classe plugin [ $pluginName ] introuvables !", E_USER_ERROR);
}
return false;
} |
Partager