242 |
jpm |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Exemple de script utilisable avec le TBFramework.
|
|
|
5 |
* Pour le lancer, taper en ligne de commande, en vous plaçant dans le dossier /framework/exemple/scripts/ :
|
|
|
6 |
* <code>/opt/lampp/bin/php cli.php mon_script -a test</code>
|
|
|
7 |
*
|
|
|
8 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
9 |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
|
|
|
10 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
|
|
|
11 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
|
|
|
12 |
* @version $Id$
|
|
|
13 |
*/
|
|
|
14 |
class MonScript extends Script {
|
|
|
15 |
|
|
|
16 |
protected $parametres_autorises = array(
|
|
|
17 |
'-y' => array(false, 'exemple de valeur par défaut', 'Un parametre supplémentaire de test'));
|
|
|
18 |
|
|
|
19 |
public function executer() {
|
|
|
20 |
// Récupération de paramêtres
|
|
|
21 |
|
|
|
22 |
// Lancement de l'action demandée
|
|
|
23 |
$cmd = $this->getParametre('a');
|
|
|
24 |
switch ($cmd) {
|
|
|
25 |
case 'test' :
|
|
|
26 |
$this->executerTest();
|
|
|
27 |
break;
|
|
|
28 |
default :
|
|
|
29 |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
private function executerTest() {
|
|
|
34 |
print('Config: '.Config::get('param1')."\n");
|
|
|
35 |
$this->traiterErreur("Un msg d'%s", array('erreur'));
|
|
|
36 |
$this->traiterErreur("Un msg d'erreur sans paramètre");
|
|
|
37 |
$this->traiterAvertissement("Un msg d'%s", array('avertissement'));
|
|
|
38 |
$this->traiterAvertissement("Un msg d'avertissement sans paramètre");
|
|
|
39 |
$this->traiterInfo("Un msg d'%s", array('info'));
|
|
|
40 |
$this->traiterInfo("Un msg d'info sans paramètre");
|
|
|
41 |
echo $this->formaterMsg("Un msg %s", array('formaté'));
|
|
|
42 |
echo $this->formaterMsg("Le parametre y : %s", array($this->getParametre('y')));
|
|
|
43 |
|
|
|
44 |
// Test de l'affichage de l'avancement dans une boucle en partant de 1
|
|
|
45 |
$ma_liste = array();
|
|
|
46 |
for ($i = 0; $i < 1000; $i++) {
|
|
|
47 |
$ma_liste[] = $i;
|
|
|
48 |
|
|
|
49 |
for ($j = 0; $j < 100; $j++) {
|
|
|
50 |
$ma_liste[] = "$i-$j";
|
|
|
51 |
// 1 seule boucle peut être affichée
|
|
|
52 |
}
|
|
|
53 |
$this->afficherAvancement("Afficher de l'avancement de la boucle for", 1);
|
|
|
54 |
}
|
|
|
55 |
echo "\n";
|
|
|
56 |
|
|
|
57 |
// Test de l'affichage de l'avancement dans une boucle en partant par défaut de 0
|
|
|
58 |
foreach ($ma_liste as $cle => $valeur) {
|
|
|
59 |
$this->afficherAvancement("Afficher de l'avancement de la boucle foreach");
|
|
|
60 |
}
|
|
|
61 |
echo "\n";
|
|
|
62 |
|
|
|
63 |
print("test réussi!\n");
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
?>
|