Précédent   Forum des professionnels en informatique > PHP > Outils > Zend > Zend Framework
Zend Framework Forum d'entraide sur la programmation PHP avec Zend Framework. Avant de poster -> FAQ ZF, Cours ZF
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/08/2011, 15h39   #1
Membre du Club
 
Homme Brice
Ingénieur d'études en développements techniques
Inscription : novembre 2005
Messages : 190
Détails du profil
Informations personnelles :
Nom : Homme Brice
Âge : 40
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études en développements techniques
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2005
Messages : 190
Points : 55
Points : 55
Envoyer un message via MSN à bpdelavega
Par défaut Mettre un flux XML avec Zend_Cache et Zend_Http_Client

Bonjour,

Je suis en train de développer une classe sous ZF qui me récupère un flux XML et la met en cache, j'utilise des objets ZF pour ça, mais je rencontre plusieurs difficultés, on va commencer par la première, je dois nommer le fichier en m'appuyant sur la date du jour, mais j'ai une erreur
Citation:
Message: Invalid id or tag 'xmlComment_cache_2011-35-30_fastbooking' : must use only [a-zA-Z0-9_]
Voici mon code :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
<?php
class App_Fastbooking
{
	/**
	 * Username
	 *
	 * @var string
	 */
	static protected $_strUsername = 'XXXX';
 
	/**
	 * Password
	 *
	 * @var string
	 */
	static protected $_strPassword = 'zzzzzzz';
 
	/**
	 * Service url
	 *
	 * @var string
	 */
	static protected $_strServiceUrl = 'http://apixml.fastbooking.net/XMLcomments.php';
 
	/**
	 * Start date of request
	 *
	 * @var string
	 */
	static protected $_strStartDate;
 
	/**
	 * End date of request
	 *
	 * @var string
	 */
	static protected $_strEndDate;
 
	/**
	 * Current service instance
	 *
	 * @var Hgp_Lib_Service_Fastbooking
	 */
	static protected $_instance;
 
	/**
	 * Nb Days on the demand period
	 *
	 * @var Integer
	 */
	static protected $_intNbDays = 30;
 
	/**
	 * Defautl Cache life in hour
	 *
	 * @var Integer
	 */
	static protected $_intCacheLife = 24;
 
	/**
	 * xmlContent
	 *
	 * @var string
	 */
	static protected $_xmlContent;
 
	/**
	 * $_client
	 *
	 * @object Zend_Http_Client
	 */
	static protected $_client;
 
	/**
	 * Constructor
	 * Init instance
	 */
	public function __construct()
	{
 
		static $beginDate;
 
		if (!isset($beginDate) || is_null($beginDate)) {
			$beginDate = Zend_Date::now('en_US');
		}
		$endDate = clone($beginDate);
		$endDate->add((int) self::$_intNbDays, Zend_Date::DAY);
 
		$endDate = clone($beginDate);
		$endDate->add(self::$_intNbDays, Zend_Date::DAY);
 
		self::$_strStartDate = $beginDate->toString('Y-m-d');
		self::$_strEndDate   = $endDate->toString('Y-m-d');
 
		$strRequest = '<?xml version="1.0" encoding="utf-8" ?>'
    	. '<REQUEST>'
    	. '<HEADER Username="'.self::$_strUsername.'" Password="'.self::$_strPassword.'" Protocol="1.0" />'
    	. '<XMLCOMMENTS startDate="'.self::$_strStartDate.'" endDate="'.self::$_strEndDate.'"/>'
    	. '</REQUEST>';
 
		self::$_client = new Zend_Http_Client(self::$_strServiceUrl, array( 'adapter' => 'Zend_Http_Client_Adapter_Curl' ));
    	self::$_client->setParameterPost('xdata', $strRequest);
 
		self::$_instance = $this;
		//self::$_instance = $client;
	}
 
	/**
	 * Returns instance
	 *
	 * @return Hgp_Lib_Service_AvailPro
	*/
	static public function getInstance()
	{
		if (!self::$_instance instanceof self) {
			self::$_instance = new self();
		}
 
		return self::$_instance;
	}
 
	protected function getCache($content)
    {
    	//The current date
    	static $currDate;
		if (!isset($currDate)) {		
		    $currDate = Zend_Date::now('en_US')->toString('Y-m-d');		
		}
 
    	// has cache ?
    	$cacheId = 'xmlComment_cache_'.$currDate.'_fastbooking';
 
		// Cache location
		$_cacheComment =  CACHE_DIR.'/';
 
    	$frontendOptions = array( 'automatic_serialization' => true );
		$backendOptions = array( 'cacheDir' => $_cacheComment );
 
		$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
		//$cache->remove($cacheId);
		$cacheValue = $cache->load($cacheId);
 
		if ($cacheValue) {
			self::$_xmlContent = $cacheValue;
			return 200;
		}
 
 
        // set cache
        $cache->setLifetime(3600 * self::$_intCacheLife); 
        $cache->save($content, $cacheId);
 
 
        return self::$_xmlContent;
    }
 
