/trunk/services/bibliotheque/generique/NomsListeGenerique.php |
---|
File deleted |
\ No newline at end of file |
/trunk/services/bibliotheque/generique/TaxonsListeGenerique.php |
---|
File deleted |
\ No newline at end of file |
/trunk/services/bibliotheque/generique/NomDetailsGenerique.php |
---|
File deleted |
\ No newline at end of file |
/trunk/services/bibliotheque/Conteneur.php |
---|
67,24 → 67,6 |
return $this->partages['RessourcesVerificateur']; |
} |
public function getBdd() { |
if (!isset($this->partages['Bdd'])){ |
$this->partages['Bdd'] = new Bdd(); |
} |
return $this->partages['Bdd']; |
} |
public function getVersions() { |
if (!isset($this->partages['Versions'])){ |
$parametres = $this->getParametresUrl(); |
$ressources = $this->getRessourcesUrl(); |
$bdd = $this->getBdd(); |
$versions = new Versions($parametres, $ressources, $bdd); |
$this->partages['Versions'] = $versions; |
} |
return $this->partages['Versions']; |
} |
public function getProjet() { |
if (!isset($this->partages['Projet'])){ |
$ressources = $this->getRessourcesUrl(); |
95,18 → 77,36 |
$projet->initialiser(); |
$projet->setParamsVerif($this->getParametresUrlVerificateur()); |
$projet->setRessourcesVerif($this->getRessourcesUrlVerificateur()); |
$projet->setServiceGenerique($this->getServiceGenerique()); |
$this->partages['Projet'] = $projet; |
} |
return $this->partages['Projet']; |
} |
public function getVersions() { |
if (!isset($this->partages['Versions'])){ |
$parametres = $this->getParametresUrl(); |
$bdd = $this->getBdd(); |
$projetNom = $this->getProjet()->getNom(); |
$versions = new Versions($parametres, $bdd, $projetNom); |
$this->partages['Versions'] = $versions; |
} |
return $this->partages['Versions']; |
} |
public function getBdd() { |
if (!isset($this->partages['Bdd'])){ |
$this->partages['Bdd'] = new Bdd(); |
} |
return $this->partages['Bdd']; |
} |
public function getNomDao() { |
$ressources = $this->getRessourcesUrl(); |
$parametres = $this->getParametresUrl(); |
$bdd = $this->getBdd(); |
$projet = $this->getProjet(); |
$versions = $this->getVersions(); |
$nomDao = new NomDAO($ressources, $parametres, $bdd, $versions); |
$nomDao = new NomDAO($ressources, $parametres, $bdd, $projet, $versions); |
return $nomDao; |
} |
119,11 → 119,9 |
return $formateur; |
} |
public function getServiceGenerique() { |
$classe = $this->getRessourcesUrl()->getServiceClasse(); |
$classeGenerique = $classe.'Generique'; |
$service = new $classeGenerique($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getNomDao(), $this->getNomFormateur()); |
if ($classe == 'NomsListe') { |
public function getService($classe) { |
$service = new $classe($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getNomDao(), $this->getNomFormateur()); |
if ($service instanceof NomsListe) { |
$service->setListeUrl($this->getParametre('listeUrl')); |
} |
return $service; |
/trunk/services/bibliotheque/Parametres.php |
---|
1,11 → 1,9 |
<?php |
// TODO : il est peut être nécessaire de mieux distinguer les attributs parametres et parametresOrigine |
// TODO : déplacer les méthodes getMasquePourBdd et getPourBdd dans les DAO |
class Parametres implements Iterator { |
private $parametres = array(); |
private $parametresOrigine = array(); |
private $parametresTypeEntier = array('navigation.limite', 'navigation.depart'); |
private $bdd = null; |
public function __construct(Array $parametres, Bdd $bdd) { |
40,14 → 38,9 |
if ($this->exister($parametreCode)) { |
$valeur = $this->parametres[$parametreCode]; |
} |
return $this->etreParametreDeTypeEntier($parametreCode) ? (int) $valeur : $valeur; |
return $valeur; |
} |
private function etreParametreDeTypeEntier($parametreCode) { |
$entier = in_array($parametreCode, $this->parametresTypeEntier) ? true : false; |
return $entier; |
} |
public function getListe($parametreCode) { |
$valeurs = array(); |
if ($this->exister($parametreCode)) { |
/trunk/services/bibliotheque/Projet.php |
---|
6,7 → 6,6 |
private $cheminBase = ''; |
private $cheminConfig = ''; |
private $cheminBiblio = ''; |
private $serviceGenerique = ''; |
public function __construct(Ressources $ressources) { |
$this->ressources = $ressources; |
32,10 → 31,6 |
$this->ressourcesVerif = $ressourcesVerificateur; |
} |
public function setServiceGenerique($generique) { |
$this->serviceGenerique = $generique; |
} |
public function initialiser() { |
$this->chargerConfig(); |
// php5.3 : Enregistrement en première position des autoload de la méthode gérant les classes des services |
49,6 → 44,7 |
private function chargerConfig() { |
$projet = $this->getNom(); |
$chemin = $this->cheminConfig."config_$projet.ini"; |
Config::charger($chemin); |
} |
56,10 → 52,6 |
return $this->ressources->getProjetNom(); |
} |
public function getClasse() { |
return $this->ressources->getServiceClasse().ucfirst($this->getNom()); |
} |
private function chargerClasseProjet($classe) { |
if (class_exists($classe)) { |
return null; |
69,7 → 61,6 |
$chemins[] = $this->cheminBase.$this->getNom().DS; |
$chemins[] = $this->cheminBase.'commun'.DS; |
$chemins[] = $this->cheminBiblio; |
$chemins[] = $this->cheminBiblio.'generique'.DS; |
$chemins[] = $this->cheminBiblio.'interfaces'.DS; |
$chemins[] = $this->cheminBiblio.'nom'.DS; |
$chemins[] = $this->cheminBiblio.'nom'.DS.'decorateurs'.DS; |
82,6 → 73,52 |
} |
} |
public function getServiceClasseNom() { |
$classeNom = ''; |
if ($this->ressources->getNombre() == 2) { |
if ($this->ressources->getServiceNom() == 'noms') { |
$classeNom = 'NomsListe'; |
} else if ($this->ressources->getServiceNom() == 'taxons') { |
$classeNom = 'TaxonsListe'; |
} |
} else if ($this->ressources->getNombre() == 3) { |
$position3 = $this->ressources->getParPosition(2); |
if ($this->ressources->etreId($position3)) { |
if ($this->ressources->getServiceNom() == 'noms') { |
$classeNom = 'NomDetails'; |
} else if ($this->ressources->getServiceNom() == 'taxons') { |
$classeNom = 'TaxonDetails'; |
} |
} |
} else if ($this->ressources->getNombre() == 4) { |
$position3 = $this->ressources->getParPosition(2); |
$position4 = $this->ressources->getParPosition(3); |
if ($this->ressources->etreStats($position3)) { |
if ($this->ressources->etreTypeDeStats($position4)) { |
$classeNom = 'NomsStats'.ucfirst($position4); |
} |
} else if ($this->ressources->etreId($position3)) { |
if ($this->ressources->etreRelations($position4)) { |
$classeNom = 'NomRelations'; |
} |
} |
} else if ($this->ressources->getNombre() == 5) { |
$position3 = $this->ressources->getParPosition(2); |
$position4 = $this->ressources->getParPosition(3); |
$position5 = $this->ressources->getParPosition(4); |
if ($this->ressources->etreId($position3)) { |
if ($this->ressources->etreRelations($position4)) { |
if ($this->ressources->etreTypeDeRelations($position5)) { |
$classeNom = 'NomRelations'.ucfirst($position5); |
} |
} |
} |
} |
$classeNomProjet = $classeNom.'Generique';//.ucfirst($this->getNom()); |
return $classeNomProjet; |
} |
public function verifier() { |
$this->paramsVerif->verifier(); |
$this->ressourcesVerif->verifier(); |
89,21 → 126,12 |
} |
private function verifierExistanceServiceClasse() { |
$classe = $this->getClasse(); |
$existe = $this->verifierExistanceClasseDuProjet($classe); |
$service = $this->ressources->getServiceNom(); |
$classe = $this->getServiceClasseNom(); |
$projet = $this->getNom(); |
if ($existe === false) { |
$service = $this->ressources->getServiceNom(); |
$projet = $this->getNom(); |
$message = "La classe du service demandé '$service' n'existe pas dans le projet '$projet' !"; |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
throw new Exception($message, $code); |
} |
} |
private function verifierExistanceClasseDuProjet($classe) { |
$chemins = array(); |
$chemins[] = $this->cheminBase.$this->getNom().DS.$classe.'.php'; |
$chemins[] = $this->cheminBase.$projet.DS.$classe.'.php'; |
$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php'; |
$existe = false; |
113,15 → 141,12 |
break; |
} |
} |
return $existe; |
if ($existe === false) { |
$message = "La classe '$classe' du service demandé '$service' n'existe pas dans le projet '$projet' !"; |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
throw new Exception($message, $code); |
} |
} |
public function consulter() { |
$serviceNom = $this->getClasse(); |
$service = new $serviceNom($this->serviceGenerique); |
$retour = $service->consulter(); |
return $retour; |
} |
} |
?> |
/trunk/services/bibliotheque/nom/NomDAO.php |
---|
1,12 → 1,14 |
<?php |
class NomDAO { |
private $bdd = null; |
private $projet = null; |
private $versions = null; |
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd, Versions $versions) { |
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd, Projet $projet, Versions $versions) { |
$this->ressources = $ressources; |
$this->parametres = $parametres; |
$this->bdd = $bdd; |
$this->projet = $projet; |
$this->versions = $versions; |
} |
13,7 → 15,7 |
private function getTable() { |
$versions = $this->versions->getVersions(); |
$derniereVersion = end($versions); |
$projetNom = strtolower($this->ressources->getProjetNom()); |
$projetNom = $this->projet->getNom(); |
return $projetNom.'_v'.$derniereVersion; |
} |
/trunk/services/bibliotheque/Versions.php |
---|
1,17 → 1,15 |
<?php |
class Versions { |
private $parametres = null; |
private $ressources = null; |
private $bdd = null; |
private $projetNom = null; |
private $versionsDispo = array(); |
private $versionCourrante = array(); |
public function __construct(Parametres $parametres, Ressources $ressources, Bdd $bdd) { |
public function __construct(Parametres $parametres, Bdd $bdd,$projetNom) { |
$this->parametres = $parametres; |
$this->ressources = $ressources; |
$this->bdd = $bdd; |
$this->projetNom = $this->ressources->getProjetNom(); |
$this->projetNom = $projetNom; |
$this->versionsDispo = $this->chargerVersionsDisponibles(); |
} |
/trunk/services/bibliotheque/ParametresVerificateur.php |
---|
3,24 → 3,6 |
private $parametres = null; |
private $parametresApi = array(); |
private $erreursParametres = array(); |
private $typesVerif = array( |
'recherche' => 'Simple', |
'ns.format' => 'Simple', |
'retour' => 'Simple', |
'retour.format' => 'Simple', |
'retour.langue' => 'RegExp', |
'ns.structure' => 'Multiple', |
'version.projet' => 'RegExp' |
); |
private $valeursPermises = array( |
'recherche' => 'stricte|floue|etendue', |
'ns.format' => 'htm|txt', |
'retour' => 'application/json|image/jpeg', |
'retour.format' => 'min|max|oss|perso', |
'retour.langue' => '/^(?:[*]|orig|[a-z]{2})$/', |
'ns.structure' => '|an|au|bib|ad', |
'version.projet' => '/^(?:[0-9]+[.][0-9]+|[*+])$/' |
); |
public function __construct(Parametres $parametres, Array $parametresApi) { |
$this->parametres = $parametres; |
32,8 → 14,7 |
$this->verifierValeurs(); |
} |
public function verifierConformiteApi() { |
$this->parametres->rewind(); |
private function verifierConformiteApi() { |
while (is_null($parametre = $this->parametres->key()) === false) { |
if (in_array($parametre, $this->parametresApi) === false) { |
$message = "Le paramètre '$parametre' n'est pas pris en compte par cette version de l'API."; |
44,23 → 25,24 |
} |
} |
public function verifierValeurs() { |
foreach ($this->typesVerif as $parametre => $type) { |
$methode = "verifierValeur$type"; |
$this->$methode($parametre); |
} |
private function verifierValeurs() { |
$this->verifierValeurSimple('recherche', 'stricte|floue|etendue'); |
$this->verifierValeurSimple('ns.format', 'htm|txt'); |
$this->verifierValeurSimple('retour', 'application/json|image/jpeg'); |
$this->verifierValeurSimple('retour.format', 'min|max|oss|perso'); |
$this->verifierValeurRegExp('retour.langue', '/^(?:[*]|orig|[a-z]{2})$/'); |
$this->verifierValeurMultipe('ns.structure', '|an|au|bib|ad'); |
$this->verifierVersionProjet(); |
if (count($this->erreursParametres) > 0) { |
array_unshift($this->erreursParametres, 'Erreur dans le paramètrage de votre URL :'); |
$message = implode('<br/>', $this->erreursParametres); |
$message = 'Erreur dans le paramètrage de votre URL : <br />'.implode('<br/>', $this->erreursParametres); |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
throw new Exception($message, $code); |
} |
} |
private function verifierValeurSimple($parametre) { |
private function verifierValeurSimple($parametre, $valeursPermises) { |
$valeur = $this->parametres->get($parametre); |
$valeursPermises = $this->valeursPermises[$parametre]; |
$permissionOk = $this->verifierValeursPermises($valeur, $valeursPermises); |
if ($permissionOk == false) { |
$this->erreursParametres[] = "Le paramètre '$parametre' ne peut pas prendre la valeur '$valeur'. Valeurs permises : $valeursPermises"; |
75,9 → 57,8 |
return $permise; |
} |
private function verifierValeurRegExp($parametre) { |
private function verifierValeurRegExp($parametre, $regexp) { |
$valeur = $this->parametres->get($parametre); |
$regexp = $this->valeursPermises[$parametre]; |
$permissionOk = preg_match($regexp, $valeur) ? true : false; |
if ($permissionOk == false) { |
$this->erreursParametres[] = "Le paramètre '$parametre' ne peut pas prendre la valeur '$valeur'. Valeurs permises : $regexp"; |
84,9 → 65,8 |
} |
} |
private function verifierValeurMultiple($parametre) { |
private function verifierValeurMultipe($parametre, $valeursPermises) { |
$valeursConcatenees = $this->parametres->get($parametre); |
$valeursPermises = $this->valeursPermises[$parametre]; |
$valeurs = explode(',', $valeursConcatenees); |
foreach ($valeurs as $valeur) { |
$permissionOk = $this->verifierValeursPermises($valeur, $valeursPermises); |
95,5 → 75,12 |
} |
} |
} |
private function verifierVersionProjet() { |
$valeur = $this->parametres->get('version.projet'); |
if (preg_match('/^(?:[0-9]+[.][0-9]+|[*+])$/', $valeur) == 0) { |
$this->erreursParametres[] = "Le paramètre 'version.projet' ne peut pas prendre la valeur '$valeur'. Valeurs permises : +,* ou [0-9]+.[0-9]+"; |
} |
} |
} |
?> |
/trunk/services/bibliotheque/Ressources.php |
---|
57,50 → 57,5 |
$etreRelationsType = in_array($aTester, $typesRelations) ? true : false; |
return $etreRelationsType; |
} |
public function getServiceClasse() { |
$classeNom = ''; |
if ($this->getNombre() == 2) { |
if ($this->getServiceNom() == 'noms') { |
$classeNom = 'NomsListe'; |
} else if ($this->getServiceNom() == 'taxons') { |
$classeNom = 'TaxonsListe'; |
} |
} else if ($this->getNombre() == 3) { |
$position3 = $this->getParPosition(2); |
if ($this->etreId($position3)) { |
if ($this->getServiceNom() == 'noms') { |
$classeNom = 'NomDetails'; |
} else if ($this->getServiceNom() == 'taxons') { |
$classeNom = 'TaxonDetails'; |
} |
} |
} else if ($this->getNombre() == 4) { |
$position3 = $this->getParPosition(2); |
$position4 = $this->getParPosition(3); |
if ($this->etreStats($position3)) { |
if ($this->etreTypeDeStats($position4)) { |
$classeNom = 'NomsStats'.ucfirst($position4); |
} |
} else if ($this->etreId($position3)) { |
if ($this->etreRelations($position4)) { |
$classeNom = 'NomRelations'; |
} |
} |
} else if ($this->getNombre() == 5) { |
$position3 = $this->getParPosition(2); |
$position4 = $this->getParPosition(3); |
$position5 = $this->getParPosition(4); |
if ($this->etreId($position3)) { |
if ($this->etreRelations($position4)) { |
if ($this->etreTypeDeRelations($position5)) { |
$classeNom = 'NomRelations'.ucfirst($position5); |
} |
} |
} |
} |
return $classeNom; |
} |
} |
?> |
/trunk/services/bibliotheque/interfaces/NomsListe.php |
---|
1,6 → 1,6 |
<?php |
interface NomsListe { |
public function __construct(NomsListeGenerique $nomsListe); |
public function __construct(Ressources $ressources, Parametres $parametres, NomDAO $nomDao, NomFormateur $nomFormateur); |
public function consulter(); |
} |
?> |
/trunk/services/bibliotheque/interfaces/NomDetails.php |
---|
1,6 → 1,6 |
<?php |
interface NomDetails { |
public function __construct(NomDetailsGenerique $nomDetails); |
public function __construct(Ressources $ressources, Parametres $parametres, NomDAO $nomDao, NomFormateur $nomFormateur); |
public function consulter(); |
} |
?> |