Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 790 → Rev 791

/trunk/services/modules/0.1/Projets.php
27,6 → 27,7
private $serviceNom = array();
/** Chemin vers le dossier courrant. */
private $cheminCourrant = null;
private $classe = null;
 
private $cache;
 
61,8 → 62,10
$retour = '';
if ($this->avoirRessources()) {
if ($this->avoirRessourceProjet()) {
$this->initialiserProjet();
$this->chargerNomDuService(); // défini $this->serviceNom
$this->initialiserProjet(); // autoload defined here
if ($this->avoirRessourceService()) {
$this->classe = self::definirClasseNeeded($this->projetNom, $this->serviceNom);
$retour = $this->initialiserService();
}
}
120,11 → 123,83
Config::charger($chemin);
}
 
/*
1) jusqu'à présent:
* le principe pour URL = a/b est: de charger
* require_once($chemin/a/ucfirst(c).php)
* new ucfirst(c); ucfirst(c)->consulter()
* sachant que ucfirst(c).php et la classe ucfirst(c) apparaîssent à de multiples emplacements (selon a)
 
1") Beurk... (php-className conflicts en PHP 5.2)
 
Ici nous faisons des cas particuliers pour Ontologies, mais en suivant ce principe, sont affectés:
Cartes, EfloreOntologiesTest, Images, Informations, InformationsTaxonsSup,
LegendeCartes, NomCommune, Noms, NomsVernaculaires, Projets, Statuts,
Taxons, TaxonsCartes, Textes, ZoneGeo
 
cf:
$ grep -r '^[cC]lass '|grep -F '.php:'|egrep -w " \($(grep -rh '^[cC]lass '|awk '{print $2}'|sort|uniq -d|tr "\n" '|')\) " \
|sort -k2
 
PS: "Using two class with the same name"
http://stackoverflow.com/questions/4555186/using-two-class-with-the-same-name
> Stop.
> Whatever you are doing is wrong. Backup. Re-evaluate what you are doing and why.
*/
private static function definirClasseNeeded($p, $s) {
if($s != 'ontologies') return NULL;
 
switch($p) {
case 'baseflor':
return 'BaseFloreOntologies';
case 'eflore':
return 'EfloreOntologies';
case 'chorodep':
return 'ChorodepOntologies';
case 'baseveg':
return 'BasevegOntologies';
case 'moissonnage':
return 'MoissonnnageOntologies';
case 'commun':
return 'Ontologies';
}
return NULL;
}
 
private function chargerClasseProjet($classe) {
if (class_exists($classe)) {
return null;
}
 
if($this->serviceNom == 'ontologies') {
$c = NULL;
switch($this->projetNom) {
case 'baseflor':
$c = 'BaseFloreOntologies';
break;
case 'eflore':
$c = 'EfloreOntologies';
break;
case 'chorodep':
$c = 'ChorodepOntologies';
break;
case 'baseveg':
$c = 'BasevegOntologies';
break;
case 'moissonnage':
$c = 'MoissonnnageOntologies';
break;
case 'commun':
$c = 'Ontologies';
break;
}
if($c) {
require_once($this->cheminCourrant . 'commun' . DS . 'Commun.php');
require_once($this->cheminCourrant . $this->projetNom . DS . $this->obtenirNomClasseService($this->serviceNom) . '.php');
return;
}
}
 
$cheminBiblio = Config::get('chemin_bibliotheque');
$chemins = array();
$chemins[] = $this->cheminCourrant.$this->projetNom.DS;
164,13 → 239,17
}
 
private function initialiserService() {
$this->chargerNomDuService();
if($this->classe) {
$classe = $this->classe;
$service = new $classe($this->getBdd());
return $service->consulter($ressourcesPourService, $this->parametres);
}
 
$classe = $this->obtenirNomClasseService($this->serviceNom);
$chemins = array();
$chemins[] = $this->cheminCourrant.$this->projetNom.DS.$classe.'.php';
$chemins[] = $this->cheminCourrant.'commun'.DS.$classe.'.php';
 
$retour = '';
$service = null;
foreach ($chemins as $chemin) {
if (file_exists($chemin)) {
177,7 → 256,7
$service = new $classe($this->getBdd());
$ressourcesPourService = $this->filtrerRessourcesPourService();
$this->cache = new CacheEflore($service, $this->projetNom, $this->serviceNom, Config::get('cache'));
$retour = $this->cache->consulter($ressourcesPourService, $this->parametres);
return $this->cache->consulter($ressourcesPourService, $this->parametres);
}
}
if (is_null($service)) {
185,7 → 264,7
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
return $retour;
return NULL;
}
 
private function chargerNomDuService() {
193,8 → 272,7
}
 
private function obtenirNomClasseService($mot) {
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
return $classeNom;
return str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
}
 
private function filtrerRessourcesPourService() {