Subversion Repositories Applications.framework

Rev

Rev 299 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 299 Rev 387
Line 11... Line 11...
11
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
12
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
13
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
13
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
14
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
14
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
15
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
15
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
16
 * @since 		0.3 
16
 * @since 		0.3
17
 * @version	$Id: Cli.php 299 2011-01-18 14:03:46Z jpm $
17
 * @version	$Id: Cli.php 387 2011-10-28 15:57:40Z jpm $
18
 * @link		/doc/framework/
18
 * @link		/doc/framework/
19
 */
19
 */
Line 20... Line 20...
20
 
20
 
21
class Cli {
21
class Cli {
22
	
22
 
23
	/** Tableau des noms des paramètres à définir dans le fichier de config car obligatoirement nécessaire à cette classe.*/
23
	/** Tableau des noms des paramètres à définir dans le fichier de config car obligatoirement nécessaire à cette classe.*/
24
	private static $parametres_obligatoires = array('chemin_modules');
24
	private static $parametres_obligatoires = array('chemin_modules');
25
	
25
 
26
	
26
 
27
	/**
27
	/**
28
	 * Execute la ligne de commande en récupérant le nom du script à lancer et ses paramètres.
28
	 * Execute la ligne de commande en récupérant le nom du script à lancer et ses paramètres.
29
	 * Instancie la classe du script à lancer et appelle la méthode executer().
29
	 * Instancie la classe du script à lancer et appelle la méthode executer().
30
	 * @return void
30
	 * @return void
31
	 */
31
	 */
32
	public static function executer() {
32
	public static function executer() {
33
		if ($_SERVER['argc'] < 2){
33
		if ($_SERVER['argc'] < 2){
34
		   trigger_error("Erreur: vous n'avez pas indiqué le nom du script. Voir '".$_SERVER['argv'][0]." help'.\n", E_USER_ERROR);
34
		   trigger_error("Erreur: vous n'avez pas indiqué le nom du script. Voir '".$_SERVER['argv'][0]." help'.\n", E_USER_ERROR);
35
		}
35
		}
36
		
36
 
37
		// Récupération de la ligne de commande
37
		// Récupération de la ligne de commande
38
		$argv = $_SERVER['argv'];
38
		$argv = $_SERVER['argv'];
39
		// Nous dépilons le nom du fichier qui initialise le framework et appele cette méthode.
39
		// Nous dépilons le nom du fichier qui initialise le framework et appele cette méthode.
40
		array_shift($argv); 
40
		array_shift($argv);
41
		// Nous dépilons le nom du script à lancer
41
		// Nous dépilons le nom du script à lancer
42
		$script = array_shift($argv);
42
		$script = array_shift($argv);
43
		// Récupération des paramètres d'execution du script
43
		// Récupération des paramètres d'execution du script
44
		$parametres = self::getParametres($argv);
44
		$parametres = self::getParametres($argv);
45
		
45
 
46
		// Chargement du script à lancer
46
		// Chargement du script à lancer
47
		$Script = Cli::charger($script, $parametres);
47
		$Script = Cli::charger($script, $parametres);
48
		if (!is_null($Script)) {
48
		if (!is_null($Script)) {
49
			$Script->executer();
49
			$Script->executer();
50
		}
50
		}
51
		
51
 
52
		// 	Affichage des exceptions et erreurs générées par le script
52
		// 	Affichage des exceptions et erreurs générées par le script
53
		echo GestionnaireException::getExceptions();
53
		echo GestionnaireException::getExceptions();
54
		
54
 
55
		// Fin d'execution
55
		// Fin d'execution
56
		exit(0);
56
		exit(0);
57
	}
57
	}
58
	
58
 
59
	private static function charger($script_nom, $parametres) {
59
	private static function charger($script_nom, $parametres) {
60
		$Script = null;
60
		$Script = null;
61
		Config::verifierPresenceParametres(self::$parametres_obligatoires);
61
		Config::verifierPresenceParametres(self::$parametres_obligatoires);
-
 
62
 
-
 
63
		if (strpos($script_nom, DS)) {
-
 
64
			$decompoScriptNom = explode(DS, $script_nom);
-
 
65
			$script_nom = array_pop($decompoScriptNom);
-
 
66
			$dossier_nom = implode(DS, $decompoScriptNom);
-
 
67
		} else {
-
 
68
			$dossier_nom = strtolower($script_nom);
-
 
69
		}
62
		
70
 
63
		$classe_nom = self::obtenirNomClasse($script_nom);
-
 
64
		$dossier_nom = strtolower($script_nom);
71
		$classe_nom = self::obtenirNomClasse($script_nom);
65
		$fichier_script = Config::get('chemin_modules').$dossier_nom.DS.$classe_nom.'.php';
72
		$fichier_script = Config::get('chemin_modules').$dossier_nom.DS.$classe_nom.'.php';
66
		
73
 
67
		if (!file_exists($fichier_script)){
74
		if (!file_exists($fichier_script)){
68
			trigger_error("Erreur : script '$fichier_script' inconnu!\n", E_USER_ERROR);
75
			trigger_error("Erreur : script '$fichier_script' inconnu!\n", E_USER_ERROR);
69
		} else {
76
		} else {
70
			require_once $fichier_script;
77
			require_once $fichier_script;
Line 74... Line 81...
74
				$Script = new $classe_nom($script_nom, $parametres);
81
				$Script = new $classe_nom($script_nom, $parametres);
75
			}
82
			}
76
		}
83
		}
77
		return $Script;
84
		return $Script;
78
	}
85
	}
79
	
86
 
80
	private static function obtenirNomClasse($script_nom) {
87
	private static function obtenirNomClasse($script_nom) {
81
		$nom_classe = implode('', array_map('ucfirst', explode('_', strtolower($script_nom))));
88
		$nom_classe = implode('', array_map('ucfirst', explode('_', strtolower($script_nom))));
82
		return $nom_classe;
89
		return $nom_classe;
83
	}
90
	}
84
	
91
 
85
	private static function getParametres($argv) {
92
	private static function getParametres($argv) {
86
		$parametres = array();
93
		$parametres = array();
87
		// Récupération des options
94
		// Récupération des options
88
		while (count($argv)) {
95
		while (count($argv)) {
89
			if (isset($argv[1]) && $argv[1]{0} != '-') {
96
			if (isset($argv[1]) && $argv[1]{0} != '-') {