	/**
	 * 
	 *
	 * @var int $aHotelId
	 * @return stdClass
	 */
	public function getAllComment()
	{
		$arrReturn = array();
		$client = self::getInstance();
		$xmlResponse = simplexml_load_string(self::$_client->request('POST')->getBody());
		//$xmlResponse = self::$_client->request('POST')->getBody();
		$arrReturn = self::getCache($xmlResponse);			
		return (object) $arrReturn;
		//return $xmlResponse;
	}
}
bpdelavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/08/2011, 15h48   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 116
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 116
Points : 8 465
Points : 8 465
Y-m-d >> Y_m_d
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 30/08/2011, 15h57   #3
Membre du Club
 
Homme Brice
Ingénieur d'études en développements techniques
Inscription : novembre 2005
Messages : 190
Détails du profil
Informations personnelles :
Nom : Homme Brice
Âge : 40
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études en développements techniques
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2005
Messages : 190
Points : 55
Points : 55
Envoyer un message via MSN à bpdelavega
Oui merci, j'étais justement en train de voir mon erreur , j'avais carrément supprimé les "-", mais bon c'est aussi bien de mettre "_", ça reste lisible, merci beaucoup !
bpdelavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/08/2011, 16h40   #4
Membre du Club
 
Homme Brice
Ingénieur d'études en développements techniques
Inscription : novembre 2005
Messages : 190
Détails du profil
Informations personnelles :
Nom : Homme Brice
Âge : 40
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études en développements techniques
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2005
Messages : 190
Points : 55
Points : 55
Envoyer un message via MSN à bpdelavega
Par défaut Plus de message d'erreur mais le flux est vide

Je continue sur mon objet ZF,
voici le code obtenu :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
 
<?php
class App_Fastbooking
{
	/**
	 * Username
	 *
	 * @var string
	 */
	static protected $_strUsername = 'XXXX';
 
	/**
	 * Password
	 *
	 * @var string
	 */
	static protected $_strPassword = 'zzzzzzz';
 
	/**
	 * Service url
	 *
	 * @var string
	 */
	static protected $_strServiceUrl = 'http://apixml.fastbooking.net/XMLcomments.php';
 
	/**
	 * Start date of request
	 *
	 * @var string
	 */
	static protected $_strStartDate;
 
	/**
	 * End date of request
	 *
	 * @var string
	 */
	static protected $_strEndDate;
 
	/**
	 * Current service instance
	 *
	 * @var Hgp_Lib_Service_Fastbooking
	 */
	static protected $_instance;
 
	/**
	 * Nb Days on the demand period
	 *
	 * @var Integer
	 */
	static protected $_intNbDays = 30;
 
	/**
	 * Defautl Cache life in hour
	 *
	 * @var Integer
	 */
	static protected $_intCacheLife = 24;
 
	/**
	 * xmlContent
	 *
	 * @var string
	 */
	static protected $_xmlContent;
 
	/**
	 * $_client
	 *
	 * @object Zend_Http_Client
	 */
	static protected $_client;
 
	/**
	 * Constructor
	 * Init instance
	 */
	public function __construct()
	{
 
		static $beginDate;
 
		if (!isset($beginDate) || is_null($beginDate)) {
			$beginDate = Zend_Date::now('en_US');
		}
		$endDate = clone($beginDate);
		$endDate->add((int) self::$_intNbDays, Zend_Date::DAY);
 
		$endDate = clone($beginDate);
		$endDate->add(self::$_intNbDays, Zend_Date::DAY);
 
		self::$_strStartDate = $beginDate->toString('Y-m-d');
		self::$_strEndDate   = $endDate->toString('Y-m-d');
 
		$strRequest = '<?xml version="1.0" encoding="utf-8" ?>'
    	. '<REQUEST>'
    	. '<HEADER Username="'.self::$_strUsername.'" Password="'.self::$_strPassword.'" Protocol="1.0" />'
    	. '<XMLCOMMENTS startDate="'.self::$_strStartDate.'" endDate="'.self::$_strEndDate.'"/>'
    	. '</REQUEST>';
 
		self::$_client = new Zend_Http_Client(self::$_strServiceUrl, array( 'adapter' => 'Zend_Http_Client_Adapter_Curl' ));
    	self::$_client->setParameterPost('xdata', $strRequest);
 
		self::$_instance = $this;
	}
 
