Subversion Repositories Applications.gtt

Compare Revisions

Ignore whitespace Rev 153 → Rev 181

/branches/v1.2-democrite/bibliotheque/noyau/Registre.class.php
New file
0,0 → 1,130
<?php
 
class Registre {
private $aso_stock = array();
private static $registre = null;
private $suivant;
private $titre;
private $espaces = array();
private $donnees = array();
private $squelettes;
 
public static function getRegistre()
{
if (is_null(Registre::$registre)) {
Registre::$registre = new Registre;
}
return Registre::$registre;
}
 
function set($intitule, $objet)
{
if (is_array($objet) && isset($this->aso_stock[$intitule])) {
$this->aso_stock[$intitule] = array_merge((array)$this->aso_stock[$intitule], (array)$objet);
$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !";
trigger_error($message, E_USER_WARNING);
} else {
$this->aso_stock[$intitule] = $objet;
}
}
 
function get($intitule)
{
if (isset($this->aso_stock[$intitule])) {
return $this->aso_stock[$intitule];
}
return false;
}
 
function detruire($intitule)
{
if (isset($this->aso_stock[$intitule])) {
unset($this->aso_stock[$intitule]);
}
}
 
public function etrePresent($intitule)
{
if(isset($this->aso_stock[$intitule])){
return true;
}
return false;
}
 
// Titre
public function getTitre()
{
return $this->titre;
}
public function setTitre($t)
{
$this->titre = $t;
}
 
// Espaces De Nomage
public function setEspaces($e)
{
$this->espaces = $e;
}
public function ajouterEspace($cle, $val)
{
$this->espaces[$cle] = $val;
}
public function getEspaces($cle = null)
{
if ($cle != null) {
if (isset($this->espaces[$cle])) {
return $this->espaces[$cle];
}
} else {
return $this->espaces;
}
}
 
// Donnees
public function setDonnees($d)
{
$this->donnees = $d;
}
public function ajouterDonnee($cle, $val)
{
if (is_array($val) && isset($this->donnees[$cle])) {
$this->donnees[$cle] = array_merge((array)$this->donnees[$cle], $val);
trigger_error('Fusion de données pour la clé : '. $cle, E_USER_NOTICE);
} else {
$this->donnees[$cle] = $val;
}
}
public function getDonnees($cle = null)
{
if (!is_null($cle)) {
if (isset($this->donnees[$cle])) {
return $this->donnees[$cle];
}
} else {
return $this->donnees;
}
}
 
// Squelettes
public function setSquelettes($s)
{
$this->squelettes = $s;
}
public function ajouterSquelette($cle, $val)
{
$this->squelettes[$cle] = $val;
}
public function getSquelettes($cle = null)
{
if ($cle != null) {
if (isset($this->squelettes[$cle])) {
return $this->squelettes[$cle];
}
return false;
} else {
return $this->squelettes;
}
}
}
?>
/branches/v1.2-democrite/bibliotheque/noyau/Chronometre.class.php
New file
0,0 → 1,187
<?php
// +------------------------------------------------------------------------------------------------------+
// | PHP version 5.0.4 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of eFlore-Debogage. |
// | |
// | Foobar is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | Foobar is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with Foobar; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: Chronometre.class.php,v 1.1 2007-01-12 13:16:09 jp_milcent Exp $
/**
* Classe permettant de mesurer le temps d'execution d'un script.
*
* Contient des méthodes permettant d'évaluer la vitesse d'exécution d'un script.
*
*@package eFlore
*@subpackage Debogage
//Auteur original :
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author aucun
*@copyright Tela-Botanica 2000-2005
*@version $Revision: 1.1 $ $Date: 2007-01-12 13:16:09 $
// +------------------------------------------------------------------------------------------------------+
*/
 
