Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 31 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

class 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->chargerNomSource();
                                $this->verifierParametres();
                                $this->chargerNomService();
                                $objetTraitement = new $this->nomService($this->parametresRecherche);
                                $methode = $this->genererNomMethodeAExecuter();
                                $retour = $objetTraitement->$methode();
                        }
                        
                } catch (Exception $erreur) {
                        $retour = $erreur; 
                }
                
                return $retour;
        }
        
        private function recupererRessourcesEtParametres($ressources, $parametres) {
                $this->ressources = $ressources;
                $this->parametres = $parametres;
        }
        
        private function chargerNomService() {
                $this->nomService = ucfirst($this->parametres['source']) . 'Formateur';
                Projets::chargerConfigurationSource($this->parametres['source']);
        }
        
        private function genererNomMethodeAExecuter() {
                return 'recuperer' . ucfirst($this->ressources[0]);
        }
        
        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 chargerNomSource() {
                if (isset($this->parametres['source'])) {
                        $this->nomSource = $this->parametres['source'];
                } else {
                        $this->nomSource = Config::get('source_defaut');
                }
        }
        
        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();
        }
        
        
}

?>