	/**
	 * Returns instance
	 *
	 * @return Hgp_Lib_Service_AvailPro
	*/
	static public function getInstance()
	{
		if (!self::$_instance instanceof self) {
			self::$_instance = new self();
		}
 
		return self::$_instance;
	}
 
	protected function getCache($content)
    {
    	//The current date
    	static $currDate;
		if (!isset($currDate)) {		
		    $currDate = Zend_Date::now('en_US')->toString('Ymd');		
		}
 
    	// has cache ?
    	$cacheId = 'xmlComment_cache_'.$currDate.'_fastbooking';
 
		// Cache location
		$_cacheComment =  CACHE_DIR.'/';
 
    	$frontendOptions = array( 'automatic_serialization' => true );
		$backendOptions = array( 'cacheDir' => $_cacheComment );
 
		$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
		//$cache->remove($cacheId);
		$cacheValue = $cache->load($cacheId);
 
		if ($cacheValue) {
			self::$_xmlContent = $cacheValue;
			return 200;
		}
 
 
        // set cache
        $cache->setLifetime(3600 * self::$_intCacheLife); 
        $cache->save($content, $cacheId);
 
 
        return self::$_xmlContent;
    }
 
 
	/**
	 * Returns All comments
	 *
	 * @return arrReturn
	 */
	public function getAllComment()
	{
		$arrReturn = array();
		self::getInstance();
		//$arrReturn = simplexml_load_string(self::getCache(self::$_client->request('POST')->getBody()));			
		$arrReturn = self::getCache(self::$_client->request('POST')->getBody());			
		return (object) $arrReturn;
	}
}
voici mon lien du Zend_Debug::dump Mais le flux est vide, ais-je mal fait quelque chose ? d'avance merci pour votre aide...
bpdelavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/08/2011, 17h41   #5
Membre du Club
 
Homme Brice
Ingénieur d'études en développements techniques
Inscription : novembre 2005
Messages : 190
Détails du profil
Informations personnelles :
Nom : Homme Brice
Âge : 40
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études en développements techniques
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2005
Messages : 190
Points : 55
Points : 55
Envoyer un message via MSN à bpdelavega
Par défaut Ca avance mais ...

ça avance bien, j'arrive à obtenir ce résultat :

Citation:
object(SimpleXMLElement)#199 (1) {
["COMMENT"] => array(3601) {
[0] => object(SimpleXMLElement)#202 (1) {
["@attributes"] => array(6) {
["date"] => string(10) "2009-08-31"
["hotel"] => string(16) "TOTO2"
["note"] => string(41) "1:5-2:5-3:5-4:1-5:2-7:3-8:3-9:3-10:1-16:0"
["origin"] => string(5) "email"
["language"] => string(2) "fr"
["confirmationCode"] => string(16) "Ole750563cHQPHCM"
}
}
[1] => object(SimpleXMLElement)#203 (1) {
["@attributes"] => array(6) {
["date"] => string(10) "2009-08-31"
["hotel"] => string(16) "TOTO1"
["note"] => string(41) "1:4-2:4-3:4-4:4-5:3-7:3-8:4-9:4-10:1-16:0"
["origin"] => string(5) "email"
["language"] => string(2) "en"
["confirmationCode"] => string(16) "Sch817884vQQPHCM"
}
}
[2] => object(SimpleXMLElement)#204 (1) {
["@attributes"] => array(6) {
["date"] => string(10) "2009-09-01"
["hotel"] => string(16) "TOTO1"
["note"] => string(45) "1:5-2:5-3:5-4:2-5:5-6:2-7:5-8:4-9:4-10:1-16:0"
["origin"] => string(5) "email"
["language"] => string(2) "fr"
["confirmationCode"] => string(16) "Max931981dVQPHCM"
}
}
[3] => object(SimpleXMLElement)#205 (1) {
["@attributes"] => array(9) {
["date"] => string(10) "2009-09-06"
["hotel"] => string(16) "TOTO2"
["note"] => string(66) "1:4-2:4-3:3-4:2-5:1-7:1-8:2-9:2-10:0-11:4-12:3-13:4-14:4-15:1-16:1"
["firstName"] => string(7) "Bernard"
["lastName"] => string(8) "salignon"
["country"] => string(2) "fr"
["origin"] => string(12) "distribution"
["language"] => string(2) "fr"
["confirmationCode"] => string(16) "sal610064dVQPHCM"
}
}
obtenu grâce au code suivant :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
/**
	 * 
	 *
	 * @return arrReturn
	 */
	public function buildArray()
	{
		$arrReturn = simplexml_load_string(self::getComments());	
		$count = count($arrReturn);	
		$_tmpArray = array();
 
		for($i=0;$i<$count;$i++){
			$_tmpArray = $arrReturn[$i];
			Zend_Debug::dump($_tmpArray);exit;			
		}
		return (object) $arrReturn;
	}
