| 723 |
gduche |
1 |
<?php
|
| 1794 |
jpm |
2 |
// declare(encoding='UTF-8');
|
| 723 |
gduche |
3 |
/**
|
| 1794 |
jpm |
4 |
* Gère les paramètres de type "masque..." utilisés dans l'URL.
|
|
|
5 |
*
|
|
|
6 |
* @category DEL
|
|
|
7 |
* @package Services
|
|
|
8 |
* @subpackage Bibliotheque
|
|
|
9 |
* @version 0.1
|
|
|
10 |
* @author Mathias CHOUET <mathias@tela-botanica.org>
|
|
|
11 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
12 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
|
|
13 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.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>
|
| 723 |
gduche |
16 |
*/
|
|
|
17 |
class Masque {
|
| 1793 |
jpm |
18 |
|
| 1794 |
jpm |
19 |
const PREFIXE = 'masque.';
|
|
|
20 |
const MASQUE_GENERAL = 'masque';
|
| 1793 |
jpm |
21 |
|
| 723 |
gduche |
22 |
private $masquesPossibles;
|
| 1795 |
jpm |
23 |
private $parametresUrl;
|
| 723 |
gduche |
24 |
private $masque;
|
| 1793 |
jpm |
25 |
|
| 723 |
gduche |
26 |
/**
|
|
|
27 |
* Constructeur de la classe Masque
|
|
|
28 |
* @param $masquesPossibles la liste des masques autorisés séparé par des ','
|
|
|
29 |
* */
|
| 1795 |
jpm |
30 |
public function __construct($masquesPossibles, $parametresUrl = null) {
|
| 817 |
aurelien |
31 |
if ($masquesPossibles != null && trim($masquesPossibles) == '') {
|
| 723 |
gduche |
32 |
$message = 'La liste des masques possibles est obligatoire';
|
|
|
33 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
|
|
34 |
throw new Exception($message, $code);
|
|
|
35 |
}
|
|
|
36 |
$this->masquesPossibles = explode(',', $masquesPossibles);
|
| 1795 |
jpm |
37 |
$this->parametresUrl = $parametresUrl;
|
| 723 |
gduche |
38 |
$this->chargerMasque();
|
|
|
39 |
}
|
| 1793 |
jpm |
40 |
|
| 723 |
gduche |
41 |
/**
|
|
|
42 |
* Parcourir le tableau Paramètres pour trouver tous les champs masque
|
|
|
43 |
*/
|
| 1794 |
jpm |
44 |
private function chargerMasque() {
|
| 1795 |
jpm |
45 |
if ($this->parametresUrl != null) {
|
|
|
46 |
foreach ($this->parametresUrl as $id => $parametre) {
|
|
|
47 |
if (in_array(str_replace(self::PREFIXE, '', $id), $this->masquesPossibles)) {
|
|
|
48 |
$this->masque[$id] = $parametre;
|
| 723 |
gduche |
49 |
}
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
}
|
| 1793 |
jpm |
53 |
|
| 723 |
gduche |
54 |
/**
|
|
|
55 |
* Retourner les masques sous forme de chaine
|
| 1795 |
jpm |
56 |
* @return String la chaine de caractère sous la forme masque=valeur&masque2=valeur
|
|
|
57 |
*/
|
| 723 |
gduche |
58 |
public function getChaineMasque() {
|
| 1795 |
jpm |
59 |
return (!empty($this->masque)) ? http_build_query($this->masque) : '';
|
| 723 |
gduche |
60 |
}
|
| 1793 |
jpm |
61 |
|
| 723 |
gduche |
62 |
/**
|
|
|
63 |
* Récupérer tout ou partie du masque
|
|
|
64 |
* @param String $id (optionnel) l'idenfiant du masque
|
|
|
65 |
* @return une chaine de caractère si l'identifiant est passé en paramètre, un tableau sinon
|
|
|
66 |
* */
|
|
|
67 |
public function getMasque($id = null) {
|
| 1795 |
jpm |
68 |
return isset($id) ? $this->masque[self::PREFIXE.$id] : $this->masque;
|
| 723 |
gduche |
69 |
}
|
| 1793 |
jpm |
70 |
}
|