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 |
*/
|
536 |
gduche |
15 |
class Textes extends Commun{
|
274 |
jpm |
16 |
|
536 |
gduche |
17 |
protected $parametres = array();
|
|
|
18 |
protected $ressources = array();
|
|
|
19 |
protected $service = 'textes';
|
274 |
jpm |
20 |
|
|
|
21 |
public function consulter($ressources, $parametres) {
|
|
|
22 |
$this->parametres = $parametres;
|
|
|
23 |
$this->ressources = $ressources;
|
|
|
24 |
|
|
|
25 |
$this->analyserRessources();
|
|
|
26 |
$resultat = $this->executerSousService();
|
|
|
27 |
|
|
|
28 |
return $resultat;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
private function analyserRessources() {
|
|
|
32 |
$nbreRessources = count($this->ressources);
|
|
|
33 |
if ($nbreRessources == 0) {
|
|
|
34 |
$message = "A implémenter : listes des pages trouvées";
|
|
|
35 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
36 |
throw new Exception($message, $code);
|
|
|
37 |
} else if ($nbreRessources == 1) {
|
|
|
38 |
if ($this->etreRessourceIdentifiants(0)) {
|
|
|
39 |
$this->sousService = 'Page';
|
|
|
40 |
} else {
|
|
|
41 |
$message = "La ressource n°1 '{$this->ressources[0]} indiquée n'est pas valable.";
|
|
|
42 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
43 |
throw new Exception($message, $code);
|
|
|
44 |
}
|
|
|
45 |
} else if ($nbreRessources > 1) {
|
|
|
46 |
$message = "Les ressources indiquées ne sont pas valables.";
|
|
|
47 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
48 |
throw new Exception($message, $code);
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
private function etreRessourceIdentifiants($position) {
|
|
|
53 |
$ok = true;
|
|
|
54 |
if (isset($this->ressources[$position])) {
|
|
|
55 |
$ids = $this->ressources[$position];
|
|
|
56 |
$supraSpPattern = "[A-Z][a-z]+";
|
|
|
57 |
$spPattern = "{$supraSpPattern}_[a-z]+";
|
|
|
58 |
$pagePattern = "/^(?:$supraSpPattern|$spPattern)$/i";
|
|
|
59 |
$ok = preg_match($pagePattern, $ids) ? true : false;
|
|
|
60 |
}
|
|
|
61 |
return $ok;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
private function executerSousService() {
|
|
|
65 |
if (isset($this->sousService)) {
|
|
|
66 |
$classe = $this->sousService.'Textes';
|
|
|
67 |
require_once dirname(__FILE__).DS.'textes'.DS.$classe.'.php';
|
|
|
68 |
$sousService = new $classe($this->ressources, $this->parametres, new Conteneur());
|
|
|
69 |
$resultat = $sousService->consulter();
|
|
|
70 |
} else {
|
|
|
71 |
$message = "L'analyse des ressources n'a pu aboutir à déterminer le sous service à exécuter.";
|
|
|
72 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
73 |
throw new Exception($message, $code);
|
|
|
74 |
}
|
|
|
75 |
return $resultat;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
}
|
|
|
80 |
?>
|