Bonjour,
C'est la première fois que j'ai à travailler sur des fichiers de conf (XML). J'ai donc créer une classe qui me permet de reprendre les informations de mon fichier
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <?php
/** Manage configuration file (in XML)
* XML markups must be in their lowercase form
*/
class ConfigurationParser
{
private $path;
private $xml; // configuration file is an XML document
/** Construct the object
* @param URL
* @type {param1} String
*/
public function __construct($URL)
{
$this->path = $URL;
$this->xml = new SimpleXMLElement($this->path,LIBXML_NOENT,true);
}
/** Get an information
* @param Information
* @type {param1} String separated by DOT
* @advert Support only 2 level (e.g : XXX.YYYY)
* @return The information
* @type {return} String */
public function get($info)
{
$info = strtolower($info);
$path = explode(".",$info);
$xpath='/configuration/'.$path[0].'/'.$path[1];
$result = $this->xml->xpath($xpath);
return (string) $result[0] -> asXML();
}
}
?> |
j'ai aussi une autre classe qui gère mes utilisateurs (le moteur de mon application Web). Dans cette classe, j'utilise une connexion SQL. Cette connexion se fait à partir d'information que je reprend du fichier XML de configuration (grâce à la classe ConfigurationParser [plus précisement de sa méthode get). Mais voila, je me rend compte que cette méthode mùe renvoie du XML. En effet, lorsque je créer une instance de ma clase User, je créer en même temps une instance de PDO (pour ma connexion)
1 2 3 4
| $this -> conf = new ConfigurationParser("/configuration/global.xml");
$this->dbh = new Connexion(
$this->conf->get("DATABASE.HOST"),$this->conf->get("DATABASE.NAME"),
$this->conf->get("DATABASE.USER"),$this->conf->get("DATABASE.PASS")); |
connexion est juste une classe qui éxecute PDO avec écriture dans un fichier de log. bref, la trace de l'erreur généré par cela est
#1 C:\Documents and Settings\mrabbaa\Mes documents\workspace\skyrecon\class\org.skyrecon.skyline.User.php(25): Connexion->__construct('<host>localhost...', '<name>skyr2</na...', '<user>mrabbaa</...', '<pass>xxxx...')
comme si la méthode get de la classe ConfigurationParser me retorunait un noeud XML et non un string comme je l'ai précisé.
quelqu'un peut il éclairer ma lanterne, ceci est trop obscure pour moi.
Partager