// +------------------------------------------------------------------------------------------------------+
// | ENTETE du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
// +------------------------------------------------------------------------------------------------------+
// | CORPS du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
/**Classe Chronometre() - Permet de stocker et d'afficher les temps d'éxécution de script.
*
* Cette classe permet de réaliser un ensemble de mesure de temps prises à
* différents endroits d'un script. Ces mesures peuvent ensuite être affichées au
* sein d'un tableau XHTML.
*
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
*/
class Chronometre
{
/*** Attributs : ***/
private $temps = array();
private $temps_sql = 0;
/*** Constructeur : ***/
public function __construct() {
$this->setTemps(array('depart' => microtime()));
}
/*** Accesseurs : ***/
// Temps
public function getTemps($cle = NULL) {
if (!is_null($cle)) {
return $this->temps[$cle];
} else {
return $this->temps;
}
}
public function setTemps($moment = array()) {
array_push($this->temps, $moment);
}
 
// Temps Sql
// Notes : utiliser microtime(true) pour renvoyer un float
public function getTempsSql() {
return $this->temps_sql;
}
public function setTempsSql($tps_deb, $tps_fin = null) {
if (is_null($tps_fin)) {
if (is_float($tps_deb)) {
$this->temps_sql += $tps_deb;
}
} else {
if (is_float($tps_deb) && is_float($tps_fin)) {
$this->temps_sql += $tps_fin - $tps_deb;
}
}
}
/*** Méthodes : ***/
/**Méthode afficherChrono() - Permet d'afficher les temps d'éxécution de différentes parties d'un script.
*
* Cette fonction permet d'afficher un ensemble de mesure de temps prises à différents endroits d'un script.
* Ces mesures sont affichées au sein d'un tableau XHTML dont on peut controler l'indentation des balises.
* Pour un site en production, il suffit d'ajouter un style #chrono {display:none;} dans la css. De cette façon,
* le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style affichant le tableau.
* Le développeur initial de cette fonction est Loic d'Anterroches. Elle a été modifiée par Jean-Pascal Milcent.
* Elle utilise une variable gobale : $_CHRONO_
*
* @author Loic d'Anterroches
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @param int l'indentation de base pour le code html du tableau.
* @param int le pas d'indentation pour le code html du tableau.
* @return string la chaine XHTML de mesure des temps.
*/
function afficherChrono($indentation_origine = 8, $indentation = 4) {
// Création du chrono de fin
$GLOBALS['_EFLORE_']['chrono']->setTemps(array('fin' => microtime()));
 
// Début création de l'affichage
$sortie = str_repeat(' ', $indentation_origine).
'<table id="chrono" lang="fr" summary="Résultat du chronométrage du programme affichant la page actuelle.">'."\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
'<caption>Chronométrage</caption>'."\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
'<thead>'."\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
'<tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
'</thead>'."\n";
$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))).
'<tbody>'."\n";
$total_tps_ecoule = 0;
// Récupération de la première mesure
$tab_depart =& $this->getTemps(0);
list($usec, $sec) = explode(' ', $tab_depart['depart']);
// Ce temps correspond à tps_fin
$tps_debut = ((float)$usec + (float)$sec);
foreach ($this->getTemps() as $tab_temps) {
foreach ($tab_temps as $cle => $valeur) {
list($usec, $sec) = explode(' ', $valeur);
$tps_fin = ((float)$usec + (float)$sec);
$tps_ecoule = abs($tps_fin - $tps_debut);
$total_tps_ecoule += $tps_ecoule;
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
'<tr>'.
'<th>'.$cle.'</th>'.
'<td>'.number_format($tps_ecoule, 3, ',', ' ').'</td>'.
'<td>'.number_format($total_tps_ecoule, 3, ',', ' ').'</td>'.
'</tr>'."\n";
$tps_debut = $tps_fin;
}
}
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
'</tbody>'."\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
'<tfoot>'."\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
'<tr>'.
'<th>'.'Total du temps écoulé (en s.)'.'</th>'.
'<td colspan="2">'.number_format($total_tps_ecoule,3, ',', ' ').'</td>'.
'</tr>'."\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
'</tfoot>'."\n";
$sortie .= $tbody;
$sortie .= str_repeat(' ', $indentation_origine).
'</table>'."\n";
return $sortie;
}
 
}
 
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log$
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>
/branches/v1.2-democrite/bibliotheque/noyau/aControlleurAction.class.php
New file
0,0 → 1,95
<?php
 
