-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_colCell.php
More file actions
131 lines (101 loc) · 3.32 KB
/
Copy path_colCell.php
File metadata and controls
131 lines (101 loc) · 3.32 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/orm/blob/master/LICENSE
*/
namespace Quid\Orm;
use Quid\Main;
// _colCell
// trait that provides common methods for Col and Cell objects
trait _colCell
{
// dynamique
protected array $callback = []; // permet d'entreposer un ou plusieurs committed callback, lors d'une opération réussi
protected ?\Exception $exception = null; // permet d'entreposer une exception, lors d'une opération raté
// exception
// retourne le message de l'exception
// si lang est true, retourne le texte indiquant que le champ est requis
final public function exception(bool $lang=false)
{
$return = true;
$exception = $this->getException();
if(is_array($exception) && array_key_exists('message',$exception) && array_key_exists('messageArgs',$exception))
{
$return = $exception['message'];
if($lang === true)
{
$lang = $this->db()->lang();
$message = $exception['messageArgs'];
if(is_array($message))
{
$safe = $lang->safe(...array_values($message));
if(is_string($safe))
$return = $safe;
}
}
}
return $return;
}
// ruleException
// retourne l'exception si présente
final public function ruleException(bool $lang=false):?string
{
$return = $this->exception($lang);
if($return === true)
$return = null;
return $return;
}
// hasCommittedCallback
// retourne vrai si l'objet contient un commited callback
final public function hasCommittedCallback(string $key):bool
{
return !empty($this->getCommittedCallback($key));
}
// getCommittedCallback
// retourne le commited callback
final public function getCommittedCallback(string $key):?\Closure
{
return $this->callback[$key] ?? null;
}
// setCommittedCallback
// ajoute un commited callback
final public function setCommittedCallback(string $key,\Closure $closure):void
{
$this->callback[$key] = $closure;
}
// clearCommittedCallback
// vide le callback à appeler après un commit, insert ou update
final public function clearCommittedCallback():void
{
$this->callback = [];
}
// hasException
// retourne vrai si l'objet contient une exception
final public function hasException():bool
{
return !empty($this->exception);
}
// getException
// retourne le message d'exception lié à l'objet
final public function getException():?array
{
return $this->exception;
}
// setException
// entrepose le message d'exception dans l'objet
final public function setException(Main\CatchableException $exception):void
{
$message['message'] = $exception->getMessage();
$message['messageArgs'] = $exception->messageArgs();
$this->exception = $message;
}
// clearException
// vide l'exception lié à une insertion raté
final public function clearException():void
{
$this->exception = null;
}
}
?>