Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 65 → Rev 66

/trunk/scripts/bibliotheque/EfloreScript.php
New file
0,0 → 1,80
<?php
// declare(encoding='UTF-8');
/**
* EfloreScript est une classe abstraite qui doit être implémenté par les classes éxecutant des scripts
* en ligne de commande pour les projets d'eFlore.
*
* @category PHP 5.2
* @package Eflore/Scripts
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Copyright (c) 2011, 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
* @since 0.3
* @version $Id$
* @link /doc/framework/
*/
abstract class EfloreScript extends Script {
 
private $Bdd = null;
private $projetNom = null;
 
public function getProjetNom() {
return $this->projetNom;
}
 
protected function initialiserProjet($projetNom) {
$this->projetNom = $projetNom;
$this->chargerConfigDuProjet();
}
 
//+------------------------------------------------------------------------------------------------------+
// Méthodes d'accès aux objets du Framework
/**
* Méthode de connection à la base de données sur demande.
* Tous les scripts n'ont pas besoin de s'y connecter.
*/
protected function getBdd() {
if (! isset($this->Bdd)) {
$this->Bdd = new Bdd();
}
return $this->Bdd;
}
 
//+------------------------------------------------------------------------------------------------------+
// Méthodes communes aux projets d'eFlore
 
protected function chargerConfigDuProjet() {
$fichierIniDefaut = $this->getScriptChemin().$this->getProjetNom().'.defaut.ini';
if (file_exists($fichierIniDefaut)) {
$fichierIni = $this->getScriptChemin().$this->getProjetNom().'.ini';
if (file_exists($fichierIni)) {
Config::charger($fichierIni);
} else {
$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
throw new Exception($m);
}
}
}
 
protected function chargerStructureSql() {
$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
$requetes = Outils::extraireRequetes($contenuSql);
foreach ($requetes as $requete) {
$this->getBdd()->requeter($requete);
}
}
 
protected function stopperLaBoucle($limite) {
$stop = false;
static $ligneActuelle = 1;
if ($nbreLignesATester = $limite) {
if ($nbreLignesATester == $ligneActuelle++) {
$stop = true;
}
}
return $stop;
}
}
?>