abstract class aControlleurAction {
 
private $suivant;
 
public function getRegistre()
{
return Registre::getRegistre();
}
 
// Suivant
public function getSuivant()
{
return $this->suivant;
}
public function setSuivant($s, $position = null)
{
if (is_array($s)){
$this->suivant = $s;
} else {
if (!is_null($position)) {
$tab_fin = array_slice($this->suivant, $position);
$tab_deb = array_slice($this->suivant, 0, $position);
$this->suivant = array_merge($tab_deb, array($s), $tab_fin);
} else {
$this->suivant[] = $s;
}
}
}
 
public function demarrer()
{
if (!is_null($this->getSuivant())) {
// ATTENTION :
// Il est important de laisser "count($this->getSuivant())" $this->getSuivant() peut varier de taille
for ($i = 0; $i < count($this->getSuivant()) ; $i++) {
//echo '<pre>'.print_r($this->getSuivant(), true).'</pre>';
if ($this->getRegistre()->get('action_finale')) {
// Si l'action met fin au script prématurément nous arrétons
break;
} else {
$liste_actions = $this->getSuivant();
//echo '<pre>'.print_r($liste_actions[$i], true).'</pre>';
if ($liste_actions[$i] instanceof aControlleurAction) {
$liste_actions[$i]->demarrer();
} else {
if (isset($_POST) || isset($_GET)) {
// Méthode "vérifier" générale présente dans aControlleurAction
$this->verifier();
$methode_verif = 'verifier'.$liste_actions[$i];
if (method_exists($this, $methode_verif)) {
// Méthode "vérifier" spécifique à une action
$this->$methode_verif();
}
}
if ($liste_actions[$i] == '__defaut__') {
$methode = 'executer';
} else {
$methode = 'executer'.$liste_actions[$i];
}
if (method_exists($this, $methode)) {
$this->$methode();
} else {
$m = "La méthode $methode de la classe ".get_class($this)." est introuvable!";
trigger_error($m, E_USER_ERROR);
}
}
}
}
} else {
$m = "Le registre ne contient aucune action!";
trigger_error($m, E_USER_ERROR);
}
}
 
public function verifier()
{
// Nous rassemblons les valeurs du tableau _POST contenant des : dans des sous-tableau de _POST.
foreach ($_POST as $cle => $val) {
$morceau = array();
if (preg_match('/^(.+?)(:.+)+$/', $cle, $morceau)) {
$table = '';
foreach (explode(':', trim($morceau[2], ':')) as $c) {
$table .= '['.$c.']';
}
eval('$_POST[$morceau[1]]'.$table.' = $val;');
unset($_POST[$cle]);
}
}
}
 
abstract protected function executer();
}
?>
/branches/v1.2-democrite/bibliotheque/noyau/GestionnaireErreur.class.php
New file
0,0 → 1,423
<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 5.0.4 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of eFlore-Debogage. |
// | |
// | Foobar is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | Foobar is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with Foobar; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: GestionnaireErreur.class.php,v 1.6 2007-07-09 18:54:43 jp_milcent Exp $
/**
* Classe de gestion des erreurs.
*
*
*
*@package eFlore
*@subpackage Debogage
//Auteur original :
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author aucun
*@copyright Tela-Botanica 2000-2005
*@version $Revision: 1.6 $ $Date: 2007-07-09 18:54:43 $
// +------------------------------------------------------------------------------------------------------+
*/
 
