-
Notifications
You must be signed in to change notification settings - Fork 16
/
coord.gtw
102 lines (60 loc) · 5.31 KB
/
coord.gtw
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
~~LANG:EN@enman:plugins/coord~~
Il est possible d'ajouter des plugins au [[/coordinateur|coordinateur]] (le coeur de Jelix, jCoordinator) qui permettent de faire des traitements supplémentaires à différentes étapes de l'exécution d'une action, quelle que soit cette action.
Il est ainsi possible d'effectuer un traitement au démarrage du processus, juste avant l'exécution de l'action, juste après (avant affichage), et en fin de processus.
Les plugins pour le coordinateur sont aussi appelés //plugins coord// dans le jargon Jelix.
===== Utilisation d'un plugin coord =====
==== Déclaration ====
Pour activer un plugin coord, vous avez deux choses à faire dans le fichier de configuration d'un point d'entrée :
* bien sûr, [[/plugins#declaration-d-un-depot-de-plugins|déclarer le dépôt]] contenant le répertoire de votre plugin, dans l'option //pluginsPath// de la configuration
* indiquer le plugin dans la section [coordplugins], ainsi que son éventuel fichier de configuration
Si vous placez votre plugin //foo// dans votreApplication/plugins/coord/ alors vous devez déclarer comme ceci :
<code ini>
pluginsPath = app:plugins/
[coordplugins]
foo = foo.coord.ini.php
</code>
Ici on indique un fichier de configuration //foo.coord.ini.php// pour le plugin (le contenu et la structure de ce fichier de configuration dépend totalement du plugin). Dans le cas où votre plugin ne comporte pas de fichier de configuration, vous devez mettre //1// au lieu d'un nom de fichier, comme ceci :
<code ini>
foo = 1
</code>
Si vous utilisez plusieurs plugins de coordinateur, l'ordre de déclaration des plugins dans le fichier de configuration a une importance. Ainsi le premier plugin déclaré à la priorité sur les autres. C'est à dire que si ce premier plugin renvoie une action, les autres plugins ne seront pas exécutés. Il convient donc de choisir l'ordre de déclaration des plugins en fonction de la priorité que l'on veut pour chaque plugin. Par exemple si vous considérez que le plugin //bar// ne peut être exécuté que si le plugin //foo// n'a pas renvoyé d'action, alors il faudrait les déclarer comme ceci :
<code ini>
[coordplugins]
foo = foo.plugin.ini.php
bar = 1
</code>
==== Configuration ====
Un plugin coord peut avoir besoin d'un fichier de configuration. Ce fichier doit être alors un fichier de type //ini//, placé dans votreApplication/var/config/ et être déclaré dans la configuration comme indiqué précédemment. Le contenu ini sera passé au constructeur du plugin sous forme de tableau (résultat de la fonction php parse_ini_file).
==== Paramètres de plugins ====
Certains plugins coord peuvent attendre des paramètres qui sont fournis par les contrôleurs. En effet, un plugin peut vouloir tester quelque chose en fonction de l'action. Par exemple, le plugin coord d'authentification //auth// va vérifier si l'action demandée nécessite ou non d'être authentifié. Pour cela, on va indiquer dans chaque contrôleur un paramètre pour chaque action, destiné au plugin auth, qui indique cette information.
Ces paramètres sont stockés dans la propriété pluginParams du contrôleur. C'est un tableau associatif. Les clés sont les noms des méthodes, et les valeurs, un tableau contenant tous les paramètres de plugins associés à la méthode (et donc à l'action correspondante). Une clé particulière, '*', indique les paramètres valables pour toutes les méthodes du contrôleur.
Exemple :
<code php>
public $pluginParams = array(
'*'=>array('auth.required'=>false)
);
</code>
Indique que toutes les actions du contrôleur ont un paramètre nommé "auth.required" et valant false.
==== Exemples de plugins ====
== magicquotes ==
Il sert à traiter les magicquotes sur les serveurs où ces magic quotes sont activés. Pas de configuration pour ce plugin.
<code ini>
[coordplugins]
magicquotes = 1
</code>
===== Développement d'un plugin coord =====
Un plugin est en fait une classe qui implémente l'interface //jICoordPlugin//. Cette classe doit donc implémenter les méthodes suivantes :
<code php>
public function __construct($config);
public function beforeAction($params);
public function beforeOutput();
public function afterProcess ();
</code>
Le constructeur reçoit la configuration du plugin.
La méthode //beforeAction// reçoit les paramètres de plugins déclarés dans le contrôleur. Elle peut renvoyer //null// si tout est ok ou alors un sélecteur d'action, //jSelectorAct//, si il faut exécuter une autre action que celle prévue.
La méthode //beforeOutput// sera appelée après exécution de l'action.
Le méthode //afterProcess// sera appelée en fin de traitement (après affichage donc).
Cette classe est à placer dans un [[/plugins#declaration-d-un-depot-de-plugins|dépôt de plugins]]. Par exemple, le répertoire //plugins/// de votre application. Ou alors dans un répertoire //plugins/// d'un module. Le sous répertoire dans lequel est placé le plugin doit porter le nom du plugin, et la classe doit suivre un nommage particulier. Si le plugin s'appelle //exemple//, alors :
* le répertoire du plugin sera **plugins/coord/exemple/**
* le fichier contenant la classe du plugin devra être **plugins/coord/exemple/exemple.coord.php**
* le nom de la classe du plugin devra être **exempleCoordPlugin**, implémentant l'interface **jICoordPlugin**