/trunk/framework/bibliotheque/Registre.php |
---|
File deleted |
\ No newline at end of file |
/trunk/framework/bibliotheque/Chronometre.php |
---|
File deleted |
\ No newline at end of file |
/trunk/framework/bibliotheque/Modele.php |
---|
File deleted |
\ No newline at end of file |
/trunk/framework/bibliotheque/GestionnaireException.php |
---|
File deleted |
/trunk/framework/bibliotheque/Net_URL.php |
---|
File deleted |
/trunk/framework/bibliotheque/Net_URL2.php |
---|
File deleted |
/trunk/framework/bibliotheque/Controleur.php |
---|
File deleted |
\ No newline at end of file |
/trunk/framework/bibliotheque/GestionnaireErreur.php |
---|
File deleted |
\ No newline at end of file |
/trunk/framework/config.inc.php |
---|
File deleted |
\ No newline at end of file |
/trunk/framework/Registre.php |
---|
New file |
0,0 → 1,88 |
<?php |
/** |
* Classe registre, qui permet un accès à différentes variables à travers les autres classes. |
* C'est un singleton |
*/ |
class Registre { |
/** |
* Tableau associatif stockant les variables |
*/ |
private $aso_stock = array(); |
/** |
* La classe registre se contient elle-même, (pour le pattern singleton) |
*/ |
private static $registre; |
/** |
* Constructeur par défaut, privé, car on accède à la classe par le getInstance |
*/ |
private function __construct() |
{ |
$registre = $this; |
} |
/** |
* Fonction qui renvoie l'instance de classe en assurant son unicité, c'est l'unique méthode qui doit être |
* utilisé pour récupérer l'objet Registre |
*/ |
public static function getInstance() |
{ |
if (self::$registre instanceof Registre) { |
return self::$registre; |
} |
self::$registre = new Registre; |
return self::$registre; |
} |
/** |
* Ajoute un objet au tableau selon un intitulé donné |
* @param string l'intitulé sous lequel l'objet sera conservé |
* @param mixed l'objet à conserver |
*/ |
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; |
} |
} |
/** |
* Renvoie l'objet associé à l'intitulé donné en paramètre |
* @return mixed l'objet associé à l'intitulé ou null s'il n'est pas présent |
*/ |
function get($intitule) |
{ |
if (isset($this->aso_stock[$intitule])) { |
return $this->aso_stock[$intitule]; |
} |
return null; |
} |
/** |
* Détruit l'objet associé à l'intitulé, n'a pas d'effet si il n'y a pas d'objet associé |
*/ |
function detruire($intitule) |
{ |
if (isset($this->aso_stock[$intitule])) { |
unset($this->aso_stock[$intitule]); |
} |
} |
/** |
* Teste si un objet est présent sous un intitulé donné |
* @return boolean true si un objet associé à cet intitulé est présent, false sinon |
*/ |
public function etrePresent($intitule) |
{ |
if(isset($this->aso_stock[$intitule])){ |
return true; |
} |
return false; |
} |
} |
?> |
Property changes: |
Added: svn:keywords |
+Id Author Date Revision HeadURL |
\ No newline at end of property |
/trunk/framework/config.defaut.ini |
---|
New file |
0,0 → 1,47 |
; +------------------------------------------------------------------------------------------------------+ |
; Débogage |
; Indique si oui ou non on veut afficher le débogage. |
fw_debogage = true |
; Indique si oui ou non on veut afficher le contexte de débogage. |
fw_debogage_contexte = false |
; Niveau d'erreur à employer pour le code PHP. Voir le manuel de PHP pour les différents niveaux disponibles. |
fw_debogage_niveau = 2048 |
; +------------------------------------------------------------------------------------------------------+ |
; Benchmark |
; Indique si oui ou nom on veut afficher le tableau de chronométrage de l'application. |
fw_benchmark_chrono = true |
; +------------------------------------------------------------------------------------------------------+ |
; Chemins et fichiers |
; Nom des fichiers de config recherché. Défini par défaut dans la classe Config |
; fw_fichier_config = "config.ini" |
; Chemin vers le dossier du framework. Défini par défaut dans la classe Config |
; fw_chemin = "php:dirname(__FILE__).DS" |
; Chemin vers le dossier de l'appli. Défini par défaut dans la classe Config |
; chemin_appli = "php:dirname($_SERVER['SCRIPT_FILENAME']).DS" |
; Chemin vers le dossier des controleurs de l'application. |
dossier_controleurs = "php:dirname($_SERVER['SCRIPT_FILENAME']).DS.'controleurs'.DS" |
; Chemin vers le dossier des modèles de l'application. |
dossier_modeles = "php:dirname($_SERVER['SCRIPT_FILENAME']).DS.'modeles'.DS" |
; Chemin vers le dossier des squelettes de l'application. |
dossier_squelettes = "php:dirname($_SERVER['SCRIPT_FILENAME']).DS.'squelettes'.DS" |
; +------------------------------------------------------------------------------------------------------+ |
; URLs |
; URL de base de l'application, si elle est laissée vide, l'application fonctionnera en Stand-alone |
url_base = "" |
; +------------------------------------------------------------------------------------------------------+ |
; Paramétrage de la base de données. |
; Protocole de la base de données. |
bdd_protocole = mysql |
; Nom du serveur de bases de données. |
bdd_serveur = localhost |
; Nom de l'utilisateur de la base de données. |
bdd_utilisateur = "root" |
; Mot de passse de l'utilisateur de la base de données. |
bdd_mot_de_passe = "" |
; Nom de la base de données principale. |
bdd_nom = papyrus |
/trunk/framework/Chronometre.php |
---|
New file |
0,0 → 1,172 |
<?php |
/** Fichier de la classe Chronometre |
* |
* PHP Version 5 |
* |
* @category PHP |
* @package Framework |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/framework/ |
*/ |
/** 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. |
* |
* |
* PHP Version 5 |
* |
* @category PHP |
* @package Framework |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version Release: <package_version> |
* @link /doc/framework/ |
*/ |
class Chronometre |
{ |
/*** Attributs : ***/ |
private $_temps = array (); |
/** Constructeur : **/ |
public function __construct() |
{ |
$this->setTemps( |
array ( |
'depart' => microtime() |
) |
); |
} |
/** Accesseurs : |
* |
* @param string $cle la cle associée à un chronomètre particulier |
* |
* @return int le temps écoulé |
*/ |
public function getTemps($cle = null) |
{ |
if (!is_null($cle)) { |
return $this->_temps[$cle]; |
} else { |
return $this->_temps; |
} |
} |
/** Setteur pour la variable temps |
* |
* @param array() $moment ajoute des points de chronométrage au tableau _temps |
* |
* @return null |
*/ |
public function setTemps($moment = array ()) |
{ |
array_push($this->_temps, $moment); |
} |
/*** 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 $indentation_origine l'indentation de base. |
* @param int $indentation le pas d'indentation. |
* @return string la chaine XHTML de mesure des temps. |
*/ |
function afficherChrono($indentation_origine = 8, $indentation = 4) { |
// Création du chrono de fin |
$GLOBALS['_SCRIPT_']['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; |
} |
} |
?> |
/trunk/framework/Config.php |
---|
New file |
0,0 → 1,121 |
<?php |
/** |
* Config permet de charger automatiquement les fichiers ini du Framework et de l'application. |
* Elle offre l'accès en lecture seule aux paramêtres de config. |
* C'est une Singleton. |
* |
* PHP Version 5 |
* |
* @category PHP |
* @package Framework |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license GPL-v3 et CECILL-v2 |
* @version SVN: <svn_id> |
* @link /doc/framework/ |
*/ |
class Config { |
private static $instance = null; |
private static $parametres = array(); |
private function __construct() { |
self::$parametres = array( |
'fw_fichier_config' => 'config.ini', |
'fw_chemin' => dirname(__FILE__).DS, |
'chemin_appli' => dirname($_SERVER['SCRIPT_FILENAME'].DS), |
); |
self::parserFichierIni(self::$parametres['fw_chemin'].self::$parametres['fw_fichier_config']); |
self::parserFichierIni(self::$parametres['chemin_appli'].self::$parametres['fw_fichier_config']); |
} |
private static function parserFichierIni($fichier_ini) { |
$retour = false; |
if (file_exists($fichier_ini)) { |
$aso_ini = parse_ini_file($fichier_ini, true); |
$aso_ini = self::evaluerPhp($aso_ini); |
self::$parametres = array_merge(self::$parametres, $aso_ini); |
$retour = true; |
} |
return $retour; |
} |
public static function charger($fichier_ini) { |
self::verifierCreationInstance(); |
return self::parserFichierIni($fichier_ini); |
} |
public static function get($param) { |
$retour = ''; |
self::verifierCreationInstance(); |
if (isset(self::$parametres[$param])) { |
$retour = self::$parametres[$param]; |
} |
return $retour; |
} |
public static function getSection($section, $param = null) { |
$retour = ''; |
self::verifierCreationInstance(); |
if (isset(self::$parametres[$section])) { |
if (!is_null($param)) { |
if (isset(self::$parametres[$section][$param])) { |
$retour = self::$parametres[$section][$param]; |
} |
} else { |
$retour = self::$parametres[$section]; |
} |
} |
return $retour; |
} |
public static function existe($param) { |
$retour = false; |
self::verifierCreationInstance(); |
if (isset(self::$parametres[$param])) { |
$retour = true; |
} |
return $retour; |
} |
public static function existeSection($section, $param = null) { |
$retour = false; |
self::verifierCreationInstance(); |
if (isset(self::$parametres[$section])) { |
if (!is_null($param)) { |
if (isset(self::$parametres[$section][$param])) { |
$retour = true; |
} |
} else { |
$retour = true; |
} |
} |
return $retour; |
} |
private static function verifierCreationInstance() { |
if (empty(self::$instance)) { |
self::$instance = new Config(); |
} |
} |
private static function evaluerPhp($tableau_a_analyser) { |
if (is_array($tableau_a_analyser)) { |
foreach ($tableau_a_analyser as $cle => $valeur) { |
if (is_array($valeur)) { |
$tableau_a_analyser[$cle] = self::evaluerPhp($valeur); |
} else { |
if (preg_match('/^php:(.+)$/', $valeur, $correspondances)) { |
eval('$tableau_a_analyser["'.$cle.'"] = '.$correspondances[1].';'); |
} else { |
$tableau_a_analyser[$cle] = $valeur; |
} |
} |
} |
} |
return $tableau_a_analyser; |
} |
} |
?> |
/trunk/framework/Modele.php |
---|
New file |
0,0 → 1,123 |
<?php |
/** |
* Classe modèle, donc d'accès au données, elle ne devrait pas être appelée de l'extérieur. |
* Elle fait office d'abstraction légère de base de données en utilisant les objects PDO natifs |
* de PHP |
* Elle est abstraite donc doit obligatoirement être étendue. |
*/ |
abstract class Modele { |
/** |
* registre global |
*/ |
private $registre; |
/** |
* Gestionnaire d'exceptions php |
*/ |
private $gestionnaire_exception; |
/** |
* Gestionnaire d'erreurs php |
*/ |
private $gestionnaire_erreur; |
/** |
* DSN pour accéder à la base de données |
*/ |
private $dsn; |
/** |
* Type de base de données (mysql, mysqli, etc ...) |
*/ |
private $type; |
/** |
* Hote herbergeant la base de données |
*/ |
private $hote; |
/** |
* Nom de la base de données à laquelle le modèle doit se connecter |
*/ |
private $bdd_nom; |
/** |
* Nom d'utilisateur |
*/ |
private $utilisateur; |
/** |
* Mot de passe |
*/ |
private $pass; |
/** |
* Connexion à la base de données |
*/ |
private $connexion = null; |
/** |
* Constructeur par défaut, appelé à l'initialisation |
*/ |
final public function __construct() { |
// les différents paramètres nécessaires sont lus à partir du registre |
$this->registre = Registre::getInstance(); |
$this->gestionnaire_erreur = GestionnaireErreur::getInstance(); |
$this->type = Config::get('bdd_protocole'); |
$this->hote = Config::get('bdd_serveur'); |
$this->bdd_nom = Config::get('bdd_nom'); |
$this->utilisateur = Config::get('bdd_utilisateur'); |
$this->pass = Config::get('bdd_mot_de_passe'); |
$this->dsn = $this->type.':dbname='.$this->bdd_nom.';host='.$this->hote; |
echo $this->dsn; |
} |
/** |
* Fonction qui appelle la bonne fonction de requete suivant le type de bdd |
* @param string la requete à effectuer |
* @return PDOStatement un objet contenant le résultat de la requête |
*/ |
final protected function requete($requete) { |
// on ne se connecte que lors du premier appel à une requete (lazy connexion) |
if($this->connexion == null) { |
$this->connecter(); |
} |
return $this->connexion->query($requete); |
} |
/** |
* Connecte à la base de données en utilisant les informations fournies par |
* le fichier de configuration, private et final car n'a pas vocation a être appelée |
* par l'utilisateur |
* @throws PDOException une exception dans le cas ou là connexion échoue |
*/ |
final private function connecter() { |
// TODO: retirer le try catch et laisser le problème au gestionnaire d'exceptions |
try { |
$this->connexion = new PDO($this->dsn, $this->utilisateur, $this->pass); |
} catch (PDOException $e) { |
} |
} |
/** |
* protège une chaine de caractères avant l'insertion dans la base de données |
*/ |
final protected function proteger($chaine) { |
// on ne se connecte que lors du premier appel à une requete |
if($this->connexion == null) { |
$this->connecter(); |
} |
return $this->connexion->quote($chaine); |
} |
/** |
* Destructeur de classe, se contente de fermer explicitement la connexion |
*/ |
final public function __destruct() { |
if($this->connexion != null) { |
$this->connexion = null ; |
} |
} |
} |
?> |
Property changes: |
Added: svn:keywords |
+Id Author Date Revision HeadURL |
\ No newline at end of property |
/trunk/framework/GestionnaireException.php |
---|
New file |
0,0 → 1,122 |
<?php |
/* |
* Created on 27 mars 2009 |
* |
* To change the template for this generated file go to |
* Window - Preferences - PHPeclipse - PHP - Code Templates |
*/ |
/** |
* Classe GestionnaireException, gère les exceptions |
*/ |
class GestionnaireException { |
/** |
* Liste des exceptions enregistrées |
*/ |
private $exceptions; |
/** |
* Détermine si l'on affiche ou nom le contexte |
*/ |
private $contexte; |
/** |
* Definit si php est lancé en ligne de commande ou en mode serveur |
*/ |
private $mode; |
/** |
* le gestionnaire d'exception est un singleton |
* et possède donc un "pointeur statique sur lui-même" |
*/ |
private static $gestionnaireException ; |
/** |
* Constructeur avec paramètres optionnel |
* @param bool indique si l'on veut afficher ou non le contexte des exceptions (i.e. la trace) |
*/ |
public function __construct($contexte = false) { |
$this->exceptions = array(); |
$this->contexte = $contexte; |
$this->mode = php_sapi_name(); |
set_exception_handler(array($this,'gererException')); |
} |
/** |
* Renvoie le booleen définissant si l'on affiche le contexte ou non |
*/ |
public function getContexte() { |
return $this->contexte; |
} |
/** |
* Definit si l'on veut afficher le contexte ou non |
* @param bool true si on veut afficher le contexte, false sinon, par défaut vaut false |
*/ |
public function setContexte($contexte) { |
$this->contexte = $contexte; |
} |
/** Fonction d'accès au singleton |
* @return GestionnaireErreur le gestionnaire d'exceptions courant |
*/ |
public static function getInstance() |
{ |
if (self::$gestionnaireException instanceof GestionnaireException) { |
return self::$gestionnaireException; |
} |
self::$gestionnaireException = new GestionnaireException; |
return self::$gestionnaireException; |
} |
/** |
* Fonction de gestion des exceptions, remplace le handler par défaut |
*/ |
public static function gererException(Exception $e) { |
// pour le moment on se contente de l'ajouter au tableau |
$this->exceptions[] = $e; |
} |
/** |
* Renvoie les exceptions au format (X)HTML |
* ou bien au format texte suivant le mode d'utilisation de PHP |
*/ |
public function getExceptions() { |
foreach ($this->exceptions as $e) { |
switch($this->mode) { |
case 'cli' : |
$retour .= '<pre class="debogage">'."\n"; |
$retour .= htmlentities($e->getMessage())."\n"; |
$retour .= '<span class="debogage_fichier">'.'Fichier : '.$e->getFile().'</span>'."\n"; |
$retour .= '<span class="debogage_ligne">'.'Ligne : '.$e->getLine().'</span>'."\n"; |
$retour .= '</pre>'."\n"; |
if ($this->getContexte()) { |
$retour .= '<pre>'."\n"; |
$retour .= '<strong>Contexte : </strong>'."\n".print_r($e->getTraceAsString(), true)."\n"; |
$retour .= '</pre>'."\n"; |
} |
break; |
default: |
$retour .= $e->getMessage()."\n"; |
$retour .= 'Fichier : '.$e->getFile()."\n"; |
$retour .= 'Ligne : '.$e->getLine()."\n"; |
$retour .= 'Message : '.$e->getMessage()."\n"; |
$retour .= 'Fichier : '.$e->getFile()."\n"; |
$retour .= 'Ligne : '.$e->getLine()."\n"; |
if ($this->getContexte()) { |
$retour .= 'Contexte : '."\n".print_r($e->getTraceAsString(), true)."\n"; |
} |
} |
} |
return $retour; |
} |
} |
?> |
Property changes: |
Added: svn:keywords |
+Id Author Date Revision HeadURL |
\ No newline at end of property |
/trunk/framework/Net_URL.php |
---|
New file |
0,0 → 1,490 |
<?php |
// +-----------------------------------------------------------------------+ |
// | Copyright (c) 2002-2004, Richard Heyes | |
// | All rights reserved. | |
// | | |
// | Redistribution and use in source and binary forms, with or without | |
// | modification, are permitted provided that the following conditions | |
// | are met: | |
// | | |
// | o Redistributions of source code must retain the above copyright | |
// | notice, this list of conditions and the following disclaimer. | |
// | o Redistributions in binary form must reproduce the above copyright | |
// | notice, this list of conditions and the following disclaimer in the | |
// | documentation and/or other materials provided with the distribution.| |
// | o The names of the authors may not be used to endorse or promote | |
// | products derived from this software without specific prior written | |
// | permission. | |
// | | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
// | | |
// +-----------------------------------------------------------------------+ |
// | Author: Richard Heyes <richard at php net> | |
// +-----------------------------------------------------------------------+ |
// |
// $Id$ |
// |
// Net_URL Class |
class Net_URL |
{ |
var $options = array('encode_query_keys' => false); |
/** |
* Full url |
* @var string |
*/ |
var $url; |
/** |
* Protocol |
* @var string |
*/ |
var $protocol; |
/** |
* Username |
* @var string |
*/ |
var $username; |
/** |
* Password |
* @var string |
*/ |
var $password; |
/** |
* Host |
* @var string |
*/ |
var $host; |
/** |
* Port |
* @var integer |
*/ |
var $port; |
/** |
* Path |
* @var string |
*/ |
var $path; |
/** |
* Query string |
* @var array |
*/ |
var $querystring; |
/** |
* Anchor |
* @var string |
*/ |
var $anchor; |
/** |
* Whether to use [] |
* @var bool |
*/ |
var $useBrackets; |
/** |
* PHP4 Constructor |
* |
* @see __construct() |
*/ |
function Net_URL($url = null, $useBrackets = true) |
{ |
$this->__construct($url, $useBrackets); |
} |
/** |
* PHP5 Constructor |
* |
* Parses the given url and stores the various parts |
* Defaults are used in certain cases |
* |
* @param string $url Optional URL |
* @param bool $useBrackets Whether to use square brackets when |
* multiple querystrings with the same name |
* exist |
*/ |
function __construct($url = null, $useBrackets = true) |
{ |
$this->url = $url; |
$this->useBrackets = $useBrackets; |
$this->initialize(); |
} |
function initialize() |
{ |
$HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
$this->user = ''; |
$this->pass = ''; |
$this->host = ''; |
$this->port = 80; |
$this->path = ''; |
$this->querystring = array(); |
$this->anchor = ''; |
// Only use defaults if not an absolute URL given |
if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) { |
$this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'); |
/** |
* Figure out host/port |
*/ |
if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) && |
preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) |
{ |
$host = $matches[1]; |
if (!empty($matches[3])) { |
$port = $matches[3]; |
} else { |
$port = $this->getStandardPort($this->protocol); |
} |
} |
$this->user = ''; |
$this->pass = ''; |
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost'); |
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol)); |
$this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/'; |
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null; |
$this->anchor = ''; |
} |
// Parse the url and store the various parts |
if (!empty($this->url)) { |
$urlinfo = parse_url($this->url); |
// Default querystring |
$this->querystring = array(); |
foreach ($urlinfo as $key => $value) { |
switch ($key) { |
case 'scheme': |
$this->protocol = $value; |
$this->port = $this->getStandardPort($value); |
break; |
case 'user': |
case 'pass': |
case 'host': |
case 'port': |
$this->$key = $value; |
break; |
case 'path': |
if ($value{0} == '/') { |
$this->path = $value; |
} else { |
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path); |
$this->path = sprintf('%s/%s', $path, $value); |
} |
break; |
case 'query': |
$this->querystring = $this->_parseRawQueryString($value); |
break; |
case 'fragment': |
$this->anchor = $value; |
break; |
} |
} |
} |
} |
/** |
* Returns full url |
* |
* @return string Full url |
* @access public |
*/ |
function getURL() |
{ |
$querystring = $this->getQueryString(); |
$this->url = $this->protocol . '://' |
. $this->user . (!empty($this->pass) ? ':' : '') |
. $this->pass . (!empty($this->user) ? '@' : '') |
. $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port) |
. $this->path |
. (!empty($querystring) ? '?' . $querystring : '') |
. (!empty($this->anchor) ? '#' . $this->anchor : ''); |
return $this->url; |
} |
/** |
* Adds or updates a querystring item (URL parameter). |
* Automatically encodes parameters with rawurlencode() if $preencoded |
* is false. |
* You can pass an array to $value, it gets mapped via [] in the URL if |
* $this->useBrackets is activated. |
* |
* @param string $name Name of item |
* @param string $value Value of item |
* @param bool $preencoded Whether value is urlencoded or not, default = not |
* @access public |
*/ |
function addQueryString($name, $value, $preencoded = false) |
{ |
if ($this->getOption('encode_query_keys')) { |
$name = rawurlencode($name); |
} |
if ($preencoded) { |
$this->querystring[$name] = $value; |
} else { |
$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value); |
} |
} |
/** |
* Removes a querystring item |
* |
* @param string $name Name of item |
* @access public |
*/ |
function removeQueryString($name) |
{ |
if ($this->getOption('encode_query_keys')) { |
$name = rawurlencode($name); |
} |
if (isset($this->querystring[$name])) { |
unset($this->querystring[$name]); |
} |
} |
/** |
* Sets the querystring to literally what you supply |
* |
* @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc |
* @access public |
*/ |
function addRawQueryString($querystring) |
{ |
$this->querystring = $this->_parseRawQueryString($querystring); |
} |
/** |
* Returns flat querystring |
* |
* @return string Querystring |
* @access public |
*/ |
function getQueryString() |
{ |
if (!empty($this->querystring)) { |
foreach ($this->querystring as $name => $value) { |
// Encode var name |
$name = rawurlencode($name); |
if (is_array($value)) { |
foreach ($value as $k => $v) { |
$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v); |
} |
} elseif (!is_null($value)) { |
$querystring[] = $name . '=' . $value; |
} else { |
$querystring[] = $name; |
} |
} |
$querystring = implode(ini_get('arg_separator.output'), $querystring); |
} else { |
$querystring = ''; |
} |
return $querystring; |
} |
/** |
* Parses raw querystring and returns an array of it |
* |
* @param string $querystring The querystring to parse |
* @return array An array of the querystring data |
* @access private |
*/ |
function _parseRawQuerystring($querystring) |
{ |
$parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); |
$return = array(); |
foreach ($parts as $part) { |
if (strpos($part, '=') !== false) { |
$value = substr($part, strpos($part, '=') + 1); |
$key = substr($part, 0, strpos($part, '=')); |
} else { |
$value = null; |
$key = $part; |
} |
if (!$this->getOption('encode_query_keys')) { |
$key = rawurldecode($key); |
} |
if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { |
$key = $matches[1]; |
$idx = $matches[2]; |
// Ensure is an array |
if (empty($return[$key]) || !is_array($return[$key])) { |
$return[$key] = array(); |
} |
// Add data |
if ($idx === '') { |
$return[$key][] = $value; |
} else { |
$return[$key][$idx] = $value; |
} |
} elseif (!$this->useBrackets AND !empty($return[$key])) { |
$return[$key] = (array)$return[$key]; |
$return[$key][] = $value; |
} else { |
$return[$key] = $value; |
} |
} |
return $return; |
} |
/** |
* Resolves //, ../ and ./ from a path and returns |
* the result. Eg: |
* |
* /foo/bar/../boo.php => /foo/boo.php |
* /foo/bar/../../boo.php => /boo.php |
* /foo/bar/.././/boo.php => /foo/boo.php |
* |
* This method can also be called statically. |
* |
* @param string $path URL path to resolve |
* @return string The result |
*/ |
function resolvePath($path) |
{ |
$path = explode('/', str_replace('//', '/', $path)); |
for ($i=0; $i<count($path); $i++) { |
if ($path[$i] == '.') { |
unset($path[$i]); |
$path = array_values($path); |
$i--; |
} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) { |
unset($path[$i]); |
unset($path[$i-1]); |
$path = array_values($path); |
$i -= 2; |
} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') { |
unset($path[$i]); |
$path = array_values($path); |
$i--; |
} else { |
continue; |
} |
} |
return implode('/', $path); |
} |
/** |
* Returns the standard port number for a protocol |
* |
* @param string $scheme The protocol to lookup |
* @return integer Port number or NULL if no scheme matches |
* |
* @author Philippe Jausions <Philippe.Jausions@11abacus.com> |
*/ |
function getStandardPort($scheme) |
{ |
switch (strtolower($scheme)) { |
case 'http': return 80; |
case 'https': return 443; |
case 'ftp': return 21; |
case 'imap': return 143; |
case 'imaps': return 993; |
case 'pop3': return 110; |
case 'pop3s': return 995; |
default: return null; |
} |
} |
/** |
* Forces the URL to a particular protocol |
* |
* @param string $protocol Protocol to force the URL to |
* @param integer $port Optional port (standard port is used by default) |
*/ |
function setProtocol($protocol, $port = null) |
{ |
$this->protocol = $protocol; |
$this->port = is_null($port) ? $this->getStandardPort($protocol) : $port; |
} |
/** |
* Set an option |
* |
* This function set an option |
* to be used thorough the script. |
* |
* @access public |
* @param string $optionName The optionname to set |
* @param string $value The value of this option. |
*/ |
function setOption($optionName, $value) |
{ |
if (!array_key_exists($optionName, $this->options)) { |
return false; |
} |
$this->options[$optionName] = $value; |
$this->initialize(); |
} |
/** |
* Get an option |
* |
* This function gets an option |
* from the $this->options array |
* and return it's value. |
* |
* @access public |
* @param string $opionName The name of the option to retrieve |
* @see $this->options |
*/ |
function getOption($optionName) |
{ |
if (!isset($this->options[$optionName])) { |
return false; |
} |
return $this->options[$optionName]; |
} |
function __toString() { |
return $this->url ; |
} |
} |
?> |
Property changes: |
Added: svn:keywords |
+Id Author Date Revision HeadURL |
\ No newline at end of property |
/trunk/framework/Net_URL2.php |
---|
New file |
0,0 → 1,817 |
<?php |
// +-----------------------------------------------------------------------+ |
// | Copyright (c) 2007-2008, Christian Schmidt, Peytz & Co. A/S | |
// | All rights reserved. | |
// | | |
// | Redistribution and use in source and binary forms, with or without | |
// | modification, are permitted provided that the following conditions | |
// | are met: | |
// | | |
// | o Redistributions of source code must retain the above copyright | |
// | notice, this list of conditions and the following disclaimer. | |
// | o Redistributions in binary form must reproduce the above copyright | |
// | notice, this list of conditions and the following disclaimer in the | |
// | documentation and/or other materials provided with the distribution.| |
// | o The names of the authors may not be used to endorse or promote | |
// | products derived from this software without specific prior written | |
// | permission. | |
// | | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
// | | |
// +-----------------------------------------------------------------------+ |
// | Author: Christian Schmidt <schmidt at php dot net> | |
// +-----------------------------------------------------------------------+ |
// |
// $Id$ |
// |
// Net_URL2 Class (PHP5 Only) |
// This code is released under the BSD License - http://www.opensource.org/licenses/bsd-license.php |
/** |
* @license BSD License |
*/ |
class Net_URL2 |
{ |
/** |
* Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default |
* is true. |
*/ |
const OPTION_STRICT = 'strict'; |
/** |
* Represent arrays in query using PHP's [] notation. Default is true. |
*/ |
const OPTION_USE_BRACKETS = 'use_brackets'; |
/** |
* URL-encode query variable keys. Default is true. |
*/ |
const OPTION_ENCODE_KEYS = 'encode_keys'; |
/** |
* Query variable separators when parsing the query string. Every character |
* is considered a separator. Default is specified by the |
* arg_separator.input php.ini setting (this defaults to "&"). |
*/ |
const OPTION_SEPARATOR_INPUT = 'input_separator'; |
/** |
* Query variable separator used when generating the query string. Default |
* is specified by the arg_separator.output php.ini setting (this defaults |
* to "&"). |
*/ |
const OPTION_SEPARATOR_OUTPUT = 'output_separator'; |
/** |
* Default options corresponds to how PHP handles $_GET. |
*/ |
private $options = array( |
self::OPTION_STRICT => true, |
self::OPTION_USE_BRACKETS => true, |
self::OPTION_ENCODE_KEYS => true, |
self::OPTION_SEPARATOR_INPUT => 'x&', |
self::OPTION_SEPARATOR_OUTPUT => 'x&', |
); |
/** |
* @var string|bool |
*/ |
private $scheme = false; |
/** |
* @var string|bool |
*/ |
private $userinfo = false; |
/** |
* @var string|bool |
*/ |
private $host = false; |
/** |
* @var int|bool |
*/ |
private $port = false; |
/** |
* @var string |
*/ |
private $path = ''; |
/** |
* @var string|bool |
*/ |
private $query = false; |
/** |
* @var string|bool |
*/ |
private $fragment = false; |
/** |
* @param string $url an absolute or relative URL |
* @param array $options |
*/ |
public function __construct($url, $options = null) |
{ |
$this->setOption(self::OPTION_SEPARATOR_INPUT, |
ini_get('arg_separator.input')); |
$this->setOption(self::OPTION_SEPARATOR_OUTPUT, |
ini_get('arg_separator.output')); |
if (is_array($options)) { |
foreach ($options as $optionName => $value) { |
$this->setOption($optionName); |
} |
} |
if (preg_match('@^([a-z][a-z0-9.+-]*):@i', $url, $reg)) { |
$this->scheme = $reg[1]; |
$url = substr($url, strlen($reg[0])); |
} |
if (preg_match('@^//([^/#?]+)@', $url, $reg)) { |
$this->setAuthority($reg[1]); |
$url = substr($url, strlen($reg[0])); |
} |
$i = strcspn($url, '?#'); |
$this->path = substr($url, 0, $i); |
$url = substr($url, $i); |
if (preg_match('@^\?([^#]*)@', $url, $reg)) { |
$this->query = $reg[1]; |
$url = substr($url, strlen($reg[0])); |
} |
if ($url) { |
$this->fragment = substr($url, 1); |
} |
} |
/** |
* Returns the scheme, e.g. "http" or "urn", or false if there is no |
* scheme specified, i.e. if this is a relative URL. |
* |
* @return string|bool |
*/ |
public function getScheme() |
{ |
return $this->scheme; |
} |
/** |
* @param string|bool $scheme |
* |
* @return void |
* @see getScheme() |
*/ |
public function setScheme($scheme) |
{ |
$this->scheme = $scheme; |
} |
/** |
* Returns the user part of the userinfo part (the part preceding the first |
* ":"), or false if there is no userinfo part. |
* |
* @return string|bool |
*/ |
public function getUser() |
{ |
return $this->userinfo !== false ? preg_replace('@:.*$@', '', $this->userinfo) : false; |
} |
/** |
* Returns the password part of the userinfo part (the part after the first |
* ":"), or false if there is no userinfo part (i.e. the URL does not |
* contain "@" in front of the hostname) or the userinfo part does not |
* contain ":". |
* |
* @return string|bool |
*/ |
public function getPassword() |
{ |
return $this->userinfo !== false ? substr(strstr($this->userinfo, ':'), 1) : false; |
} |
/** |
* Returns the userinfo part, or false if there is none, i.e. if the |
* authority part does not contain "@". |
* |
* @return string|bool |
*/ |
public function getUserinfo() |
{ |
return $this->userinfo; |
} |
/** |
* Sets the userinfo part. If two arguments are passed, they are combined |
* in the userinfo part as username ":" password. |
* |
* @param string|bool $userinfo userinfo or username |
* @param string|bool $password |
* |
* @return void |
*/ |
public function setUserinfo($userinfo, $password = false) |
{ |
$this->userinfo = $userinfo; |
if ($password !== false) { |
$this->userinfo .= ':' . $password; |
} |
} |
/** |
* Returns the host part, or false if there is no authority part, e.g. |
* relative URLs. |
* |
* @return string|bool |
*/ |
public function getHost() |
{ |
return $this->host; |
} |
/** |
* @param string|bool $host |
* |
* @return void |
*/ |
public function setHost($host) |
{ |
$this->host = $host; |
} |
/** |
* Returns the port number, or false if there is no port number specified, |
* i.e. if the default port is to be used. |
* |
* @return int|bool |
*/ |
public function getPort() |
{ |
return $this->port; |
} |
/** |
* @param int|bool $port |
* |
* @return void |
*/ |
public function setPort($port) |
{ |
$this->port = intval($port); |
} |
/** |
* Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or |
* false if there is no authority none. |
* |
* @return string|bool |
*/ |
public function getAuthority() |
{ |
if (!$this->host) { |
return false; |
} |
$authority = ''; |
if ($this->userinfo !== false) { |
$authority .= $this->userinfo . '@'; |
} |
$authority .= $this->host; |
if ($this->port !== false) { |
$authority .= ':' . $this->port; |
} |
return $authority; |
} |
/** |
* @param string|false $authority |
* |
* @return void |
*/ |
public function setAuthority($authority) |
{ |
$this->user = false; |
$this->pass = false; |
$this->host = false; |
$this->port = false; |
if (preg_match('@^(([^\@]+)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) { |
if ($reg[1]) { |
$this->userinfo = $reg[2]; |
} |
$this->host = $reg[3]; |
if (isset($reg[5])) { |
$this->port = intval($reg[5]); |
} |
} |
} |
/** |
* Returns the path part (possibly an empty string). |
* |
* @return string |
*/ |
public function getPath() |
{ |
return $this->path; |
} |
/** |
* @param string $path |
* |
* @return void |
*/ |
public function setPath($path) |
{ |
$this->path = $path; |
} |
/** |
* Returns the query string (excluding the leading "?"), or false if "?" |
* isn't present in the URL. |
* |
* @return string|bool |
* @see self::getQueryVariables() |
*/ |
public function getQuery() |
{ |
return $this->query; |
} |
/** |
* @param string|bool $query |
* |
* @return void |
* @see self::setQueryVariables() |
*/ |
public function setQuery($query) |
{ |
$this->query = $query; |
} |
/** |
* Returns the fragment name, or false if "#" isn't present in the URL. |
* |
* @return string|bool |
*/ |
public function getFragment() |
{ |
return $this->fragment; |
} |
/** |
* @param string|bool $fragment |
* |
* @return void |
*/ |
public function setFragment($fragment) |
{ |
$this->fragment = $fragment; |
} |
/** |
* Returns the query string like an array as the variables would appear in |
* $_GET in a PHP script. |
* |
* @return array |
*/ |
public function getQueryVariables() |
{ |
$pattern = '/[' . |
preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') . |
']/'; |
$parts = preg_split($pattern, $this->query, -1, PREG_SPLIT_NO_EMPTY); |
$return = array(); |
foreach ($parts as $part) { |
if (strpos($part, '=') !== false) { |
list($key, $value) = explode('=', $part, 2); |
} else { |
$key = $part; |
$value = null; |
} |
if ($this->getOption(self::OPTION_ENCODE_KEYS)) { |
$key = rawurldecode($key); |
} |
$value = rawurldecode($value); |
if ($this->getOption(self::OPTION_USE_BRACKETS) && |
preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { |
$key = $matches[1]; |
$idx = $matches[2]; |
// Ensure is an array |
if (empty($return[$key]) || !is_array($return[$key])) { |
$return[$key] = array(); |
} |
// Add data |
if ($idx === '') { |
$return[$key][] = $value; |
} else { |
$return[$key][$idx] = $value; |
} |
} elseif (!$this->getOption(self::OPTION_USE_BRACKETS) |
&& !empty($return[$key]) |
) { |
$return[$key] = (array) $return[$key]; |
$return[$key][] = $value; |
} else { |
$return[$key] = $value; |
} |
} |
return $return; |
} |
/** |
* @param array $array (name => value) array |
* |
* @return void |
*/ |
public function setQueryVariables(array $array) |
{ |
if (!$array) { |
$this->query = false; |
} else { |
foreach ($array as $name => $value) { |
if ($this->getOption(self::OPTION_ENCODE_KEYS)) { |
$name = rawurlencode($name); |
} |
if (is_array($value)) { |
foreach ($value as $k => $v) { |
$parts[] = $this->getOption(self::OPTION_USE_BRACKETS) |
? sprintf('%s[%s]=%s', $name, $k, $v) |
: ($name . '=' . $v); |
} |
} elseif (!is_null($value)) { |
$parts[] = $name . '=' . $value; |
} else { |
$parts[] = $name; |
} |
} |
$this->query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT), |
$parts); |
} |
} |
/** |
* @param string $name |
* @param mixed $value |
* |
* @return array |
*/ |
public function setQueryVariable($name, $value) |
{ |
$array = $this->getQueryVariables(); |
$array[$name] = $value; |
$this->setQueryVariables($array); |
} |
/** |
* @param string $name |
* |
* @return void |
*/ |
public function unsetQueryVariable($name) |
{ |
$array = $this->getQueryVariables(); |
unset($array[$name]); |
$this->setQueryVariables($array); |
} |
/** |
* Returns a string representation of this URL. |
* |
* @return string |
*/ |
public function getURL() |
{ |
// See RFC 3986, section 5.3 |
$url = ""; |
if ($this->scheme !== false) { |
$url .= $this->scheme . ':'; |
} |
$authority = $this->getAuthority(); |
if ($authority !== false) { |
$url .= '//' . $authority; |
} |
$url .= $this->path; |
if ($this->query !== false) { |
$url .= '?' . $this->query; |
} |
if ($this->fragment !== false) { |
$url .= '#' . $this->fragment; |
} |
return $url; |
} |
/** |
* Returns a normalized string representation of this URL. This is useful |
* for comparison of URLs. |
* |
* @return string |
*/ |
public function getNormalizedURL() |
{ |
$url = clone $this; |
$url->normalize(); |
return $url->getUrl(); |
} |
/** |
* Returns a normalized Net_URL2 instance. |
* |
* @return Net_URL2 |
*/ |
public function normalize() |
{ |
// See RFC 3886, section 6 |
// Schemes are case-insensitive |
if ($this->scheme) { |
$this->scheme = strtolower($this->scheme); |
} |
// Hostnames are case-insensitive |
if ($this->host) { |
$this->host = strtolower($this->host); |
} |
// Remove default port number for known schemes (RFC 3986, section 6.2.3) |
if ($this->port && |
$this->scheme && |
$this->port == getservbyname($this->scheme, 'tcp')) { |
$this->port = false; |
} |
// Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1) |
foreach (array('userinfo', 'host', 'path') as $part) { |
if ($this->$part) { |
$this->$part = preg_replace('/%[0-9a-f]{2}/ie', 'strtoupper("\0")', $this->$part); |
} |
} |
// Path segment normalization (RFC 3986, section 6.2.2.3) |
$this->path = self::removeDotSegments($this->path); |
// Scheme based normalization (RFC 3986, section 6.2.3) |
if ($this->host && !$this->path) { |
$this->path = '/'; |
} |
} |
/** |
* Returns whether this instance represents an absolute URL. |
* |
* @return bool |
*/ |
public function isAbsolute() |
{ |
return (bool) $this->scheme; |
} |
/** |
* Returns an Net_URL2 instance representing an absolute URL relative to |
* this URL. |
* |
* @param Net_URL2|string $reference relative URL |
* |
* @return Net_URL2 |
*/ |
public function resolve($reference) |
{ |
if (is_string($reference)) { |
$reference = new self($reference); |
} |
if (!$this->isAbsolute()) { |
throw new Exception('Base-URL must be absolute'); |
} |
// A non-strict parser may ignore a scheme in the reference if it is |
// identical to the base URI's scheme. |
if (!$this->getOption(self::OPTION_STRICT) && $reference->scheme == $this->scheme) { |
$reference->scheme = false; |
} |
$target = new self(''); |
if ($reference->scheme !== false) { |
$target->scheme = $reference->scheme; |
$target->setAuthority($reference->getAuthority()); |
$target->path = self::removeDotSegments($reference->path); |
$target->query = $reference->query; |
} else { |
$authority = $reference->getAuthority(); |
if ($authority !== false) { |
$target->setAuthority($authority); |
$target->path = self::removeDotSegments($reference->path); |
$target->query = $reference->query; |
} else { |
if ($reference->path == '') { |
$target->path = $this->path; |
if ($reference->query !== false) { |
$target->query = $reference->query; |
} else { |
$target->query = $this->query; |
} |
} else { |
if (substr($reference->path, 0, 1) == '/') { |
$target->path = self::removeDotSegments($reference->path); |
} else { |
// Merge paths (RFC 3986, section 5.2.3) |
if ($this->host !== false && $this->path == '') { |
$target->path = '/' . $this->path; |
} else { |
$i = strrpos($this->path, '/'); |
if ($i !== false) { |
$target->path = substr($this->path, 0, $i + 1); |
} |
$target->path .= $reference->path; |
} |
$target->path = self::removeDotSegments($target->path); |
} |
$target->query = $reference->query; |
} |
$target->setAuthority($this->getAuthority()); |
} |
$target->scheme = $this->scheme; |
} |
$target->fragment = $reference->fragment; |
return $target; |
} |
/** |
* Removes dots as described in RFC 3986, section 5.2.4, e.g. |
* "/foo/../bar/baz" => "/bar/baz" |
* |
* @param string $path a path |
* |
* @return string a path |
*/ |
private static function removeDotSegments($path) |
{ |
$output = ''; |
// Make sure not to be trapped in an infinite loop due to a bug in this |
// method |
$j = 0; |
while ($path && $j++ < 100) { |
// Step A |
if (substr($path, 0, 2) == './') { |
$path = substr($path, 2); |
} elseif (substr($path, 0, 3) == '../') { |
$path = substr($path, 3); |
// Step B |
} elseif (substr($path, 0, 3) == '/./' || $path == '/.') { |
$path = '/' . substr($path, 3); |
// Step C |
} elseif (substr($path, 0, 4) == '/../' || $path == '/..') { |
$path = '/' . substr($path, 4); |
$i = strrpos($output, '/'); |
$output = $i === false ? '' : substr($output, 0, $i); |
// Step D |
} elseif ($path == '.' || $path == '..') { |
$path = ''; |
// Step E |
} else { |
$i = strpos($path, '/'); |
if ($i === 0) { |
$i = strpos($path, '/', 1); |
} |
if ($i === false) { |
$i = strlen($path); |
} |
$output .= substr($path, 0, $i); |
$path = substr($path, $i); |
} |
} |
return $output; |
} |
/** |
* Returns a Net_URL2 instance representing the canonical URL of the |
* currently executing PHP script. |
* |
* @return string |
*/ |
public static function getCanonical() |
{ |
if (!isset($_SERVER['REQUEST_METHOD'])) { |
// ALERT - no current URL |
throw new Exception('Script was not called through a webserver'); |
} |
// Begin with a relative URL |
$url = new self($_SERVER['PHP_SELF']); |
$url->scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http'; |
$url->host = $_SERVER['SERVER_NAME']; |
$port = intval($_SERVER['SERVER_PORT']); |
if ($url->scheme == 'http' && $port != 80 || |
$url->scheme == 'https' && $port != 443) { |
$url->port = $port; |
} |
return $url; |
} |
/** |
* Returns the URL used to retrieve the current request. |
* |
* @return string |
*/ |
public static function getRequestedURL() |
{ |
return self::getRequested()->getUrl(); |
} |
/** |
* Returns a Net_URL2 instance representing the URL used to retrieve the |
* current request. |
* |
* @return Net_URL2 |
*/ |
public static function getRequested() |
{ |
if (!isset($_SERVER['REQUEST_METHOD'])) { |
// ALERT - no current URL |
throw new Exception('Script was not called through a webserver'); |
} |
// Begin with a relative URL |
$url = new self($_SERVER['REQUEST_URI']); |
$url->scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http'; |
// Set host and possibly port |
$url->setAuthority($_SERVER['HTTP_HOST']); |
return $url; |
} |
/** |
* Sets the specified option. |
* |
* @param string $optionName a self::OPTION_ constant |
* @param mixed $value option value |
* |
* @return void |
* @see self::OPTION_STRICT |
* @see self::OPTION_USE_BRACKETS |
* @see self::OPTION_ENCODE_KEYS |
*/ |
function setOption($optionName, $value) |
{ |
if (!array_key_exists($optionName, $this->options)) { |
return false; |
} |
$this->options[$optionName] = $value; |
} |
/** |
* Returns the value of the specified option. |
* |
* @param string $optionName The name of the option to retrieve |
* |
* @return mixed |
*/ |
function getOption($optionName) |
{ |
return isset($this->options[$optionName]) |
? $this->options[$optionName] : false; |
} |
public function __toString() { |
return $this->getURL(); |
} |
} |
Property changes: |
Added: svn:keywords |
+Id Author Date Revision HeadURL |
\ No newline at end of property |
/trunk/framework/Controleur.php |
---|
New file |
0,0 → 1,130 |
<?php |
/** |
* Fichier contenant la classe controleur |
* |
* PHP Version 5 |
* |
* @category PHP |
* @package Framework |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/framework/ |
*/ |
/** |
* classe Controlleur, coeur d'une application, c'est normalement la seule classe d'une application |
* qui devrait être appelée de l'extérieur. |
* Elle est abstraite donc doit obligatoirement être étendue |
* |
* PHP Version 5 |
* |
* @category Class |
* @package Framework |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL |
* @version SVN: $Id$ |
* @link /doc/framework/ |
* |
*/ |
abstract class Controleur { |
/** |
* Registre global, normalement accessible partout |
*/ |
private $_registre; |
/** |
* Gestionnaire d'exceptions php |
*/ |
private $__gestionnaire_exception; |
/** |
* Gestionnaire d'erreurs php |
*/ |
private $_gestionnaire_erreur; |
/** |
* Constructeur par défaut |
*/ |
final public function __construct() { |
if (Config::existe('fw_html_errors')) { |
ini_set('html_errors', Config::get('fw_html_errors')); |
} |
$this->registre = Registre::getInstance(); |
$this->registre->set('base_chemin_modele', Config::get('dossier_modeles')); |
$this->registre->set('base_chemin_squelette', Config::get('dossier_squelettes')); |
$this->registre->set('base_chemin_controleur', Config::get('dossier_controleurs')); |
$this->registre->set('base_url_application', new Net_URL2(Config::get('url_base'))); |
$this->_gestionnaire_exception = GestionnaireException::getInstance(); |
$this->_gestionnaire_erreur = GestionnaireErreur::getInstance(); |
} |
/** |
* Charge un modele donné et le rend disponible sous la forme $this->nom_modele |
* |
* @param string $nom_modele le nom du modèle à charger |
* |
* @return boolean false si le chargement à échoué, rien sinon |
*/ |
final protected function chargerModele($nom_modele) { |
$chemin_modele = ($this->registre->get('base_chemin_modele')).$nom_modele.'.php'; |
if (!file_exists($chemin_modele)) { |
return false; |
} |
include_once $chemin_modele; |
if (!class_exists($nom_modele)) { |
return false; |
} |
$this->$nom_modele = new $nom_modele; |
} |
/** |
* Fonction prenant en paramètre le nom d'un squelette et un tableau associatif de données, |
* en extrait les variables, charge le squelette |
* et cree une variable de classe contenant les deux combinés. |
* |
* @param String $nom_squelette le nom du squelette |
* @param Array $donnees un tableau associatif contenant les variables a injecter dans la vue |
* |
* @return boolean false si la vue n'existe pas, rien sinon |
*/ |
final protected function chargerVue($nom_squelette,$donnees) { |
$chemin_squelette = ($this->registre->get('base_chemin_squelette')).$nom_squelette.'.tpl.html'; |
if (!file_exists($chemin_squelette)) { |
return false ; |
} |
$donnees['base_url'] = $this->registre->get('base_url_application'); |
// on extrait les variables du tableau de données |
extract($donnees); |
// et on enclenche la bufferisation de sortie |
ob_start(); |
// si les tags courts sont désactivés |
if ((bool) @ini_get('short_open_tag') === false) { |
// on remplace les tags par la syntaxe classique avec echo |
echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($chemin_squelette)))); |
} else { |
// sinon, on se contente d'inclure le squelette |
include $chemin_squelette; |
} |
// on récupère le buffer et on le vide |
$buffer = ob_get_contents(); |
@ob_end_clean(); |
// enfin on renvoie le contenu |
$this->$nom_squelette = $buffer; |
} |
} |
?> |
/trunk/framework/GestionnaireErreur.php |
---|
New file |
0,0 → 1,372 |
<?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$ |
/** |
* 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$ $Date$ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// +------------------------------------------------------------------------------------------------------+ |
// | 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 courant. Celui que l'on donne à la fonction |
* error_reporting(). |
* @access private |
*/ |
private $niveau_erreur_courant; |
/** |
* Le gestionnaire d'erreur est un singleton |
*/ |
private static $gestionnaire_erreurs; |
/*** Constructeur: ***/ |
/** |
* Construit le gestionnaire d'erreur. |
* |
* @return void |
* @access public |
*/ |
private function __construct( $contexte = false ) |
{ |
$this->mode = php_sapi_name(); |
$this->erreurs = array(); |
$this->setContexte($contexte); |
$this->niveau_erreur_courant = 2048 ; |
set_error_handler(array(&$this, 'gererErreur')); |
} |
/** |
* Fonction d'accès au singleton |
* @return GestionnaireErreur le gestionnaire d'erreurs courant |
*/ |
public static function getInstance() |
{ |
if (self::$gestionnaire_erreurs instanceof GestionnaireErreur) { |
return self::$gestionnaire_erreurs; |
} |
self::$gestionnaire_erreurs = new GestionnaireErreur ; |
return self::$gestionnaire_erreurs; |
} |
/*** Accesseurs: ***/ |
/** |
* 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 getNiveauErreurCourant( ) { |
return (int)$this->niveau_erreur_courant; |
} |
/** |
* Définit le niveau d'erreur courrant. |
* |
* @param int un niveau d'erreur. |
* @return void |
* @access public |
*/ |
public function setNiveauErreurCourant( $niveau = 2048 ) { |
$this->niveau_erreur_courant = $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_courant = $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->getNiveauErreurCourant() ) { |
$aso_erreur['niveau'] = $niveau; |
switch ($niveau) { |
case E_USER_NOTICE : |
if (is_array($message) || is_object($message)) { |
$aso_erreur['message'] = print_r($message, true); |
} else { |
$aso_erreur['message'] = $message; |
} |
break; |
default: |
$aso_erreur['message'] = $message; |
} |
$aso_erreur['fichier'] = $fichier; |
$aso_erreur['ligne'] = $ligne; |
if ($this->getContexte()) { |
$aso_erreur['contexte'] = $contexte; |
} |
$this->setErreur($aso_erreur); |
} |
echo print_r($this->erreurs,true) ; |
exit() ; |
// 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 = ''; |
foreach($this->getErreur() as $aso_erreur) { |
if ('<!-- BEGIN sql -->' == substr($aso_erreur['message'], 0, 18)) { |
$retour .= $aso_erreur['message']; |
continue; |
} |
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 .= htmlentities($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 .= '<strong>Contexte : </strong>'."\n".print_r($aso_erreur['contexte'], true)."\n"; |
$retour .= '</pre>'."\n"; |
} |
$retour .= '</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; |
} |
} |
?> |
Property changes: |
Added: svn:keywords |
+Id Author Date Revision HeadURL |
\ No newline at end of property |
/trunk/framework/autoload.inc.php |
---|
23,12 → 23,6 |
define('DS', DIRECTORY_SEPARATOR); |
} |
// Appel du fichier de configuration du framework |
require_once dirname(__FILE__).DS.'config.inc.php'; |
// Chargement automatique du fichier de configuration de l'application |
require_once CHEMIN_APPLI.'config.inc.php'; |
/** |
* La fonction __autoload() charge dynamiquement les |
* classes trouvées dans le code. |
41,20 → 35,24 |
*@return null le fichier contenant la classe. |
*/ |
function __autoload($classe) { |
/* les dossiers dans lequels on cherche sont ceux |
*initialisés dans les fichiers de configuration |
*TODO: faire un tableau qui soit contenu dans le |
*fichier de configuration pour que les utilisateurs |
* puissent rajouter les leur et agrandir les possibilités. |
*/ |
$dossiers_classes = array( DOSSIER_BIBLIO, |
DOSSIER_CONTROLEURS, |
DOSSIER_MODELES); |
foreach ($dossiers_classes as $chemin) { |
if (file_exists($fichier_a_tester = $chemin.$classe.'.php')) { |
include_once $fichier_a_tester; |
return null; |
if (file_exists($fichier_a_tester = dirname(__FILE__).DS.$classe.'.php')) { |
include_once $fichier_a_tester; |
return null; |
} else { |
/* les dossiers dans lequels on cherche sont ceux |
*initialisés dans les fichiers de configuration |
*TODO: faire un tableau qui soit contenu dans le |
*fichier de configuration pour que les utilisateurs |
* puissent rajouter les leur et agrandir les possibilités. |
*/ |
$dossiers_classes = array( Config::get('dossier_controleurs'), |
Config::get('fw_dossier_modeles')); |
foreach ($dossiers_classes as $chemin) { |
if (file_exists($fichier_a_tester = $chemin.$classe.'.php')) { |
include_once $fichier_a_tester; |
return null; |
} |
} |
} |
} |
/trunk/framework |
---|
Property changes: |
Added: svn:ignore |
+config.ini |
/trunk/exemple/config.inc.php |
---|
File deleted |
\ No newline at end of file |
/trunk/exemple/admin_administrateur.php |
---|
File deleted |
\ No newline at end of file |
/trunk/exemple/index.php |
---|
1,9 → 1,90 |
<?php |
/** |
* Created on 19 mars 2009 |
* |
* To change the template for this generated file go to |
* Window - Preferences - PHPeclipse - PHP - Code Templates |
**/ |
header('Location: admin_administrateur.php'); |
?> |
* @category PHP |
* @package Framework |
* @author Aurelien PERONNET <aurelien@tela-botanica.org> |
* @copyright Tela-Botanica 2009 |
* @link /doc/framework/ |
* Ceci est un exemple d'application qui permet d'illustrer le fonctionnement du framework, il montre comment |
* une application peut être dans papyrus, ou bien utilisée en stand alone. |
*/ |
// La fonction autolad doit être appelée avant tout autre chose dans l'application. |
// Sinon, rien ne sera chargé. |
require_once '../framework/autoload.inc.php'; |
/** |
* Fonction d'affichage de Papyrus, pour le corps de page |
*/ |
function afficherContenuCorps() { |
// Si l'utilisateur est authentifié |
if (!Config::get('identification')) { |
// on renvoie la vue principale de l'application |
$methode = '' ; |
if (isset($_GET['m'])) { |
$methode = $_GET['m']; |
} |
$controlleur = new AdminAdministrateur(); |
switch ($methode) { |
case 'ajout_admin': |
return $controlleur->ajoutAdmin(); |
break; |
case 'ajout_admin_va': |
$nom = $_POST['admin_nom']; |
$prenom = $_POST['admin_prenom']; |
$mail = $_POST['admin_mail']; |
$lang = $_POST['admin_lang']; |
$pass = $_POST['admin_pass']; |
$pass_conf = $_POST['admin_pass_confirm']; |
return $controlleur->ajoutAdminVa($nom, $prenom, $mail, $lang, $pass, $pass_conf); |
break; |
case 'modif_admin': |
$id = $_GET['id_admin']; |
return $controlleur->modifAdmin($id); |
break; |
case 'modif_admin_va': |
$id = $_GET['id_admin']; |
$nom = $_POST['admin_nom']; |
$prenom = $_POST['admin_prenom']; |
$mail = $_POST['admin_mail']; |
$lang = $_POST['admin_lang']; |
$pass = $_POST['admin_pass']; |
$pass_conf = $_POST['admin_pass_confirm']; |
return $controlleur->modifAdminVa($id, $nom, $prenom, $mail, $lang, $pass, $pass_conf); |
break; |
case 'suppr_admin': |
$id = $_GET['id_admin']; |
return $controlleur->supprAdmin($id); |
break; |
default: |
return $controlleur->chargerAdmin(); |
break; |
} |
} else { |
// sinon on lui demande de s'identifier |
$controlleur = new AdminAdministrateur(); |
return $controlleur->demanderIdent(); |
} |
} |
function afficherContenuTete() { |
$controlleur = new AdminAdministrateur(); |
return $controlleur->adminTete(); |
} |
function afficherContenuPied() { |
$controlleur = new AdminAdministrateur(); |
return $controlleur->adminPied(); |
} |
if(!defined('PAP_VERSION')) { |
echo afficherContenuTete(); |
echo afficherContenuCorps(); |
echo afficherContenuPied(); |
} |
/* |
* afficherContenuNavigation() |
* afficherContenuMenu() |
*/ |
?> |
/trunk/exemple/squelettes/liste_admin.tpl.html |
---|
12,15 → 12,12 |
<td><?=$element['ga_nom'] ?></td> |
<td><?=$element['ga_prenom'] ?></td> |
<td><?=$element['ga_ce_i18n'] ?></td> |
<td><a href=<?=$base_url.'?m=modif_admin&id_admin='.$element['ga_id_administrateur'] |
?>>Modifier</a></td> |
<td><a href=<?=$base_url.'?m=suppr_admin&id_admin='.$element['ga_id_administrateur'] |
?>>Supprimer</a></td> |
<td><a href="<?=$base_url.'?m=modif_admin&id_admin='.$element['ga_id_administrateur'];?>">Modifier</a></td> |
<td><a href="<?=$base_url.'?m=suppr_admin&id_admin='.$element['ga_id_administrateur'];?>">Supprimer</a></td> |
</tr> |
<?php endforeach; ?> |
</table> |
<?php if (isset($erreurs['supp'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['supp'] ?> </span> |
<span class="symbole_obligatoire"> <?=$erreurs['supp'];?> </span> |
<?php endif; ?> |
<p><a href="<?=$base_url.'?&m=ajout_admin' ?>"> Ajouter un |
administrateur </a></p> |
<p><a href="<?=$base_url.'?&m=ajout_admin';?>"> Ajouter un administrateur </a></p> |
/trunk/exemple/squelettes/ident_admin.tpl.html |
---|
1,13 → 1,11 |
<p class="zone_alert">Identifiez-vous</p> |
<form id="form_connexion" style="clear: both;" |
class="form_identification" action="<?=$base_url ?>" |
method="post"> |
<fieldset><legend>Identifiez vous</legend> <label |
for="username">Courriel : </label> <input type="text" id="username" |
name="username" maxlength="80" tabindex="1" value="courriel" /> <label |
for="password">Mot de passe : </label> <input type="password" |
id="password" name="password" maxlength="80" tabindex="2" |
value="mot de passe" /> <input type="submit" id="connexion" |
name="connexion" tabindex="3" value="ok" /></fieldset> |
<form id="form_connexion" style="clear: both;" class="form_identification" action="<?=$base_url ?>" method="post"> |
<fieldset> |
<legend>Identifiez vous</legend> |
<label for="username">Courriel :</label> |
<input type="text" id="username" name="username" maxlength="80" tabindex="1" value="courriel" /> |
<label for="password">Mot de passe : </label> |
<input type="password" id="password" name="password" maxlength="80" tabindex="2" value="mot de passe" /> |
<input type="submit" id="connexion" name="connexion" tabindex="3" value="ok" /> |
</fieldset> |
</form> |
/trunk/exemple/config.ini |
---|
New file |
0,0 → 1,4 |
; URL de base de l'application, si elle est laissée vide, l'application fonctionnera en Stand-alone |
url_base = "" |
; Mettre à true si l'application nécessite de s'identifier. |
identification = false |