/[openfoncier]/trunk/obj/electronicsignature.class.php
ViewVC logotype

Annotation of /trunk/obj/electronicsignature.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10070 - (hide annotations)
Fri May 7 11:15:55 2021 UTC (3 years, 8 months ago) by softime
Original Path: branches/4.14.0-develop_connecteur_parapheur/obj/electronicsignature.class.php
File size: 9719 byte(s)
* WIP : ajout de la méthode get_conf pour electronicsignature_base

1 softime 10067 <?php
2     /**
3     * Contient la définition des classes 'electronicsignature' et 'electronicsignature_base'.
4     */
5    
6     /**
7     * Abstracteur du parapheur
8     */
9     class electronicsignature {
10    
11     /**
12     * [$conf description]
13     * @var null
14     */
15     var $conf = null;
16    
17     /**
18     * [$electronicsignature description]
19     * @var null
20     */
21     var $electronicsignature = null;
22    
23     /**
24     * [__construct description]
25     * @param array $params [description]
26     */
27     public function __construct(array $params) {
28     //
29     if (file_exists("../dyn/electronicsignature.inc.php") === false) {
30     throw new electronicsignature_configuration_exception(__("Aucun fichier de configuration pour la signature électronique."), false);
31     }
32     include("../dyn/electronicsignature.inc.php");
33     if (isset($conf) === false) {
34     throw new electronicsignature_configuration_exception(__("Aucune configuration pour la signature électronique."), false);
35     }
36     $this->conf = $conf;
37     //
38     if (isset($params['conf_name']) === true) {
39     $this->conf = $this->conf[$params['conf_name']];
40     } else {
41     $this->conf = $this->conf['electronicsignature-default'];
42     }
43     //
44     if (isset($params['collectivite_idx']) === true
45     && $this->get_conf('unexpected_collectivite') !== null
46     && in_array($params['collectivite_idx'], $this->get_conf('unexpected_collectivite')) === true) {
47     //
48     throw new electronicsignature_configuration_exception(__("Aucun parapheur configuré pour la collectivité."), false);
49     }
50     //
51     if (isset($params['collectivite_idx']) === true
52     && $this->get_conf($params['collectivite_idx']) !== null) {
53     //
54     $this->conf = $this->conf[$params['collectivite_idx']];
55     }
56     elseif (isset($params['collectivite_multi_idx']) === true
57     && $this->get_conf($params['collectivite_multi_idx']) !== null) {
58     //
59     $this->conf = $this->conf[$params['collectivite_multi_idx']];
60     } else {
61     throw new electronicsignature_configuration_exception(__("Aucun parapheur configuré pour la collectivité."), false);
62     }
63    
64     //
65     if ($this->get_conf('path') === null) {
66     throw new electronicsignature_configuration_exception(__("Le chemin vers le connecteur du parapheur n'est pas configuré."));
67     }
68     //
69     if ($this->get_conf('connector') === null) {
70     throw new electronicsignature_configuration_exception(__("Le nom du connecteur du parapheur n'est pas configuré."));
71     }
72     //
73     $connector = sprintf(
74     '%s_%s',
75     get_class($this),
76     $this->get_conf('connector')
77     );
78     require_once $this->conf['path'].$connector.'.class.php';
79     $this->electronicsignature = new $connector($this->get_conf());
80     }
81    
82     /**
83     * [__destruct description]
84     */
85     public function __destruct() {
86     //
87     if (is_null($this->electronicsignature) === false) {
88     unset($this->electronicsignature);
89     }
90     }
91    
92     /**
93     * [get_conf description]
94     * @param [type] $params [description]
95     * @return [type] [description]
96     */
97     public function get_conf($params = null) {
98     if ($params === null) {
99     return $this->conf;
100     }
101     if (is_string($params) === true
102     && is_array($this->conf) === true) {
103     //
104     if (array_key_exists($params, $this->conf) === true) {
105     return $this->conf[$params];
106     }
107     }
108     if (is_array($params) === true
109     && is_array($this->conf) === true
110     && count($params) === 2
111     && array_key_exists($params[0], $this->conf) === true
112     && is_array($this->conf[$params[0]]) === true
113     && array_key_exists($params[1], $this->conf[$params[0]]) === true) {
114     //
115     return $this->conf[$params[0]][$params[1]];
116     }
117     return null;
118     }
119    
120     /**
121     * [send_for_signature description]
122     * @param array $data [description]
123     * @param string $file_content [description]
124     * @return [type] [description]
125     */
126     public function send_for_signature(array $data, string $file_content) {
127     //
128     if (is_array($data) === false
129     || empty($data) === true) {
130     //
131 softime 10070 throw new electronicsignature_parameter_exception(__("Le tableau des valeurs est vide."));
132 softime 10067 }
133     if (empty($file_content) === true) {
134     //
135     throw new electronicsignature_parameter_exception(__("Aucun contenu de document transmis."));
136     }
137    
138     //
139     $es = $this->electronicsignature;
140     if (is_null($es) === true) {
141     return false;
142     }
143     //
144     return $es->send_for_signature($data, $file_content);
145     }
146    
147     /**
148     * [get_signature_status description]
149     * @param array $data [description]
150     * @return [type] [description]
151     */
152     public function get_signature_status(array $data) {
153     //
154     if (is_array($data) === false
155     || empty($data) === true) {
156     //
157     throw new electronicsignature_parameter_exception();
158     }
159    
160     //
161     $es = $this->electronicsignature;
162     if (is_null($es) === true) {
163     return false;
164     }
165     //
166     return $es->get_signature_status($data);
167     }
168    
169     /**
170     * [get_signed_document description]
171     * @param array $data [description]
172     * @return [type] [description]
173     */
174     public function get_signed_document(array $data) {
175     //
176     if (is_array($data) === false
177     || empty($data) === true) {
178     //
179     throw new electronicsignature_parameter_exception();
180     }
181    
182     //
183     $es = $this->electronicsignature;
184     if (is_null($es) === true) {
185     return false;
186     }
187     //
188     return $es->get_signed_document($data);
189     }
190    
191     }
192    
193     /**
194     * Classe parente de tous les connecteurs parapheur
195     */
196     class electronicsignature_base {
197    
198 softime 10070 var $conf = null;
199    
200     protected function __construct(array $conf) {
201     $this->conf = $conf;
202     }
203    
204     protected function get_conf($params = null) {
205     if ($params === null) {
206     return $this->conf;
207     }
208     if (is_string($params) === true
209     && is_array($this->conf) === true) {
210     //
211     if (array_key_exists($params, $this->conf) === true) {
212     return $this->conf[$params];
213     }
214     }
215     if (is_array($params) === true
216     && is_array($this->conf) === true
217     && count($params) === 2
218     && array_key_exists($params[0], $this->conf) === true
219     && is_array($this->conf[$params[0]]) === true
220     && array_key_exists($params[1], $this->conf[$params[0]]) === true) {
221     //
222     return $this->conf[$params[0]][$params[1]];
223     }
224     return null;
225     }
226    
227 softime 10067 protected function send_for_signature(array $data, string $file_content) {
228     //
229     throw new electronicsignature_connector_method_not_implemented_exception();
230     }
231    
232     protected function get_signature_status(array $data) {
233     //
234     throw new electronicsignature_connector_method_not_implemented_exception();
235     }
236    
237     protected function get_signed_document(array $data) {
238     //
239     throw new electronicsignature_connector_method_not_implemented_exception();
240     }
241    
242     }
243    
244     /**
245     * Classe gérant les erreurs
246     */
247     class electronicsignature_exception extends Exception {
248    
249     public function __construct($message = "", $write_log = true, $code = 0, Exception $previous = null) {
250     parent::__construct($message, $code, $previous);
251     if ($write_log === true) {
252     logger::instance()->writeErrorLogToFile();
253     }
254     }
255     }
256    
257     class electronicsignature_configuration_exception extends electronicsignature_exception {
258    
259     public function __construct($message = null, $write_log = true) {
260     $ret = trim(sprintf(
261     '%s %s %s',
262     __('Erreur de configuration du parapheur.'),
263     __('Veuillez contacter votre administrateur.'),
264     $message
265     ));
266     parent::__construct($ret, $write_log);
267     }
268     }
269    
270     class electronicsignature_parameter_exception extends electronicsignature_exception {
271    
272     public function __construct($message = null, $write_log = true) {
273     $ret = trim(sprintf(
274     '%s %s %s',
275     __("Les paramètres d'appel au parapheur ne sont pas valides."),
276     __('Veuillez contacter votre administrateur.'),
277     $message
278     ));
279     parent::__construct($ret, $write_log);
280     }
281     }
282    
283     class electronicsignature_connector_exception extends electronicsignature_exception {
284    
285     public function __construct($message = null, $write_log = true) {
286     $ret = trim(sprintf(
287     '%s %s %s',
288     __('Erreur du parapheur.'),
289     __('Veuillez contacter votre administrateur.'),
290     $message
291     ));
292     parent::__construct($ret, $write_log);
293     }
294     }
295    
296     class electronicsignature_connector_method_not_implemented_exception extends electronicsignature_exception {
297    
298     public function __construct($message = null, $write_log = true) {
299     $ret = trim(sprintf(
300     '%s %s %s',
301     __("La méthode n'est pas implémentée dans le connecteur."),
302     __('Veuillez contacter votre administrateur.'),
303     $message
304     ));
305     parent::__construct($ret, $write_log);
306     }
307     }

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26