Subversion Repositories Applications.framework

Compare Revisions

Ignore whitespace Rev 241 → Rev 242

/trunk/exemple/scripts/cli.php
New file
0,0 → 1,37
<?php
// Encodage : UTF-8
// +-------------------------------------------------------------------------------------------------------------------+
/**
* Initialise le chargement et l'exécution des scripts
*
* Lancer ce fichier en ligne de commande avec :
* <code>/opt/lampp/bin/php cli.php mon_script -a test</code>
*
//Auteur original :
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
* @copyright Tela-Botanica 1999-2008
* @licence GPL v3 & CeCILL v2
* @version $Id$
*/
// +-------------------------------------------------------------------------------------------------------------------+
 
// Le fichier autoload.inc.php du Framework de Tela Botanica doit être appelée avant tout autre chose dans l'application.
// Sinon, rien ne sera chargé.
// Chemin du fichier chargeant le framework requis
$framework = dirname(__FILE__).DIRECTORY_SEPARATOR.'framework.php';
if (!file_exists($framework)) {
$e = "Veuillez paramétrer l'emplacement et la version du Framework dans le fichier $framework";
trigger_error($e, E_USER_ERROR);
} else {
// Inclusion du Framework
require_once $framework;
 
// Ajout d'information concernant cette application
Framework::setCheminAppli(__FILE__);// Obligatoire
Framework::setInfoAppli(Config::get('info'));
 
// Initialisation et lancement du script appelé en ligne de commande
Cli::executer();
}
?>
/trunk/exemple/scripts/modules/mon_script/config.ini
New file
0,0 → 1,0
param1 = "config OK";
/trunk/exemple/scripts/modules/mon_script/MonScript.php
New file
0,0 → 1,66
<?php
// declare(encoding='UTF-8');
/**
* Exemple de script utilisable avec le TBFramework.
* Pour le lancer, taper en ligne de commande, en vous plaçant dans le dossier /framework/exemple/scripts/ :
* <code>/opt/lampp/bin/php cli.php mon_script -a test</code>
*
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
* @version $Id$
*/
class MonScript extends Script {
protected $parametres_autorises = array(
'-y' => array(false, 'exemple de valeur par défaut', 'Un parametre supplémentaire de test'));
public function executer() {
// Récupération de paramêtres
 
// Lancement de l'action demandée
$cmd = $this->getParametre('a');
switch ($cmd) {
case 'test' :
$this->executerTest();
break;
default :
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
}
}
 
private function executerTest() {
print('Config: '.Config::get('param1')."\n");
$this->traiterErreur("Un msg d'%s", array('erreur'));
$this->traiterErreur("Un msg d'erreur sans paramètre");
$this->traiterAvertissement("Un msg d'%s", array('avertissement'));
$this->traiterAvertissement("Un msg d'avertissement sans paramètre");
$this->traiterInfo("Un msg d'%s", array('info'));
$this->traiterInfo("Un msg d'info sans paramètre");
echo $this->formaterMsg("Un msg %s", array('formaté'));
echo $this->formaterMsg("Le parametre y : %s", array($this->getParametre('y')));
// Test de l'affichage de l'avancement dans une boucle en partant de 1
$ma_liste = array();
for ($i = 0; $i < 1000; $i++) {
$ma_liste[] = $i;
for ($j = 0; $j < 100; $j++) {
$ma_liste[] = "$i-$j";
// 1 seule boucle peut être affichée
}
$this->afficherAvancement("Afficher de l'avancement de la boucle for", 1);
}
echo "\n";
// Test de l'affichage de l'avancement dans une boucle en partant par défaut de 0
foreach ($ma_liste as $cle => $valeur) {
$this->afficherAvancement("Afficher de l'avancement de la boucle foreach");
}
echo "\n";
print("test réussi!\n");
}
}
?>
/trunk/exemple/scripts/framework.defaut.php
New file
0,0 → 1,6
<?php
// Inclusion du Framework
// Renomer ce fichier en "framework.php"
// Indiquyer ci-dessous le chemin absolu vers le fichier autoload.inc.php de la bonne version du Framework
require_once '../../framework/Framework.php';
?>