274 |
jpm |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe implémentant l'API d'eFlore Textes pour le projet WIKIPEDIA.
|
|
|
5 |
*
|
|
|
6 |
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Textes
|
|
|
7 |
*
|
|
|
8 |
* @package eFlore/services
|
|
|
9 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
10 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
11 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
12 |
* @version 1.0
|
|
|
13 |
* @copyright 1999-2012 Tela Botanica (accueil@tela-botanica.org)
|
|
|
14 |
*/
|
|
|
15 |
class Textes {
|
|
|
16 |
|
|
|
17 |
private $parametres = array();
|
|
|
18 |
private $ressources = array();
|
|
|
19 |
|
|
|
20 |
public function consulter($ressources, $parametres) {
|
|
|
21 |
$this->parametres = $parametres;
|
|
|
22 |
$this->ressources = $ressources;
|
|
|
23 |
|
|
|
24 |
$this->analyserRessources();
|
|
|
25 |
$resultat = $this->executerSousService();
|
|
|
26 |
|
|
|
27 |
return $resultat;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
private function analyserRessources() {
|
|
|
31 |
$nbreRessources = count($this->ressources);
|
|
|
32 |
if ($nbreRessources == 0) {
|
|
|
33 |
$message = "A implémenter : listes des pages trouvées";
|
|
|
34 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
35 |
throw new Exception($message, $code);
|
|
|
36 |
} else if ($nbreRessources == 1) {
|
|
|
37 |
if ($this->etreRessourceIdentifiants(0)) {
|
|
|
38 |
$this->sousService = 'Page';
|
|
|
39 |
} else {
|
|
|
40 |
$message = "La ressource n°1 '{$this->ressources[0]} indiquée n'est pas valable.";
|
|
|
41 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
42 |
throw new Exception($message, $code);
|
|
|
43 |
}
|
|
|
44 |
} else if ($nbreRessources > 1) {
|
|
|
45 |
$message = "Les ressources indiquées ne sont pas valables.";
|
|
|
46 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
47 |
throw new Exception($message, $code);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private function etreRessourceIdentifiants($position) {
|
|
|
52 |
$ok = true;
|
|
|
53 |
if (isset($this->ressources[$position])) {
|
|
|
54 |
$ids = $this->ressources[$position];
|
|
|
55 |
$supraSpPattern = "[A-Z][a-z]+";
|
|
|
56 |
$spPattern = "{$supraSpPattern}_[a-z]+";
|
|
|
57 |
$pagePattern = "/^(?:$supraSpPattern|$spPattern)$/i";
|
|
|
58 |
$ok = preg_match($pagePattern, $ids) ? true : false;
|
|
|
59 |
}
|
|
|
60 |
return $ok;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
private function executerSousService() {
|
|
|
64 |
if (isset($this->sousService)) {
|
|
|
65 |
$classe = $this->sousService.'Textes';
|
|
|
66 |
require_once dirname(__FILE__).DS.'textes'.DS.$classe.'.php';
|
|
|
67 |
$sousService = new $classe($this->ressources, $this->parametres, new Conteneur());
|
|
|
68 |
$resultat = $sousService->consulter();
|
|
|
69 |
} else {
|
|
|
70 |
$message = "L'analyse des ressources n'a pu aboutir à déterminer le sous service à exécuter.";
|
|
|
71 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
72 |
throw new Exception($message, $code);
|
|
|
73 |
}
|
|
|
74 |
return $resultat;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
}
|
|
|
79 |
?>
|