Subversion Repositories Applications.framework

Rev

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

Rev 246 Rev 248
Line 48... Line 48...
48
	 *
48
	 *
49
	 * @var array available options
49
	 * @var array available options
50
	 */
50
	 */
51
	protected $options = array(
51
	protected $options = array(
52
		'stockage_chemin' => null,
52
		'stockage_chemin' => null,
53
		'fichier_verrou' => true,// file_locking
53
		'fichier_verrou' => true,
54
		'controle_lecture' => true,// controle de lecture
54
		'controle_lecture' => true,
55
		'controle_lecture_type' => 'crc32',
55
		'controle_lecture_type' => 'crc32',
56
		'dossier_niveau' => 0,
56
		'dossier_niveau' => 0,
57
		'dossier_umask' => 0700,
57
		'dossier_umask' => 0700,
58
		'fichier_prefixe' => 'tbf',
58
		'fichier_prefixe' => 'tbf',
59
		'fichier_umask' => 0600,
59
		'fichier_umask' => 0600,
Line 63... Line 63...
63
	/**
63
	/**
64
	 * Array of metadatas (each item is an associative array)
64
	 * Array of metadatas (each item is an associative array)
65
	 *
65
	 *
66
	 * @var array
66
	 * @var array
67
	 */
67
	 */
68
	protected $metadonnees = array(); // metadatasArray
68
	protected $metadonnees = array();
Line 69... Line 69...
69
 
69
 
70
 
70
 
71
	/**
71
	/**
72
	 * Constructor
72
	 * Constructor
73
	 *
73
	 *
74
	 * @param  array $options associative array of options
74
	 * @param  array $options associative array of options
75
	 * @throws Zend_Cache_Exception
75
	 * @throws Zend_Cache_Exception
76
	 * @return void
76
	 * @return void
-
 
77
	 */
-
 
78
	public function __construct(array $options = array()) {
77
	 */
79
		$this->setOptions($options);
78
	public function __construct(array $options = array()) {
80
 
79
		if (isset($this->options['prefixe_fichier'])) {
81
		if (isset($this->options['prefixe_fichier'])) {
80
			if (!preg_match('~^[a-zA-Z0-9_]+$~D', $this->options['prefixe_fichier'])) {
82
			if (!preg_match('~^[a-zA-Z0-9_]+$~D', $this->options['prefixe_fichier'])) {
81
				trigger_error("Préfixe de nom de fichier invalide : doit contenir seulement [a-zA-Z0-9_]", E_USER_WARNING);
83
				trigger_error("Préfixe de nom de fichier invalide : doit contenir seulement [a-zA-Z0-9_]", E_USER_WARNING);
82
			}
84
			}
83
		}
85
		}
84
		if ($this->_options['metadonnees_max_taille'] < 10) {
86
		if ($this->options['metadonnees_max_taille'] < 10) {
85
			trigger_error("Taille du tableau des méta-données invalide, elle doit être > 10", E_USER_WARNING);
87
			trigger_error("Taille du tableau des méta-données invalide, elle doit être > 10", E_USER_WARNING);
86
		}
88
		}
87
		if (isset($options['dossier_umask']) && is_string($options['dossier_umask'])) {
89
		if (isset($options['dossier_umask']) && is_string($options['dossier_umask'])) {
Line 91... Line 93...
91
		if (isset($options['fichier_umask']) && is_string($options['fichier_umask'])) {
93
		if (isset($options['fichier_umask']) && is_string($options['fichier_umask'])) {
92
			// See #ZF-4422
94
			// See #ZF-4422
93
			$this->options['fichier_umask'] = octdec($this->options['fichier_umask']);
95
			$this->options['fichier_umask'] = octdec($this->options['fichier_umask']);
94
		}
96
		}
95
	}
97
	}
-
 
98
	
-
 
99
	private function setOptions($options) {
-
 
100
		while (list($nom, $valeur) = each($options)) {
-
 
101
			if (!is_string($nom)) {
-
 
102
				trigger_error("Nom d'option incorecte : $nom", E_USER_WARNING);
-
 
103
			}
-
 
104
			$nom = strtolower($nom);
-
 
105
			if (array_key_exists($nom, $this->options)) {
-
 
106
				$this->options[$nom] = $valeur;
-
 
107
			}
-
 
108
		}
-
 
109
	}
Line 96... Line 110...
96
 
110
 
97
   	private function setEmplacement($emplacement) {
111
   	public function setEmplacement($emplacement) {
98
		if (!is_dir($emplacement)) {
112
		if (!is_dir($emplacement)) {
99
			trigger_error("L'emplacement doit être un dossier.", E_USER_WARNING);
113
			trigger_error("L'emplacement doit être un dossier.", E_USER_WARNING);
100
		}
114
		}
101
		if (!is_writable($emplacement)) {
115
		if (!is_writable($emplacement)) {
Line 153... Line 167...
153
	 * @param  string $id			   Cache id
167
	 * @param  string $id			   Cache id
154
	 * @param  array  $tags			 Array of strings, the cache record will be tagged by each string entry
168
	 * @param  array  $tags			 Array of strings, the cache record will be tagged by each string entry
155
	 * @param  int	$specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
169
	 * @param  int	$specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
156
	 * @return boolean true if no problem
170
	 * @return boolean true if no problem
157
	 */
171
	 */
158
	public function save($data, $id, $tags = array(), $specificLifetime = false) {
172
	public function sauver($donnees, $id, $tags = array(), $duree_vie_specifique = false) {
159
		clearstatcache();
173
		clearstatcache();
160
		$file = $this->getFichierNom($id);
174
		$fichier = $this->getFichierNom($id);
161
		$path = $this->getChemin($id);
175
		$chemin = $this->getChemin($id);
-
 
176
		
-
 
177
		$resultat = true;
162
		if ($this->_options['hashed_directory_level'] > 0) {
178
		if ($this->options['dossier_niveau'] > 0) {
163
			if (!is_writable($path)) {
179
			if (!is_writable($chemin)) {
164
				// maybe, we just have to build the directory structure
180
				// maybe, we just have to build the directory structure
165
				$this->lancerMkdirEtChmodRecursif($id);
181
				$this->lancerMkdirEtChmodRecursif($id);
166
			}
182
			}
167
			if (!is_writable($path)) {
183
			if (!is_writable($chemin)) {
168
				return false;
184
				$resultat = false;
169
			}
185
			}
170
		}
186
		}
-
 
187
		
-
 
188
		if ($resultat === true) {
171
		if ($this->_options['read_control']) {
189
			if ($this->options['controle_lecture']) {
172
			$hash = $this->genererCleSecu($data, $this->_options['read_control_type']);
190
				$cle_secu = $this->genererCleSecu($donnees, $this->options['controle_lecture_type']);
173
		} else {
191
			} else {
174
			$hash = '';
192
				$cle_secu = '';
175
		}
193
			}
-
 
194
			
176
		$metadatas = array(
195
			$metadonnees = array(
177
			'hash' => $hash,
196
				'hash' => $cle_secu,
178
			'mtime' => time(),
197
				'mtime' => time(),
179
			'expire' => $this->_expireTime($this->getLifetime($specificLifetime)),
198
				'expiration' => $this->getTimestampExpiration($duree_vie_specifique),
180
			'tags' => $tags
199
				'tags' => $tags
181
		);
200
			);
-
 
201
 
182
		$res = $this->_setMetadatas($id, $metadatas);
202
			if (! $resultat = $this->setMetadonnees($id, $metadonnees)) {
-
 
203
				// TODO : ajouter un log
183
		if (!$res) {
204
			} else {
184
			$this->_log('Zend_Cache_Backend_File::save() / error on saving metadata');
205
				$resultat = $this->setContenuFichier($fichier, $donnees);
185
			return false;
206
			}
186
		}
207
		}
187
		$res = $this->setContenuFichier($file, $data);
-
 
188
		return $res;
208
		return $resultat;
189
	}
209
	}
Line 190... Line 210...
190
 
210
 
191
	/**
211
	/**
192
	 * Remove a cache record
212
	 * Remove a cache record
Line 219... Line 239...
219
	 * @return boolean true if no problem
239
	 * @return boolean true if no problem
220
	 */
240
	 */
221
	public function nettoyer($mode = Cache::NETTOYAGE_MODE_TOUS, $tags = array()) {
241
	public function nettoyer($mode = Cache::NETTOYAGE_MODE_TOUS, $tags = array()) {
222
		// We use this protected method to hide the recursive stuff
242
		// We use this protected method to hide the recursive stuff
223
		clearstatcache();
243
		clearstatcache();
224
		return $this->nettoyerFichiers($this->options['stockage_dossier'], $mode, $tags);
244
		return $this->nettoyerFichiers($this->options['stockage_chemin'], $mode, $tags);
225
	}
245
	}
Line 226... Line 246...
226
 
246
 
227
	/**
247
	/**
228
	 * Return an array of stored cache ids
248
	 * Return an array of stored cache ids
229
	 *
249
	 *
230
	 * @return array array of stored cache ids (string)
250
	 * @return array array of stored cache ids (string)
231
	 */
251
	 */
232
	public function getIds()
-
 
233
	{
252
	public function getIds() {
234
		return $this->_get($this->_options['cache_dir'], 'ids', array());
253
		return $this->analyserCache($this->options['stockage_chemin'], 'ids', array());
Line 235... Line 254...
235
	}
254
	}
236
 
255
 
237
	/**
256
	/**
238
	 * Return an array of stored tags
257
	 * Return an array of stored tags
239
	 *
258
	 *
240
	 * @return array array of stored tags (string)
259
	 * @return array array of stored tags (string)
241
	 */
-
 
242
	public function getTags()
260
	 */
243
	{
261
	public function getTags() {
Line 244... Line 262...
244
		return $this->_get($this->_options['cache_dir'], 'tags', array());
262
		return $this->analyserCache($this->options['stockage_chemin'], 'tags', array());
245
	}
263
	}
246
 
264
 
247
	/**
265
	/**
248
	 * Return an array of stored cache ids which match given tags
266
	 * Return an array of stored cache ids which match given tags
249
	 *
267
	 *
250
	 * In case of multiple tags, a logical AND is made between tags
268
	 * In case of multiple tags, a logical AND is made between tags
251
	 *
269
	 *
252
	 * @param array $tags array of tags
270
	 * @param array $tags array of tags
253
	 * @return array array of matching cache ids (string)
-
 
254
	 */
271
	 * @return array array of matching cache ids (string)
255
	public function getIdsMatchingTags($tags = array())
272
	 */
Line 256... Line 273...
256
	{
273
	public function getIdsAvecLesTags($tags = array()) {
257
		return $this->_get($this->_options['cache_dir'], 'matching', $tags);
274
		return $this->analyserCache($this->options['stockage_chemin'], 'matching', $tags);
258
	}
275
	}
259
 
276
 
260
	/**
277
	/**
261
	 * Return an array of stored cache ids which don't match given tags
278
	 * Return an array of stored cache ids which don't match given tags
262
	 *
279
	 *
263
	 * In case of multiple tags, a logical OR is made between tags
280
	 * In case of multiple tags, a logical OR is made between tags
264
	 *
281
	 *
265
	 * @param array $tags array of tags
-
 
266
	 * @return array array of not matching cache ids (string)
282
	 * @param array $tags array of tags
267
	 */
283
	 * @return array array of not matching cache ids (string)
Line 268... Line 284...
268
	public function getIdsNotMatchingTags($tags = array())
284
	 */
269
	{
285
	public function getIdsSansLesTags($tags = array()) {
270
		return $this->_get($this->_options['cache_dir'], 'notMatching', $tags);
286
		return $this->analyserCache($this->options['stockage_chemin'], 'notMatching', $tags);
271
	}
287
	}
272
 
288
 
273
	/**
289
	/**
274
	 * Return an array of stored cache ids which match any given tags
290
	 * Return an array of stored cache ids which match any given tags
275
	 *
291
	 *
276
	 * In case of multiple tags, a logical AND is made between tags
292
	 * In case of multiple tags, a logical AND is made between tags
277
	 *
-
 
278
	 * @param array $tags array of tags
293
	 *
279
	 * @return array array of any matching cache ids (string)
294
	 * @param array $tags array of tags
Line 280... Line 295...
280
	 */
295
	 * @return array array of any matching cache ids (string)
281
	public function getIdsMatchingAnyTags($tags = array())
296
	 */
282
	{
297
	public function getIdsAvecUnTag($tags = array()) {
283
		return $this->_get($this->_options['cache_dir'], 'matchingAny', $tags);
298
		return $this->analyserCache($this->options['stockage_chemin'], 'matchingAny', $tags);
284
	}
299
	}
285
 
300
 
286
	/**
301
	/**
287
	 * Return the filling percentage of the backend storage
-
 
288
	 *
302
	 * Return the filling percentage of the backend storage
289
	 * @throws Zend_Cache_Exception
303
	 *
-
 
304
	 * @throws Zend_Cache_Exception
-
 
305
	 * @return int integer between 0 and 100
290
	 * @return int integer between 0 and 100
306
	 */
291
	 */
307
	public function getPourcentageRemplissage() {
292
	public function getFillingPercentage()
308
		$libre = disk_free_space($this->options['sotckage_chemin']);
293
	{
-
 
294
		$free = disk_free_space($this->_options['cache_dir']);
-
 
295
		$total = disk_total_space($this->_options['cache_dir']);
-
 
296
		if ($total == 0) {
309
		$total = disk_total_space($this->options['sotckage_chemin']);
297
			Zend_Cache::throwException('can\'t get disk_total_space');
310
		
-
 
311
		$pourcentage = 0;
298
		} else {
312
		if ($total == 0) {
Line 299... Line 313...
299
			if ($free >= $total) {
313
			trigger_error("Impossible d'utiliser la fonction disk_total_space", E_USER_WARNING);
300
				return 100;
314
		} else {
301
			}
315
			$pourcentage = ($libre >= $total) ? 100 : ((int) (100. * ($total - $libre) / $total));
Line 312... Line 326...
312
	 * - mtime : timestamp of last modification time
326
	 * - mtime : timestamp of last modification time
313
	 *
327
	 *
314
	 * @param string $id cache id
328
	 * @param string $id cache id
315
	 * @return array array of metadatas (false if the cache id is not found)
329
	 * @return array array of metadatas (false if the cache id is not found)
316
	 */
330
	 */
317
	public function getMetadatas($id)
331
	public function getMetadonnees($id) {
318
	{
-
 
319
		$metadatas = $this->getMetadonneesFichier($id);
332
		if ($metadonnees = $this->getMetadonneesFichier($id)) {
320
		if (!$metadatas) {
333
			if (time() > $metadonnees['expiration']) {
321
			return false;
334
				$metadonnees = false;
322
		}
335
			} else {
-
 
336
				$metadonnees = array(
-
 
337
					'expiration' => $metadonnees['expiration'],
-
 
338
					'tags' => $metadonnees['tags'],
323
		if (time() > $metadatas['expire']) {
339
					'mtime' => $metadonnees['mtime']
324
			return false;
340
				);
-
 
341
			}
325
		}
342
		}
-
 
343
		
326
		return array(
344
		return $metadonnees;
327
			'expire' => $metadatas['expire'],
-
 
328
			'tags' => $metadatas['tags'],
-
 
329
			'mtime' => $metadatas['mtime']
-
 
330
		);
-
 
331
	}
345
	}
Line 332... Line 346...
332
 
346
 
333
	/**
347
	/**
334
	 * Give (if possible) an extra lifetime to the given cache id
348
	 * Give (if possible) an extra lifetime to the given cache id
335
	 *
349
	 *
336
	 * @param string $id cache id
350
	 * @param string $id cache id
337
	 * @param int $extraLifetime
351
	 * @param int $extraLifetime
338
	 * @return boolean true if ok
352
	 * @return boolean true if ok
339
	 */
353
	 */
340
	public function touch($id, $extraLifetime)
354
	public function ajouterSupplementDureeDeVie($id, $supplement_duree_de_vie) {
341
	{
355
		$augmentation = true;
342
		$metadatas = $this->getMetadonneesFichier($id);
-
 
343
		if (!$metadatas) {
-
 
344
			return false;
-
 
345
		}
356
		if ($metadonnees = $this->getMetadonneesFichier($id)) {
346
		if (time() > $metadatas['expire']) {
357
			if (time() > $metadonnees['expiration']) {
347
			return false;
358
				$augmentation = false;
348
		}
359
			} else {
349
		$newMetadatas = array(
360
				$metadonnees_nouvelle = array(
350
			'hash' => $metadatas['hash'],
361
					'hash' => $metadonnees['hash'],
351
			'mtime' => time(),
362
					'mtime' => time(),
352
			'expire' => $metadatas['expire'] + $extraLifetime,
363
					'expiration' => $metadonnees['expiration'] + $supplement_duree_de_vie,
353
			'tags' => $metadatas['tags']
364
					'tags' => $metadonnees['tags']
354
		);
365
				);
355
		$res = $this->_setMetadatas($id, $newMetadatas);
-
 
356
		if (!$res) {
366
				$augmentation = $this->setMetadonnees($id, $metadonnees_nouvelle);
357
			return false;
367
			}
358
		}
368
		}
359
		return true;
369
		return $augmentation;
Line 360... Line 370...
360
	}
370
	}
361
 
371
 
362
	/**
372
	/**
Line 525... Line 535...
525
		}
535
		}
526
		foreach ($glob as $fichier)  {
536
		foreach ($glob as $fichier)  {
527
			if (is_file($fichier)) {
537
			if (is_file($fichier)) {
528
				$fichier_nom = basename($fichier);
538
				$fichier_nom = basename($fichier);
529
				if ($this->etreFichierMeta($fichier_nom)) {
539
				if ($this->etreFichierMeta($fichier_nom)) {
530
					// in CLEANING_MODE_ALL, we drop anything, even remainings old metadatas files
540
					// Pour le mode Cache::NETTOYAGE_MODE_TOUS, nous essayons de tous supprimer même les vieux fichiers méta
531
					if ($mode != Cache::NETTOYAGE_MODE_TOUS) {
541
					if ($mode != Cache::NETTOYAGE_MODE_TOUS) {
532
						continue;
542
						continue;
533
					}
543
					}
534
				}
544
				}
535
				$id = $this->transformerNomFichierEnId($fichier_nom);
545
				$id = $this->transformerNomFichierEnId($fichier_nom);
536
				$metadatas = $this->getMetadonneesFichier($id);
546
				$metadonnees = $this->getMetadonneesFichier($id);
537
				if ($metadatas === FALSE) {
547
				if ($metadonnees === FALSE) {
538
					$metadatas = array('expire' => 1, 'tags' => array());
548
					$metadonnees = array('expiration' => 1, 'tags' => array());
539
				}
549
				}
540
				switch ($mode) {
550
				switch ($mode) {
541
					case Zend_Cache::CLEANING_MODE_ALL:
551
					case Cache::NETTOYAGE_MODE_TOUS :
542
						$res = $this->remove($id);
552
						if ($resultat_suppression = $this->supprimer($id)) {
543
						if (!$res) {
-
 
544
							// in this case only, we accept a problem with the metadatas file drop
553
							// Dans ce cas seulement, nous acception qu'il y ait un problème avec la suppresssion du fichier meta
545
							$res = $this->supprimerFichier($file);
554
							$resultat_suppression = $this->supprimerFichier($fichier);
546
						}
555
						}
547
						$resultat = $resultat && $res;
556
						$resultat = $resultat && $resultat_suppression;
548
						break;
557
						break;
549
					case Zend_Cache::CLEANING_MODE_OLD:
558
					case Cache::NETTOYAGE_MODE_EXPIRATION :
550
						if (time() > $metadatas['expire']) {
559
						if (time() > $metadonnees['expiration']) {
551
							$resultat = $this->remove($id) && $resultat;
560
							$resultat = $this->supprimer($id) && $resultat;
552
						}
561
						}
553
						break;
562
						break;
554
					case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
563
					case Cache::NETTOYAGE_MODE_AVEC_LES_TAGS :
555
						$matching = true;
564
						$correspondance = true;
556
						foreach ($tags as $tag) {
565
						foreach ($tags as $tag) {
557
							if (!in_array($tag, $metadatas['tags'])) {
566
							if (!in_array($tag, $metadonnees['tags'])) {
558
								$matching = false;
567
								$correspondance = false;
559
								break;
568
								break;
560
							}
569
							}
561
						}
570
						}
562
						if ($matching) {
571
						if ($correspondance) {
563
							$resultat = $this->remove($id) && $resultat;
572
							$resultat = $this->supprimer($id) && $resultat;
564
						}
573
						}
565
						break;
574
						break;
566
					case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
575
					case Cache::NETTOYAGE_MODE_SANS_LES_TAGS :
567
						$matching = false;
576
						$correspondance = false;
568
						foreach ($tags as $tag) {
577
						foreach ($tags as $tag) {
569
							if (in_array($tag, $metadatas['tags'])) {
578
							if (in_array($tag, $metadonnees['tags'])) {
570
								$matching = true;
579
								$correspondance = true;
571
								break;
580
								break;
572
							}
581
							}
573
						}
582
						}
574
						if (!$matching) {
583
						if (!$correspondance) {
575
							$resultat = $this->remove($id) && $resultat;
584
							$resultat = $this->supprimer($id) && $resultat;
576
						}
585
						}
577
						break;
586
						break;
578
					case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
587
					case Cache::NETTOYAGE_MODE_AVEC_UN_TAG :
579
						$matching = false;
588
						$correspondance = false;
580
						foreach ($tags as $tag) {
589
						foreach ($tags as $tag) {
581
							if (in_array($tag, $metadatas['tags'])) {
590
							if (in_array($tag, $metadonnees['tags'])) {
582
								$matching = true;
591
								$correspondance = true;
583
								break;
592
								break;
584
							}
593
							}
585
						}
594
						}
586
						if ($matching) {
595
						if ($correspondance) {
587
							$resultat = $this->remove($id) && $resultat;
596
							$resultat = $this->supprimer($id) && $resultat;
588
						}
597
						}
589
						break;
598
						break;
590
					default:
599
					default:
591
						Zend_Cache::throwException('Invalid mode for clean() method');
600
						trigger_error("Mode de nettoyage invalide pour la méthode nettoyer()", E_USER_WARNING);
592
						break;
601
						break;
593
				}
602
				}
594
			}
603
			}
595
			if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
604
			if ((is_dir($fichier)) and ($this->options['dossier_niveau'] > 0)) {
596
				// Recursive call
605
				// Appel récursif
597
				$resultat = $this->nettoyerFichiers($file . DIRECTORY_SEPARATOR, $mode, $tags) && $resultat;
606
				$resultat = $this->nettoyerFichiers($fichier.DS, $mode, $tags) && $resultat;
598
				if ($mode=='all') {
607
				if ($mode == Cache::NETTOYAGE_MODE_TOUS) {
599
					// if mode=='all', we try to drop the structure too
608
					// Si mode == Cache::NETTOYAGE_MODE_TOUS, nous essayons de supprimer la structure aussi
600
					@rmdir($file);
609
					@rmdir($fichier);
601
				}
610
				}
602
			}
611
			}
603
		}
612
		}
604
		return $resultat;
613
		return $resultat;
605
	}
614
	}
Line 606... Line 615...
606
 
615
 
607
	protected function _get($dir, $mode, $tags = array()) {
616
	protected function analyserCache($dossier, $mode, $tags = array()) {
608
		if (!is_dir($dir)) {
617
		if (!is_dir($dossier)) {
609
			return false;
618
			return false;
610
		}
619
		}
611
		$result = array();
620
		$resultat = array();
612
		$prefix = $this->_options['file_name_prefix'];
621
		$prefixe = $this->options['fichier_prefixe'];
613
		$glob = @glob($dir . $prefix . '--*');
622
		$glob = @glob($dossier.$prefixe.'--*');
614
		if ($glob === false) {
623
		if ($glob === false) {
615
			// On some systems it is impossible to distinguish between empty match and an error.
624
			// On some systems it is impossible to distinguish between empty match and an error.
616
			return array();
625
			return array();
617
		}
626
		}
618
		foreach ($glob as $file)  {
627
		foreach ($glob as $fichier)  {
619
			if (is_file($file)) {
628
			if (is_file($fichier)) {
620
				$fileName = basename($file);
629
				$nom_fichier = basename($fichier);
621
				$id = $this->transformerNomFichierEnId($fileName);
630
				$id = $this->transformerNomFichierEnId($nom_fichier);
622
				$metadatas = $this->getMetadonneesFichier($id);
631
				$metadonnees = $this->getMetadonneesFichier($id);
623
				if ($metadatas === FALSE) {
632
				if ($metadonnees === FALSE) {
624
					continue;
633
					continue;
625
				}
634
				}
626
				if (time() > $metadatas['expire']) {
635
				if (time() > $metadonnees['expiration']) {
627
					continue;
636
					continue;
628
				}
637
				}
629
				switch ($mode) {
638
				switch ($mode) {
630
					case 'ids':
639
					case 'ids':
631
						$result[] = $id;
640
						$resultat[] = $id;
632
						break;
641
						break;
633
					case 'tags':
642
					case 'tags':
634
						$result = array_unique(array_merge($result, $metadatas['tags']));
643
						$resultat = array_unique(array_merge($resultat, $metadonnees['tags']));
635
						break;
644
						break;
636
					case 'matching':
645
					case 'matching':
637
						$matching = true;
646
						$correspondance = true;
638
						foreach ($tags as $tag) {
647
						foreach ($tags as $tag) {
639
							if (!in_array($tag, $metadatas['tags'])) {
648
							if (!in_array($tag, $metadonnees['tags'])) {
640
								$matching = false;
649
								$correspondance = false;
641
								break;
650
								break;
642
							}
651
							}
643
						}
652
						}
644
						if ($matching) {
653
						if ($correspondance) {
645
							$result[] = $id;
654
							$resultat[] = $id;
646
						}
655
						}
647
						break;
656
						break;
648
					case 'notMatching':
657
					case 'notMatching':
649
						$matching = false;
658
						$correspondance = false;
650
						foreach ($tags as $tag) {
659
						foreach ($tags as $tag) {
651
							if (in_array($tag, $metadatas['tags'])) {
660
							if (in_array($tag, $metadonnees['tags'])) {
652
								$matching = true;
661
								$correspondance = true;
653
								break;
662
								break;
654
							}
663
							}
655
						}
664
						}
656
						if (!$matching) {
665
						if (!$correspondance) {
657
							$result[] = $id;
666
							$resultat[] = $id;
658
						}
667
						}
659
						break;
668
						break;
660
					case 'matchingAny':
669
					case 'matchingAny':
661
						$matching = false;
670
						$correspondance = false;
662
						foreach ($tags as $tag) {
671
						foreach ($tags as $tag) {
663
							if (in_array($tag, $metadatas['tags'])) {
672
							if (in_array($tag, $metadonnees['tags'])) {
664
								$matching = true;
673
								$correspondance = true;
665
								break;
674
								break;
666
							}
675
							}
667
						}
676
						}
668
						if ($matching) {
677
						if ($correspondance) {
669
							$result[] = $id;
678
							$resultat[] = $id;
670
						}
679
						}
671
						break;
680
						break;
672
					default:
681
					default:
673
						Zend_Cache::throwException('Invalid mode for _get() method');
682
						trigger_error("Mode invalide pour la méthode analyserCache()", E_USER_WARNING);
674
						break;
683
						break;
675
				}
684
				}
676
			}
685
			}
677
			if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
686
			if ((is_dir($fichier)) and ($this->options['dossier_niveau'] > 0)) {
678
				// Recursive call
687
				// Appel récursif
679
				$recursiveRs =  $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags);
688
				$resultat_analyse_recursive = $this->analyserCache($fichier.DS, $mode, $tags);
680
				if ($recursiveRs === false) {
689
				if ($resultat_analyse_recursive === false) {
681
					$this->_log('Zend_Cache_Backend_File::_get() / recursive call : can\'t list entries of "'.$file.'"');
690
					// TODO : ajoute un log
682
				} else {
691
				} else {
683
					$result = array_unique(array_merge($result, $recursiveRs));
692
					$resultat = array_unique(array_merge($resultat, $resultat_analyse_recursive));
684
				}
693
				}
685
			}
694
			}
686
		}
695
		}
687
		return array_unique($result);
696
		return array_unique($resultat);
Line 688... Line 697...
688
	}
697
	}
689
 
698
 
690
	/**
699
	/**
691
	 * Compute & return the expire time
700
	 * Compute & return the expire time
692
	 *
701
	 *
693
	 * @return int expire time (unix timestamp)
702
	 * @return int expire time (unix timestamp)
694
	 */
703
	 */
695
	protected function _expireTime($lifetime) {
704
	protected function getTimestampExpiration($duree_de_vie) {
696
		if ($lifetime === null) {
705
		if ($duree_de_vie === false) {
-
 
706
			$duree_de_vie = 3600;
697
			return 9999999999;
707
		}
698
		}
708
		$timestamp = ($duree_de_vie === null) ? 9999999999 : (time() + $duree_de_vie);
Line 699... Line 709...
699
		return time() + $lifetime;
709
		return $timestamp;
700
	}
710
	}
701
 
711
 
Line 728... Line 738...
728
	 * @param  string $id Cache id
738
	 * @param  string $id Cache id
729
	 * @return string File name
739
	 * @return string File name
730
	 */
740
	 */
731
	protected function transformaterIdEnNomFichier($id) {
741
	protected function transformaterIdEnNomFichier($id) {
732
		$prefixe = $this->options['fichier_prefixe'];
742
		$prefixe = $this->options['fichier_prefixe'];
733
		$resulta = $prefixe.'---'.$id;
743
		$resultat = $prefixe.'---'.$id;
734
		return $resultat;
744
		return $resultat;
735
	}
745
	}
Line 736... Line 746...
736
 
746
 
737
	/**
747
	/**
Line 758... Line 768...
758
		$chemin = $this->options['stockage_chemin'];
768
		$chemin = $this->options['stockage_chemin'];
759
		$prefixe = $this->options['fichier_prefixe'];
769
		$prefixe = $this->options['fichier_prefixe'];
760
		if ($this->options['dossier_niveau'] > 0) {
770
		if ($this->options['dossier_niveau'] > 0) {
761
			$hash = hash('adler32', $id);
771
			$hash = hash('adler32', $id);
762
			for ($i = 0 ; $i < $this->options['dossier_niveau'] ; $i++) {
772
			for ($i = 0 ; $i < $this->options['dossier_niveau'] ; $i++) {
763
				$chemin .= $prefix.'--'.substr($hash, 0, $i + 1).DS;
773
				$chemin .= $prefixe.'--'.substr($hash, 0, $i + 1).DS;
764
				$morceaux[] = $chemin;
774
				$morceaux[] = $chemin;
765
			}
775
			}
766
		}
776
		}
767
		return ($decoupage) ? 	$morceaux : $chemin;
777
		return ($decoupage) ? 	$morceaux : $chemin;
768
	}
778
	}