// +------------------------------------------------------------------------------------------------------+
// | ENTETE du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
// +------------------------------------------------------------------------------------------------------+
// | CORPS du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
/**
* Classe GestionnaireErreur
*
* Gérer les erreurs PHP et SQL.
*/
class GestionnaireErreur
{
/*** Attributes: ***/
 
/**
* Permet de savoir si on utilise PHP en ligne de commande dans une console (PHP-CLI) ou en mode module de serveur.
* @access private
*/
private $mode;
 
/**
* Contient la liste des erreurs.
* @access private
*/
private $erreurs;
 
/**
* Permet de savoir si on veut faire apparaître ou pas le contexte de l'erreur,
* c'est à dire le contenu des variables.
* @access private
*/
private $contexte;
/**
* Contient le niveau d'erreur courrant. Celui que l'on donne à la fonction
* error_reporting().
* @access private
*/
private $niveau_erreur_courrant;
/*** Constructeur: ***/
/**
* Construit le gestionnaire d'erreur.
*
* @return void
* @access public
*/
public function __construct( $contexte = false )
{
$this->mode = php_sapi_name();
$this->erreurs = array();
$this->setContexte($contexte);
set_error_handler(array(&$this, 'gererErreur'));
}
/*** Accesseurs: ***/
// end of member function __construct
/**
* Récupère le tableau des erreurs.
*
* @return array
* @access public
*/
public function getErreur( ) {
return $this->erreurs;
}
 
/**
* Ajoute une erreur à la liste.
*
* @param array une_erreur
* @return void
* @access public
*/
public function setErreur( $une_erreur ) {
$this->erreurs[] = $une_erreur;
}
 
/**
* Récupère la valeur du contexte.
*
* @return boolean
* @access public
*/
public function getContexte( ) {
return $this->contexte;
}
 
/**
* Définit si oui ou non le contexte sera affiché.
*
* @param boolean un_contexte
* @return void
* @access public
*/
public function setContexte( $un_contexte ) {
$this->contexte = $un_contexte;
}
/**
* Récupère le niveau d'erreur courrant.
*
* @return int le niveau d'erreur courrant.
* @access public
*/
public function getNiveauErreurCourrant( ) {
return (int)$this->niveau_erreur_courrant;
}
 
/**
* Définit le niveau d'erreur courrant.
*
* @param int un niveau d'erreur.
* @return void
* @access public
*/
public function setNiveauErreurCourrant( $niveau = 2048 ) {
$this->niveau_erreur_courrant = $niveau;
}
/**
* Définit le niveau d'erreur courrant (synonyme fonction precedente)
*
* @param int un niveau d'erreur.
* @return void
* @access public
*/
public function setActive ($niveau) {
$this->niveau_erreur_courrant = $niveau;
}
/*** Méthodes : ***/
/**
*
* @param int niveau
* @param string message
* @param string fichier
* @param int ligne
* @param boolean contexte
* @return void
* @access public
*/
public function gererErreur($niveau, $message, $fichier, $ligne, $contexte)
{
$aso_erreur = array();
// Nous vérifions si nous affichons ou pas l'erreur en fonction du niveau demandé
if ( $niveau <= $this->getNiveauErreurCourrant() ) {
$aso_erreur['niveau'] = $niveau;
$aso_erreur['message'] = $message;
$aso_erreur['fichier'] = $fichier;
$aso_erreur['ligne'] = $ligne;
if ($this->getContexte()) {
$aso_erreur['contexte'] = $contexte;
}
$this->setErreur($aso_erreur);
}
// Si nous avons à faire à une erreur et non à un warning ou une notice, nous arrêtons l'exécution du script
switch ($niveau) {
case E_ERROR :
case E_USER_ERROR :
die($this->retournerErreur());
break;
}
}
 
/**
* Retourne l'erreur PHP formatée en XHTML.
*
* @return string
* @access public
*/
public function retournerErreur()
{
$retour = '';
$erreur_pear_nbre = 0;
$erreur_pear_fichier_nbre = 0;
$erreur_pear_message_nbre = 0;
foreach($this->getErreur() as $aso_erreur) {
if ('<!-- BEGIN sql -->' == substr($aso_erreur['message'], 0, 18)) {
$retour .= $aso_erreur['message'];
continue;
}
// Nous testons les erreurs PEAR pour ne pas en tenir compte
if (!GTT_DEBOGAGE_PEAR && preg_match(GTT_DEBOGAGE_PEAR_REGEXP_CHAINE, $aso_erreur['fichier'])) {
$erreur_pear_fichier_nbre++;
} else if (!GTT_DEBOGAGE_PEAR && preg_match(GTT_DEBOGAGE_PEAR_REGEXP_MESSAGE, $aso_erreur['message'])) {
$erreur_pear_message_nbre++;
} else {
switch ($this->mode) {
case 'cli' :
if ($aso_erreur['niveau'] == E_USER_NOTICE) {
$retour .= $aso_erreur['message']."\n";
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n";
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n";
} else if ($aso_erreur['niveau'] <= 512) {
$retour .= 'INFO : Niveau '.$aso_erreur['niveau']."\n";
} else {
$retour .= 'ERREUR : Niveau '.$aso_erreur['niveau']."\n";
}
$retour .= 'Niveau : '.$aso_erreur['niveau']."\n";
$retour .= 'Message : '.$aso_erreur['message']."\n";
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n";
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n";
if ($this->getContexte()) {
$retour .= 'Contexte : '."\n".print_r($aso_erreur['contexte'], true)."\n";
}
break;
default:
if ($aso_erreur['niveau'] == E_USER_NOTICE) {
$retour .= '<pre class="debogage">'."\n";
$retour .= $aso_erreur['message']."\n";
$retour .= '<span class="debogage_fichier">'.'Fichier : '.$aso_erreur['fichier'].'</span>'."\n";
$retour .= '<span class="debogage_ligne">'.'Ligne : '.$aso_erreur['ligne'].'</span>'."\n";
$retour .= '</pre>'."\n";
continue;
} else if ($aso_erreur['niveau'] <= 512) {
$retour .= '<p class="information">'."\n";
$retour .= '<strong>INFO : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n";
} else {
$retour .= '<p class="attention">'."\n";
$retour .= '<strong>ERREUR : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n";
}
$retour .= '<strong>Niveau : </strong>'.$aso_erreur['niveau'].'<br />'."\n";
$retour .= '<strong>Message : </strong>'.$aso_erreur['message'].'<br />'."\n";
$retour .= '<strong>Fichier : </strong>'.$aso_erreur['fichier'].'<br />'."\n";
$retour .= '<strong>Ligne : </strong>'.$aso_erreur['ligne'].'<br />'."\n";
if ($this->getContexte()) {
$retour .= '<pre>'."\n";
$retour .= '<stong>Contexte : </stong>'."\n".print_r($aso_erreur['contexte'], true)."\n";
$retour .= '</pre>'."\n";
}
$retour .= '</p>'."\n";
}
}
}
$erreur_pear_nbre = $erreur_pear_fichier_nbre + $erreur_pear_message_nbre;
if ($erreur_pear_nbre != 0) {
$retour .= '<p class="attention">'.
'<strong>Nombre d\'erreurs PEAR totales : </strong>'.$erreur_pear_nbre.'<br />'."\n".
'<strong> - éliminées car le "fichier" correspondé à '.GTT_DEBOGAGE_PEAR_REGEXP_CHAINE.' : </strong>'.$erreur_pear_fichier_nbre.'<br />'."\n".
'<strong> - éliminées car le "message" correspondé à '.GTT_DEBOGAGE_PEAR_REGEXP_MESSAGE.' : </strong>'.$erreur_pear_message_nbre.'<br />'."\n".
'</p>'."\n";
}
return $retour;
}
 
/**
* Retourne l'erreur SQL formatée en XHTML.
*
* @param string fichier
* @param int ligne
* @param string message
* @param string requete
* @param string autres
* @return string
* @static
* @access public
*/
public static function retournerErreurSql( $fichier, $methode, $message, $requete = null, $autres = null )
{
$retour = '';
switch (php_sapi_name()) {
case 'cli' :
$retour .= 'ERREUR SQL '."\n";
$retour .= 'Fichier : '.$fichier."\n";
$retour .= 'Méthode : '.$methode."\n";
$retour .= 'Message : '.$message."\n";
if (!is_null($requete)) {
$retour .= 'Requete : '."\n";
$retour .= $requete."\n";
}
if (!is_null($autres)) {
$retour .= 'Autres infos : '."\n";
$retour .= $autres."\n";
}
break;
default:
$retour .= '<!-- BEGIN sql -->';
$retour .= '<div id="zone_erreur">'."\n";
$retour .= '<h1 > ERREUR SQL </h1><br />'."\n";
$retour .= '<dl>'."\n";
$retour .= '<dt> Fichier : </dt> ';
$retour .= '<dd> '.$fichier.'</dd>'."\n";
$retour .= '<dt> Méthode : </dt> ';
$retour .= '<dd> '.$methode.'</dd>'."\n";
$retour .= '<dt> Message erreur : </dt> ';
$retour .= '<dd> '.$message.'</dd>'."\n";
if (!is_null($requete)) {
$retour .= '<dt> Requete : </dt> ';
$retour .= '<dd> '.$requete.' </dd>'."\n";
}
if (!is_null($autres)) {
$retour .= '<dt> Autres infos : </dt> ';
$retour .= '<dd> '.$autres.' </dd>'."\n";
}
$retour .= '</dl>'."\n";
$retour .= '</div>'."\n";
$retour .= '<!-- END sql -->'."\n";
}
return $retour;
}
}
 
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: GestionnaireErreur.class.php,v $
* Revision 1.6 2007-07-09 18:54:43 jp_milcent
* Remplacement des balises html par des entités pour le message des E_USER_NOTICE.
*
* Revision 1.5 2007-07-02 15:31:53 jp_milcent
* Initialisation d'une variable.
*
* Revision 1.4 2007-07-02 12:43:09 jp_milcent
* Gestion de php-cli ou cgi...
*
* Revision 1.3 2007-07-02 10:50:06 jp_milcent
* Ajout de la gestion du mode d'affichage (xhtml ou txt).
*
* Revision 1.2 2007-01-15 15:30:03 jp_milcent
* Amélioration du gestionnaire d'erreur pour qu'il prenne en compte les erreurs Pear des méthodes "non static"...
*
* Revision 1.1 2007/01/12 13:16:09 jp_milcent
* Déplacement des classes de débogage et d'optimisation dans le dossier noyau.
*
* Revision 1.9 2006/10/25 08:15:23 jp_milcent
* Fusion avec la livraison Decaisne.
*
* Revision 1.8.2.1 2006/08/29 09:22:37 jp_milcent
* Correction et amélioration du gestionnaire d'erreurs.
*
* Revision 1.8 2006/07/20 13:33:46 jp_milcent
* Légère modif affichage.
*
* Revision 1.7 2006/07/20 13:33:03 jp_milcent
* Amélioration du gestionnaire d'erreur.
*
* Revision 1.6 2006/07/20 13:27:07 jp_milcent
* Ajout du type information.
*
* Revision 1.5 2006/05/29 13:52:41 ddelon
* Integration wiki dans eflore
*
* Revision 1.4 2005/12/09 10:47:05 jp_milcent
* Amélioration du Gestionnaire de Bogues.
*
* Revision 1.3 2005/10/10 07:28:07 jp_milcent
* Utilisation du webservice Yahoo-Image.
*
* Revision 1.2 2005/10/04 16:34:03 jp_milcent
* Début gestion de la chorologie.
* Ajout de la bibliothèque de cartographie (à améliorer!).
*
* Revision 1.1 2005/08/04 15:51:45 jp_milcent
* Implémentation de la gestion via DAO.
* Fin page d'accueil.
* Fin formulaire recherche taxonomique.
*
* Revision 1.3 2005/08/02 16:19:33 jp_milcent
* Amélioration des requetes de recherche de noms.
*
* Revision 1.2 2005/08/01 16:18:39 jp_milcent
* Début gestion résultat de la recherche par nom.
*
* Revision 1.1 2005/07/28 15:37:56 jp_milcent
* Début gestion des squelettes et de l'API eFlore.
*
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>
/branches/v1.2-democrite/bibliotheque/noyau/ControlleurFrontal.class.php
New file
0,0 → 1,161
<?php
 
