Subversion Repositories Applications.framework

Rev

Rev 348 | Rev 350 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 348 Rev 349
Line 7... Line 7...
7
* @package 	Framework
7
* @package 	Framework
8
* @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
* @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
* @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
9
* @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
10
* @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
* @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
* @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
11
* @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
* @version		$Id: RestClient.php 348 2011-06-16 15:35:06Z jpm $
12
* @version		$Id: RestClient.php 349 2011-06-16 15:53:12Z jpm $
13
*/
13
*/
14
class RestClient {
14
class RestClient {
15
	const HTTP_URL_REQUETE_SEPARATEUR = '&';
15
	const HTTP_URL_REQUETE_SEPARATEUR = '&';
-
 
16
	const HTTP_URL_REQUETE_CLE_VALEUR_SEPARATEUR = '=';
16
	private $http_methodes = array('GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'CONNECT', 'TRACE');
17
	private $http_methodes = array('GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'CONNECT', 'TRACE');
17
	protected $parametres = null;
18
	protected $parametres = null;
18
	private $url = null;
19
	private $url = null;
19
	private $reponse_entetes = null;
20
	private $reponse_entetes = null;
Line 78... Line 79...
78
			$contexte = stream_context_create(array(
79
			$contexte = stream_context_create(array(
79
				'http' => array(
80
				'http' => array(
80
      				'method' => $mode,
81
      				'method' => $mode,
81
					'header' => "Content-type: application/x-www-form-urlencoded\r\n",
82
					'header' => "Content-type: application/x-www-form-urlencoded\r\n",
82
      				'content' => http_build_query($donnees, null, self::HTTP_URL_REQUETE_SEPARATEUR))));
83
      				'content' => http_build_query($donnees, null, self::HTTP_URL_REQUETE_SEPARATEUR))));
83
			$flux = @fopen($url, 'r', false, $contexte);
84
			$flux = @fopen($this->url, 'r', false, $contexte);
84
			if (!$flux) {
85
			if (!$flux) {
85
				$this->reponse_entetes = $http_response_header;
86
				$this->reponse_entetes = $http_response_header;
86
				$e = "L'ouverture de l'url '$url' par la méthode HTTP '$mode' a échoué!";
87
				$e = "L'ouverture de l'url '{$this->url}' par la méthode HTTP '$mode' a échoué!";
87
				trigger_error($e, E_USER_WARNING);
88
				trigger_error($e, E_USER_WARNING);
88
			} else {
89
			} else {
89
				// Informations sur les en-têtes et métadonnées du flux
90
				// Informations sur les en-têtes et métadonnées du flux
90
				$this->reponse_entetes = stream_get_meta_data($flux);
91
				$this->reponse_entetes = stream_get_meta_data($flux);
Line 102... Line 103...
102
	
103
	
103
	private function traiterUrlParametres() {
104
	private function traiterUrlParametres() {
104
		$parametres = array();
105
		$parametres = array();
105
		if (count($this->parametres) > 0) {
106
		if (count($this->parametres) > 0) {
106
			foreach ($this->parametres as $cle => $valeur) {
107
			foreach ($this->parametres as $cle => $valeur) {
107
				$parametres[] = $cle.self::HTTP_URL_REQUETE_SEPARATEUR.$valeur;
108
				$parametres[] = $cle.self::HTTP_URL_REQUETE_CLE_VALEUR_SEPARATEUR.$valeur;
108
			}
109
			}
109
			$url_parametres = implode(self::HTTP_URL_REQUETE_SEPARATEUR, $parametres);
110
			$url_parametres = implode(self::HTTP_URL_REQUETE_SEPARATEUR, $parametres);
110
			$this->url = $this->url.'?'.$url_parametres;
111
			$this->url = $this->url.'?'.$url_parametres;
111
		}
112
		}