2020require_once __DIR__ . '/../../core/php/core.inc.php ' ;
2121
2222/**
23- * Gère les réponses AJAX de Jeedom
23+ * Handles AJAX responses in Jeedom
2424 *
25- * @note Évolutions possibles et compatibles
26- * Cette classe pourrait être enrichie progressivement avec :
27- * - Une interface ResponseFormatterInterface pour supporter différents formats (json, xml...)
28- * - Un système de middleware pour la validation des entrées
29- * - Des codes d'erreur HTTP standards via une énumération
30- * Ces changements peuvent être implémentés graduellement sans casser l'existant
25+ * @example
26+ * ajax::init(['getInfos']); // returns void
27+ * ajax::success(['result' => 'ok']); // sends JSON response
3128 *
32- * @example Utilisation actuelle
33- * ```php
34- * ajax::init(['getInfos']);
35- * ajax::success($data);
36- * ```
37- *
38- * @example Utilisation future possible
39- * ```php
40- * // Même API, plus de fonctionnalités
41- * ajax::init(['getInfos'])
42- * ->withValidator(new InputValidator())
43- * ->withFormat(new JsonFormatter());
44- * ajax::success($data);
45- * ```
46- *
47- * @see config::class Pour la gestion des configurations
48- * @see log::class Pour la gestion des logs
49- *
50- * @todo Version 4.6 ou 5.0
51- * - [OPTIONNEL] Ajouter un système de middleware pour valider les entrées
52- * - [OPTIONNEL] Support de différents formats via interfaces
53- * - [COMPATIBLE] Utiliser des codes HTTP standards
29+ * @see config::class For configuration management
30+ * @see log::class For logging management
5431 */
5532class ajax {
5633 /* * *************************Attributs****************************** */
5734
5835 /* * *********************Methode static ************************* */
5936
6037 /**
61- * Initialise la réponse AJAX
62- * Configure les en-têtes HTTP et vérifie les actions autorisées en GET
38+ * Initializes AJAX response with HTTP headers and GET action validation
6339 *
64- * @param array $_allowGetAction Liste des actions autorisées en GET
40+ * @param string[] $_allowGetAction List of allowed GET actions
6541 * @return void
66- * @throws \Exception Si l'action demandée en GET n'est pas autorisée
67- *
68- * @note Évolution possible
69- * Cette méthode pourrait retourner $this pour permettre le chaînage :
70- * ```php
71- * ajax::init(['action'])
72- * ->withValidator()
73- * ->withFormat();
74- * ```
75- * Ce changement serait rétrocompatible
42+ * @throws \Exception When requested GET action is not allowed
7643 */
7744 public static function init ($ _allowGetAction = array ()) {
7845 if (!headers_sent ()) {
@@ -84,38 +51,31 @@ public static function init($_allowGetAction = array()) {
8451 }
8552
8653 /**
87- * Retourne un token (méthode non utilisée ?)
54+ * Returns authentication token
8855 *
89- * @return string Token vide
56+ * @deprecated Since version 4.4, authentication is handled differently
57+ * @return string Empty token
9058 */
9159 public static function getToken (){
9260 return '' ;
9361 }
9462
9563 /**
96- * Envoie une réponse de succès et termine l'exécution
64+ * Sends a success response and ends execution
9765 *
98- * @param mixed $_data Données à renvoyer dans la réponse
66+ * @param mixed $_data Data to send in response
9967 * @return never
100- *
101- * @note Compatibilité et évolution
102- * Pour maintenir la compatibilité tout en permettant l'évolution :
103- * - Garder le comportement actuel par défaut
104- * - Permettre l'injection d'un formatter optionnel
105- * ```php
106- * ajax::success($data, new JsonFormatter()); // Optionnel
107- * ```
10868 */
10969 public static function success ($ _data = '' ) {
11070 echo self ::getResponse ($ _data );
11171 die ();
11272 }
11373
11474 /**
115- * Envoie une réponse d'erreur et termine l'exécution
75+ * Sends an error response and ends execution
11676 *
117- * @param mixed $_data Message d'erreur ou données à renvoyer
118- * @param int $_errorCode Code d'erreur
77+ * @param mixed $_data Error message or data to send
78+ * @param int $_errorCode Custom error code for client-side handling (default: 0)
11979 * @return never
12080 */
12181 public static function error ($ _data = '' , $ _errorCode = 0 ) {
@@ -124,19 +84,11 @@ public static function error($_data = '', $_errorCode = 0) {
12484 }
12585
12686 /**
127- * Génère la réponse JSON formatée
128- *
129- * @param mixed $_data Données à inclure dans la réponse
130- * @param ?int $_errorCode Code d'erreur (null pour une réponse de succès)
131- * @return string Réponse JSON encodée
87+ * Generates formatted JSON response
13288 *
133- * @note Architecture future
134- * Cette méthode pourrait déléguer le formatage à des classes dédiées :
135- * - JsonFormatter (comportement actuel)
136- * - XmlFormatter
137- * - CsvFormatter
138- * etc.
139- * La transition peut se faire graduellement en gardant le comportement par défaut
89+ * @param mixed $_data Data to include in response
90+ * @param ?int $_errorCode Error code (null for success response)
91+ * @return string|false Encoded JSON response
14092 */
14193 public static function getResponse ($ _data = '' , $ _errorCode = null ) {
14294 $ isError = !(null === $ _errorCode );
0 commit comments