class ControlleurFrontal {
 
private $url_action;
private $url_format;
private $url_sortie;
 
public function __construct($action, $format, $sortie)
{
$this->url_action = $action;
$this->url_format = $format;
$this->url_sortie = $sortie;
}
 
public function getRegistre()
{
return Registre::getRegistre();
}
 
public function parserAction($url)
{
if (preg_match('/^(.+?)(?:_(.+)|)$/', $url, $match)) {
$aso_compo_classe = explode('-', $match[1]);
$retour['classe_action'] = 'GttCtrlAction';
foreach ($aso_compo_classe as $mot) {
$retour['classe_action'] .= ucfirst($mot);
}
}
 
$retour['tab_actions'] = array('__defaut__');
if (isset($match[2])) {
preg_match_all('/(.+)(?:_|$)/', $match[2], $match_actions);
//echo '<pre>'.print_r($match_actions[1], true).'</pre>';
foreach ($match_actions[1] as $action) {
$aso_compo_action = explode('-', $action);
$action = '';
foreach ($aso_compo_action as $mot_action) {
$action .= ucfirst($mot_action);
}
$retour['tab_actions'][] = $action;
}
}
return $retour;
}
 
private function chargerActionGenerique(&$tab_actions)
{
// Gestion de l'identification
$GttCtrlActionIdentification = new GttCtrlActionIdentification($this->getRegistre());
$GttCtrlActionIdentification->setSuivant('__defaut__');
array_unshift($tab_actions, $GttCtrlActionIdentification);
 
// Gestion des menus
$GttCtrlActionMenu = new GttCtrlActionMenu($this->getRegistre());
$GttCtrlActionMenu->setSuivant('__defaut__');
$tab_actions[] = $GttCtrlActionMenu;
}
 
 
public function executer()
{
$tab_info_url = $this->parserAction($this->url_action);
//trigger_error(print_r($tab_info_url, true), E_USER_NOTICE);
$classe_action = $tab_info_url['classe_action'];
$fichier_action = GTT_CHEMIN_ACTION.$classe_action.'.class.php';
if (file_exists($fichier_action)) {
require_once $fichier_action;
$Action = new $classe_action($this->getRegistre());
$this->chargerActionGenerique($tab_info_url['tab_actions']);
$Action->setSuivant($tab_info_url['tab_actions']);
$Action->demarrer();
if ($this->url_format == 'html') {
$aso_principal['principal'] = $this->rendre();
//echo '<pre>'.print_r($aso_principal, true).'</pre>';
$aso_principal['principal']['titre'] = $this->getRegistre()->getTitre();
$this->getRegistre()->setEspaces(array());
$this->getRegistre()->setDonnees(array());
$this->getRegistre()->ajouterEspace('Principal', 'principal');
$this->getRegistre()->ajouterDonnee('principal', $aso_principal['principal']);
}
$sortie = $this->rendre();
 
// Gestion de la sortie
switch ($this->url_sortie) {
case 'html' :
echo $sortie;
break;
case 'csv' :
header('Content-Disposition: inline' );
header('Content-Type: text/plain');
header('Content-Length: '.strlen($sortie));
echo $sortie;
break;
case 'csvt' :
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="'.str_replace(' ', '_', $this->getRegistre()->getTitre()).'.csv";' );
header('Content-Length: '.strlen($sortie));
echo $sortie;
break;
}
exit();
} else {
$m = "Le fichier $fichier_action contenant l'action est introuvable!";
trigger_error($m, E_USER_ERROR);
}
}
 
public function rendre()
{
$contenu_principal = null;
$aso_contenu = array('zone_contenu' => '', 'zone_menu' => '', 'zone_identification' => '', 'zone_calendrier' => '');
foreach ($this->getRegistre()->getEspaces() as $espace_de_nom) {
if (is_array($this->getRegistre()->getDonnees($espace_de_nom))) {
$squelette = $espace_de_nom;
if (false != $this->getRegistre()->getSquelettes($espace_de_nom)) {
$squelette = $this->getRegistre()->getSquelettes($espace_de_nom);
}
$fichier_squelette = GTT_CHEMIN_PRESENTATION.$squelette.'.tpl.'.$this->url_format;
$squelette_erreur = $fichier_squelette;
if (file_exists($fichier_squelette)) {
$bool_squelette_erreur = false;
ob_start();
extract($GLOBALS['_GTT_']['i18n']['general'], EXTR_PREFIX_ALL, 'i18n_general');
extract($this->getRegistre()->getDonnees($espace_de_nom));
include_once $fichier_squelette;
if ($this->url_format == 'html') {
// Répartition dans des zones
switch($espace_de_nom) {
case 'principal' :
$contenu_principal .= ob_get_contents();
break;
case 'zone_calendrier' :
$aso_contenu['zone_calendrier'] .= ob_get_contents();
break;
case 'identification' :
$aso_contenu['zone_identification'] .= ob_get_contents();
break;
case 'zone_menu' :
$aso_contenu['zone_menu'] .= ob_get_contents();
break;
default:
$aso_contenu['zone_contenu'] .= ob_get_contents();
}
} else {
$contenu_principal = ob_get_contents();
}
ob_end_clean();
}
}
}
if ($bool_squelette_erreur) {
trigger_error("Absence du fichier de squelette : $squelette_erreur", E_USER_ERROR);
}
if (!is_null($contenu_principal)) {
return $contenu_principal;
}
return $aso_contenu;
}
}
?>