Subversion Repositories Applications.referentiel

Compare Revisions

Ignore whitespace Rev 343 → Rev 344

/branches/v2.0-betulales/scripts/bibliotheque/Script.php
New file
0,0 → 1,71
<?php
// Encodage : UTF-8
// +-------------------------------------------------------------------------------------------------------------------+
/**
* Script
*
* Description : Fabrique permettant de charger les scripts
*
//Auteur original :
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Tela-Botanica 1999-2008
* @licence GPL v3 & CeCILL v2
* @version $Id$
*/
// +-------------------------------------------------------------------------------------------------------------------+
 
class Script {
/** Niveau de message de type LOG */
const LOG = 0;
/** Niveau de message de type ERREUR */
const ERREUR = 1;
/** Niveau de message de type AVERTISSEMENT */
const AVERTISSEMENT = 2;
/** Niveau de message de type INFORMATION */
const INFO = 3;
public static function getCode($niveau) {
$txt_niveaux = array('LOG', 'ERREUR','AVERTISSEMENT', 'INFO');
return $txt_niveaux[$niveau];
}
public static function charger($commande_nom) {
$classe_nom = implode('', array_map('ucfirst', explode('_', strtolower($commande_nom))));
$fichier_script = ES_CHEMIN_MODULE.$commande_nom.DS.$classe_nom.'.php';
if (!file_exists($fichier_script)){
trigger_error("Erreur : script '$fichier_script' inconnu!\n", E_USER_ERROR);
}
require_once $fichier_script;
if (!class_exists( $classe_nom)) {
trigger_error("Erreur: impossible de trouver la classe de la commande : $classe_nom\n", E_USER_ERROR);
}
$Script = new $classe_nom($commande_nom);
return $Script;
}
public static function getParametres($argv) {
$parametres = array();
// Récupération des options
while(count($argv)) {
if (isset($argv[1]) && $argv[1]{0} != '-') {
$param = array_shift($argv);
$parametres[$param] = array_shift($argv);
} elseif (!isset($argv[1]) || $argv[1]{0} == '-') {
$parametres[array_shift($argv)] = null;
} else {
trigger_error("Erreur: valeur manquante pour le paramêtre '".$argv[0]."' \n", E_USER_ERROR);
}
}
return $parametres;
}
public static function setAutoloadChemin($chemin) {
if (is_array($chemin)) {
$GLOBALS['chemins_autoload'] = array_unique(array_merge($GLOBALS['chemins_autoload'], $chemin));
} else {
$GLOBALS['chemins_autoload'][] = $chemin;
}
}
}
?>