| Line 14... | 
            Line 14... | 
          
          
            | 14 | 
             * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
  | 
            14 | 
             * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
  | 
          
          
            | 15 | 
             * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
  | 
            15 | 
             * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
  | 
          
          
            | 16 | 
             */
  | 
            16 | 
             */
  | 
          
          
            | 17 | 
            class Nomstaxons extends RestService {
  | 
            17 | 
            class Nomstaxons extends RestService {
  | 
          
          
            | Line 18... | 
            Line -... | 
          
          
            | 18 | 
             
  | 
            - | 
               | 
          
          
            | 19 | 
             
  | 
            18 | 
             
  | 
          
          
            | 20 | 
            	private $parametres = array();
  | 
            19 | 
            	private $parametres = array();
  | 
          
          
            | 21 | 
            	private $ressources = array();
  | 
            20 | 
            	private $ressources = array();
  | 
          
          
            | 22 | 
            	private $methode = null;
  | 
            21 | 
            	private $methode = null;
  | 
          
          
            | 23 | 
            	private $projetNom = array();
  | 
            22 | 
            	private $serviceNom = 'nomstaxons';
  | 
          
          
            | 24 | 
            	private $serviceNom = array();
  | 
            23 | 
            	private $sousServiceNom = null;
  | 
          
          
            | Line 25... | 
            Line 24... | 
          
          
            | 25 | 
            	private $cheminCourant = null;
  | 
            24 | 
            	private $cheminCourant = null;
  | 
          
          
            | Line 26... | 
            Line 25... | 
          
          
            | 26 | 
             
  | 
            25 | 
             
  | 
          
          
            | Line 33... | 
            Line 32... | 
          
          
            | 33 | 
            		$this->cheminCourant = dirname(__FILE__).DS;
  | 
            32 | 
            		$this->cheminCourant = dirname(__FILE__).DS;
  | 
          
          
            | 34 | 
            	}
  | 
            33 | 
            	}
  | 
          
          
            | Line 35... | 
            Line 34... | 
          
          
            | 35 | 
             
  | 
            34 | 
             
  | 
          
          
            | 36 | 
            	public function consulter($ressources, $parametres) {
  | 
            35 | 
            	public function consulter($ressources, $parametres) {
  | 
          
          
            | - | 
               | 
            36 | 
            		$this->methode = 'consulter';
  | 
          
          
            | - | 
               | 
            37 | 
            		$this->initialiserRessourcesEtParametres($ressources, $parametres);
  | 
          
          
            | - | 
               | 
            38 | 
            		return $this->executerService();
  | 
          
          
            | - | 
               | 
            39 | 
            	}
  | 
          
          
            | - | 
               | 
            40 | 
             
  | 
          
          
            | 37 | 
            		$this->methode = 'consulter';
  | 
            41 | 
            	private function initialiserRessourcesEtParametres($ressources, $parametres = array()) {
  | 
          
          
            | - | 
               | 
            42 | 
            		$this->ressources = $ressources;
  | 
          
          
            | - | 
               | 
            43 | 
            		$this->parametres = $parametres;
  | 
          
          
            | - | 
               | 
            44 | 
            	}
  | 
          
          
            | - | 
               | 
            45 | 
             
  | 
          
          
            | 38 | 
            		$resultat = '';
  | 
            46 | 
            	private function executerService() {
  | 
          
          
            | 39 | 
            		$reponseHttp = new ReponseHttp();
  | 
            47 | 
            		$reponseHttp = new ReponseHttp();
  | 
          
          
            | 40 | 
            		try {
  | 
            - | 
               | 
          
          
            | 41 | 
            			$this->initialiserRessourcesEtParametres($ressources, $parametres);
  | 
            48 | 
            		try {
  | 
          
          
            | 42 | 
            			$this->conteneur = new Conteneur($this->parametres);
  | 
            49 | 
            			$this->conteneur = new Conteneur($this->parametres);
  | 
          
          
            | 43 | 
            			$resultat = $this->traiterRessources();
  | 
            50 | 
            			$resultat = $this->traiterRessources();
  | 
          
          
            | 44 | 
            			$reponseHttp->setResultatService($resultat);
  | 
            51 | 
            			$reponseHttp->setResultatService($resultat);
  | 
          
          
            | 45 | 
            		} catch (Exception $e) {
  | 
            52 | 
            		} catch (Exception $e) {
  | 
          
          
            | Line 48... | 
            Line 55... | 
          
          
            | 48 | 
            		$reponseHttp->emettreLesEntetes();
  | 
            55 | 
            		$reponseHttp->emettreLesEntetes();
  | 
          
          
            | 49 | 
            		$corps = $reponseHttp->getCorps();
  | 
            56 | 
            		$corps = $reponseHttp->getCorps();
  | 
          
          
            | 50 | 
            		return $corps;
  | 
            57 | 
            		return $corps;
  | 
          
          
            | 51 | 
            	}
  | 
            58 | 
            	}
  | 
          
          
            | Line 52... | 
            Line -... | 
          
          
            | 52 | 
             
  | 
            - | 
               | 
          
          
            | 53 | 
            	private function initialiserRessourcesEtParametres($ressources, $parametres) {
  | 
            - | 
               | 
          
          
            | 54 | 
            		$this->ressources = $ressources;
  | 
            - | 
               | 
          
          
            | 55 | 
            		$this->parametres = $parametres;
  | 
            - | 
               | 
          
          
            | 56 | 
            	}
  | 
            - | 
               | 
          
          
            | 57 | 
             
  | 
            59 | 
             
  | 
          
          
            | 58 | 
            	private function traiterRessources() {
  | 
            - | 
               | 
          
          
            | 59 | 
            		$retour = '';
  | 
            60 | 
            	private function traiterRessources() {
  | 
          
          
            | 60 | 
            		$this->initialiserProjet();
  | 
            61 | 
            		$this->analyserRessources();
  | 
          
          
            | 61 | 
            		$retour = $this->initialiserService();
  | 
            62 | 
            		$retour = $this->initialiserService();
  | 
          
          
            | 62 | 
            		return $retour;
  | 
            63 | 
            		return $retour;
  | 
          
          
            | Line 63... | 
            Line 64... | 
          
          
            | 63 | 
            	}
  | 
            64 | 
            	}
  | 
          
          
            | 64 | 
             
  | 
            65 | 
             
  | 
          
          
            | 65 | 
            	/*------------------------------------------------------------------------------------------------------------------
  | 
            - | 
               | 
          
          
            | 66 | 
            										CONFIGURATION DU PROJET
  | 
            66 | 
            	private function analyserRessources() {
  | 
          
          
            | 67 | 
            	------------------------------------------------------------------------------------------------------------------*/
  | 
            67 | 
            		if ($this->methode == 'consulter') {
  | 
          
          
            | - | 
               | 
            68 | 
            			if (count($this->ressources) == 0
  | 
          
          
            | 68 | 
            	private function initialiserProjet() {
  | 
            69 | 
            				&& $this->verifierPresenceParametre('masque.nom')
  | 
          
          
            | 69 | 
            		$this->projetNom = 'nomstaxons';
  | 
            70 | 
            				&& $this->verifierPresenceParametre('masque.referentiel')) {
  | 
          
          
            | 70 | 
            		$this->chargerConfigProjet();
  | 
            71 | 
            				$this->sousServiceNom = 'liste-taxons';
  | 
          
          
            | 71 | 
            	}
  | 
            72 | 
            			}
  | 
          
          
            | 72 | 
             
  | 
            73 | 
            		}
  | 
          
          
            | 73 | 
            	private function chargerConfigProjet() {
  | 
            - | 
               | 
          
          
            | 74 | 
            		$projet = $this->projetNom;
  | 
            74 | 
            		if ($this->sousServiceNom == null) {
  | 
          
          
            | 75 | 
            		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
  | 
            75 | 
            			$this->lancerMessageErreurRessource();
  | 
          
          
            | 76 | 
            		Config::charger($chemin);
  | 
            76 | 
            		}
  | 
          
          
            | - | 
               | 
            77 | 
            	}
  | 
          
          
            | 77 | 
            	}
  | 
            78 | 
             
  | 
          
          
            | 78 | 
             
  | 
            79 | 
            	private function verifierPresenceParametre($cle) {
  | 
          
          
            | 79 | 
            	/*------------------------------------------------------------------------------------------------------------------
  | 
            80 | 
            		if (isset($this->parametres[$cle]) && trim($this->parametres[$cle]) == '') {
  | 
          
          
            | 80 | 
            								CONFIGURATION DU SERVICE
  | 
            81 | 
            			$message = "Le service demandé '{$this->serviceNom}' ".
  | 
          
          
            | - | 
               | 
            82 | 
            				"nécessite l'utilisation de paramètres (non vide) : masque.nom & masque.referentiel\n";
  | 
          
          
            | 81 | 
            	------------------------------------------------------------------------------------------------------------------*/
  | 
            83 | 
            			throw new Exception($message, RestServeur::HTTP_CODE_ECHEC_CONDITION);
  | 
          
          
            | - | 
               | 
            84 | 
            		}
  | 
          
          
            | Line -... | 
            Line 85... | 
          
          
            | - | 
               | 
            85 | 
            		return true;
  | 
          
          
            | - | 
               | 
            86 | 
            	}
  | 
          
          
            | - | 
               | 
            87 | 
             
  | 
          
          
            | - | 
               | 
            88 | 
            	private function lancerMessageErreurRessource() {
  | 
          
          
            | - | 
               | 
            89 | 
            		$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
  | 
          
          
            | - | 
               | 
            90 | 
            		$message = "La ressource demandée '$ressource' ".
  | 
          
          
            | - | 
               | 
            91 | 
            			"n'est pas disponible pour le service ".$this->serviceNom." !\n".
  | 
          
          
            | - | 
               | 
            92 | 
            			"Les URLs disponibles sont : \n".
  | 
          
          
            | - | 
               | 
            93 | 
            			" - en GET : nomstaxons (paramètres : masque.nom & masque.referentiel) \n";
  | 
          
          
            | - | 
               | 
            94 | 
            		$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
  | 
          
          
            | - | 
               | 
            95 | 
            		throw new Exception($message, $code);
  | 
          
          
            | 82 | 
            	private function initialiserService() {
  | 
            96 | 
            	}
  | 
          
          
            | 83 | 
            		$this->chargerNomService();
  | 
            97 | 
             
  | 
          
          
            | 84 | 
             
  | 
            98 | 
            	private function initialiserService() {
  | 
          
          
            | 85 | 
            		$classe = $this->obtenirNomClasseService($this->serviceNom);
  | 
            99 | 
            		$classe = $this->obtenirNomClasseService($this->sousServiceNom);
  | 
          
          
            | 86 | 
            		$chemins = array();
  | 
            100 | 
            		$chemins = array();
  | 
          
          
            | 87 | 
            		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
  | 
            101 | 
            		$chemins[] = $this->cheminCourant.$this->serviceNom.DS.$classe.'.php';
  | 
          
          
            | - | 
               | 
            102 | 
            		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
  | 
          
          
            | 88 | 
            		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
  | 
            103 | 
            		$retour = '';
  | 
          
          
            | 89 | 
            		$retour = '';
  | 
            104 | 
            		$service = null;
  | 
          
          
            | 90 | 
            		$service = null;
  | 
            - | 
               | 
          
          
            | 91 | 
            		foreach ($chemins as $chemin) {
  | 
            105 | 
             
  | 
          
          
            | 92 | 
            			if (file_exists($chemin)) {
  | 
            106 | 
            		foreach ($chemins as $chemin) {
  | 
          
          
            | 93 | 
            				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
  | 
            107 | 
            			if (file_exists($chemin)) {
  | 
          
          
            | 94 | 
            				require_once $chemin;
  | 
            108 | 
            				require_once $chemin;
  | 
          
          
            | 95 | 
            				$service = new $classe($this->conteneur);
  | 
            109 | 
            				$service = new $classe($this->conteneur);
  | 
          
          
            | - | 
               | 
            110 | 
            				if ($this->methode == 'consulter') {
  | 
          
          
            | - | 
               | 
            111 | 
            					$retour = $service->consulter();
  | 
          
          
            | - | 
               | 
            112 | 
            				} else {
  | 
          
          
            | 96 | 
            				if ($this->methode == 'consulter') {
  | 
            113 | 
            					$message = "Le sous-service '{$this->sousServiceNom}' du service '{$this->serviceNom}' ".
  | 
          
          
            | 97 | 
            					$retour = $service->consulter($this->ressources, $this->parametres);
  | 
            114 | 
            						"ne possède pas de méthode '{$this->methode}' !";
  | 
          
          
            | 98 | 
            				} else {
  | 
            115 | 
            					$code = RestServeur::HTTP_NON_IMPLEMENTE;
  | 
          
          
            | 99 | 
            					//TODO : throw exception
  | 
            116 | 
            					throw new Exception($message, $code);
  | 
          
          
            | Line 100... | 
            Line 117... | 
          
          
            | 100 | 
            				}
  | 
            117 | 
            				}
  | 
          
          
            | - | 
               | 
            118 | 
            			}
  | 
          
          
            | 101 | 
            			}
  | 
            119 | 
            		}
  | 
          
          
            | - | 
               | 
            120 | 
             
  | 
          
          
            | 102 | 
            		}
  | 
            121 | 
            		if (is_null($service)) {
  | 
          
          
            | 103 | 
             
  | 
            122 | 
            			$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
  | 
          
          
            | 104 | 
            		if (is_null($service)) {
  | 
            123 | 
            			$message = "Le classe '$classe' correspondant à la ressource '$ressource' ".
  | 
          
          
            | 105 | 
            			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
  | 
            124 | 
            				"est introuvable par le service '{$this->serviceNom}' !";
  | 
          
          
            | 106 | 
            			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
  | 
            125 | 
            			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
  | 
          
          
            | Line 107... | 
            Line -... | 
          
          
            | 107 | 
            			throw new Exception($message, $code);
  | 
            - | 
               | 
          
          
            | 108 | 
            		}
  | 
            - | 
               | 
          
          
            | 109 | 
            		return $retour;
  | 
            - | 
               | 
          
          
            | 110 | 
            	}
  | 
            - | 
               | 
          
          
            | 111 | 
             
  | 
            - | 
               | 
          
          
            | 112 | 
            	private function chargerNomService() {
  | 
            126 | 
            			throw new Exception($message, $code);
  | 
          
          
            | 113 | 
            		// si la méthode est POST, on ajouter un commentaire
  | 
            127 | 
            		}
  | 
          
          
            | 114 | 
            		$this->serviceNom = 'liste-taxons';
  | 
            128 | 
            		return $retour;
  | 
          
          
            | 115 | 
            	}
  | 
            129 | 
            	}
  | 
          
          
            | 116 | 
             
  | 
            - | 
               | 
          
          
            | 117 | 
            	private function obtenirNomClasseService($mot) {
  | 
            - | 
               | 
          
          
            | 118 | 
            		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
  | 
            130 | 
             
  | 
          
          
            | - | 
               | 
            131 | 
            	private function obtenirNomClasseService($mot) {
  | 
          
          
            | 119 | 
            		return $classeNom;
  | 
            132 | 
            		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
  |