Je n'arrive pas à obtenir ce que je veux
Citation:
["TOTO1"]
["fr"]
["date"] => string(10) "2009-09-06"
["note"] => string(66) "1:4-2:4-3:3-4:2-5:1-7:1-8:2-9:2-10:0-11:4-12:3-13:4-14:4-15:1-16:1"
["firstName"] => string(7) "Bernard"
["lastName"] => string(8) "salignon"
["origin"] => string(12) "distribution"
["confirmationCode"] => string(16) "sal610064dVQPHCM"

["en"]
["date"] => string(10) "2009-09-06"
["note"] => string(66) "1:4-2:4-3:3-4:2-5:1-7:1-8:2-9:2-10:0-11:4-12:3-13:4-14:4-15:1-16:1"
["firstName"] => string(7) "xxx"
["lastName"] => string(8) "yyyy"
["origin"] => string(12) "email"
["confirmationCode"] => string(16) "sal610064dVQPHCM"

["TOTO2"]
["fr"]
["date"] => string(10) "2009-09-06"
["note"] => string(66) "1:4-2:4-3:3-4:2-5:1-7:1-8:2-9:2-10:0-11:4-12:3-13:4-14:4-15:1-16:1"
["firstName"] => string(7) "Bernard"
["lastName"] => string(8) "salignon"
["origin"] => string(12) "distribution"
["confirmationCode"] => string(16) "sal610064dVQPHCM"

["en"]
["date"] => string(10) "2009-09-06"
["note"] => string(66) "1:4-2:4-3:3-4:2-5:1-7:1-8:2-9:2-10:0-11:4-12:3-13:4-14:4-15:1-16:1"
["firstName"] => string(7) "xxx"
["lastName"] => string(8) "yyyy"
["origin"] => string(12) "email"
["confirmationCode"] => string(16) "sal610064dVQPHCM"
Après plusieurs essais infructueux, je n'arrive pas à obtenir ce que je veux, d'avance merci pour votre aide.
bpdelavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/09/2011, 12h26   #6
Membre du Club
 
Homme Brice
Ingénieur d'études en développements techniques
Inscription : novembre 2005
Messages : 190
Détails du profil
Informations personnelles :
Nom : Homme Brice
Âge : 40
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études en développements techniques
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2005
Messages : 190
Points : 55
Points : 55
Envoyer un message via MSN à bpdelavega
Par défaut Voici le script final pour ceux que ça intéresse

Finalement un très bon copain m'a donné la solution, voici le code pour ceux que ça intéresse :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
/**
	 * 
	 *
	 * @return arrReturn
	 */
	public function buildArray()
	{	
		$arrReturn = simplexml_load_string(self::getComments());
 
		$arrComments = array();
				foreach($arrReturn as $node) {
					$strHotelId = null;
					$strLocale = null;
					$arrHotel = array();
					foreach ($node->attributes() as $strName => $mxdValue) {
						$strValue = (string) $mxdValue;
						switch ($strName) {
							case 'hotel':
								$strHotelId = $strValue;
								break;
 
							case 'language':
								$strLocale = $strValue;
								break;
 
							default:
								$arrHotel[$strName] = $strValue;
						}
 
						if (null != $strHotelId && null != $strLocale) {
							if (!isset($arrComments[$strHotelId])) {
								$arrComments[$strHotelId] = array();
							}
							$arrComments[$strHotelId][$strLocale] = $arrHotel;
						}
					}
				}
 
		Zend_Debug::dump($arrComments);exit;
		return $arrComments;
	}
bpdelavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/09/2011, 14h02   #7
Membre confirmé
 
Homme Bouchery Frédéric
Chef de projet NTIC
Inscription : juillet 2010
Messages : 15
Détails du profil
Informations personnelles :
Nom : Homme Bouchery Frédéric
Âge : 40
Localisation : France, Ille et Vilaine (Bretagne)

Informations professionnelles :
Activité : Chef de projet NTIC

Informations forums :
Inscription : juillet 2010
Messages : 15
Points : 221
Points : 221
Par défaut Pourquoi un tableau

Une question m'intrigue : pourquoi vouloir un tableau, l'arbre objet n'est-il pas suffisant ?
frederic.bouchery est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/09/2011, 16h11   #8
Membre du Club
 
Homme Brice
Ingénieur d'études en développements techniques
Inscription : novembre 2005
Messages : 190
Détails du profil
Informations personnelles :
Nom : Homme Brice
Âge : 40
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études en développements techniques
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2005
Messages : 190
Points : 55
Points : 55
Envoyer un message via MSN à bpdelavega
Parce que ça me simplifie l'appel dans ma vue, je lui passe directement les bons index.
bpdelavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 15h02.


 
 
 
 
Partenaires

Hébergement Web