Rev 26 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpclass Commun {private $parametres;private $nomSource;private $nomService;private $verificateur;private $parametresRecherche;public function consulter($ressources, $parametres) {$this->recupererRessourcesEtParametres($ressources, $parametres);$retour = null;try {if (!$this->verifierExistenceSourcesDonnees()) {$message = "Source de donnees indisponible";throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);} else {$this->verifierParametres();if ($this->ressources[0] == 'mailles') {$retour = $this->recupererMaillage();} else {$this->chargerNomSource();$this->chargerNomService();$retour = $this->executerServicePourSource();}}} catch (Exception $erreur) {$retour = $erreur;}return $retour;}private function recupererRessourcesEtParametres($ressources, $parametres) {$this->ressources = $ressources;$this->parametres = $parametres;}private function verifierExistenceSourcesDonnees() {$sourcesDisponibles = explode(',', Config::get('sources_dispo'));$estDisponible = false;if (isset($this->parametres['source'])) {if (in_array($this->parametres['source'], $sourcesDisponibles)) {$estDisponible = true;}} else {// choisir la source par defaut, qui est toujours disponible$estDisponible = true;}return $estDisponible;}private function verifierParametres() {$this->verificateur = new VerificateurParametres($this->parametres);$this->verificateur->verifierParametres();if ($this->verificateur->contientErreurs()) {$this->verificateur->leverException();} else {$this->recupererParametresRecherche();}}private function recupererParametresRecherche() {$this->parametresRecherche = $this->verificateur->renvoyerResultatVerification();}private function chargerNomSource() {if (isset($this->parametres['source'])) {$this->nomSource = $this->parametres['source'];} else {$this->nomSource = Config::get('source_defaut');}}private function chargerNomService() {$this->nomService = ucfirst($this->parametres['source']) . 'Formateur';Projets::chargerConfigurationSource($this->parametres['source']);}private function recupererMaillage() {$maillage = new Maillage($this->parametresRecherche->bbox, $this->parametresRecherche->zoom);$maillage->genererMaillesVides();$formateurJSON = new FormateurJson();return $formateurJSON->formaterMaillesVides($maillage->formaterSortie(true));}private function executerServicePourSource() {$objetTraitement = new $this->nomService($this->parametresRecherche);$methode = $this->genererNomMethodeAExecuter();return $objetTraitement->$methode();}private function genererNomMethodeAExecuter() {return 'recuperer' . ucfirst($this->ressources[0]);}}?>