Subversion Repositories Applications.framework

Rev

Rev 353 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 353 Rev 470
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 353 2011-08-01 16:02:32Z jpm $
12
* @since		0.2
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
	const HTTP_URL_REQUETE_CLE_VALEUR_SEPARATEUR = '=';
17
	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');
Line 74... Line 74...
74
			trigger_error($e, E_USER_WARNING);
74
			trigger_error($e, E_USER_WARNING);
75
		} else {
75
		} else {
76
			if ($mode == 'GET') {
76
			if ($mode == 'GET') {
77
				$this->traiterUrlParametres();
77
				$this->traiterUrlParametres();
78
			}
78
			}
-
 
79
			$content = http_build_query($donnees, null, self::HTTP_URL_REQUETE_SEPARATEUR);
79
			$contexte = stream_context_create(array(
80
			$contexte = stream_context_create(array(
80
				'http' => array(
81
				'http' => array(
81
      				'method' => $mode,
82
      				'method' => $mode,
82
					'header' => "Content-type: application/x-www-form-urlencoded\r\n",
83
					'header' => "Content-type: application/x-www-form-urlencoded\r\n",
83
      				'content' => http_build_query($donnees, null, self::HTTP_URL_REQUETE_SEPARATEUR))));
84
      				'content' => $content)));
84
			$flux = @fopen($this->url, 'r', false, $contexte);
85
			$flux = @fopen($this->url, 'r', false, $contexte);
85
			if (!$flux) {
86
			if (!$flux) {
86
				$this->reponse_entetes = $http_response_header;
87
				$this->reponse_entetes = $http_response_header;
-
 
88
				$entetesFmt = print_r($this->analyserEntete(), true);
87
				$e = "L'ouverture de l'url '{$this->url}' par la méthode HTTP '$mode' a échoué!";
89
				$e = "L'ouverture de l'url '{$this->url}' par la méthode HTTP '$mode' a échoué!\n".
-
 
90
					"Le contenu des métadonnées était : $entetesFmt \n".
-
 
91
					"Les paramètres de la requête HTTP étaient : $content \n".
-
 
92
					"Le contenu était : ".stream_get_contents($flux);
88
				trigger_error($e, E_USER_WARNING);
93
				trigger_error($e, E_USER_WARNING);
89
			} else {
94
			} else {
90
				// Informations sur les en-têtes et métadonnées du flux
95
				// Informations sur les en-têtes et métadonnées du flux
91
				$this->reponse_entetes = stream_get_meta_data($flux);
96
				$this->reponse_entetes = stream_get_meta_data($flux);