@@ -65,9 +65,10 @@ public static function information(array $table): array|string|bool
6565 * Handle CREATE request
6666 *
6767 * @param array $table
68+ * @param array $callback
6869 * @return bool|mysqli_result|string
6970 */
70- public static function create (array $ table ): mysqli_result |bool |string
71+ public static function create (array $ table, array $ callback = [] ): mysqli_result |bool |string
7172 {
7273 $ tableName = array_key_first ($ table );
7374 $ sql = "INSERT INTO $ tableName " ;
@@ -95,6 +96,10 @@ public static function create(array $table): mysqli_result|bool|string
9596
9697 $ result = self ::$ generatrixDB ->dbConnection ->query ($ sql );
9798
99+ if (count ($ callback ) == 2 && is_callable ($ callback )) {
100+ $ result = call_user_func_array ($ callback , (array )$ result );
101+ }
102+
98103 return match (self ::$ responseType ) {
99104 'JSON ' => json_encode ($ result ),
100105 default => $ result ,
@@ -108,9 +113,10 @@ public static function create(array $table): mysqli_result|bool|string
108113 * @param array $table
109114 * @param array $relationships
110115 * @param string $relationshipDirection
116+ * @param array $callback
111117 * @return array|false|string
112118 */
113- public static function read (int $ id , array $ table , array $ relationships = [], string $ relationshipDirection = 'LEFT ' ): bool |array |string
119+ public static function read (int $ id , array $ table , array $ relationships = [], string $ relationshipDirection = 'LEFT ' , array $ callback = [] ): bool |array |string
114120 {
115121 $ tableName = array_key_first ($ table );
116122
@@ -167,6 +173,10 @@ public static function read(int $id, array $table, array $relationships = [], st
167173 }
168174 }
169175
176+ if (count ($ callback ) == 2 && is_callable ($ callback )) {
177+ $ response = call_user_func_array ($ callback , $ response );
178+ }
179+
170180 return match (self ::$ responseType ) {
171181 'JSON ' => json_encode ($ response ),
172182 default => $ response ,
@@ -178,9 +188,10 @@ public static function read(int $id, array $table, array $relationships = [], st
178188 *
179189 * @param int $id
180190 * @param array $table
191+ * @param array $callback
181192 * @return bool|mysqli_result|string
182193 */
183- public static function update (int $ id , array $ table ): mysqli_result |bool |string
194+ public static function update (int $ id , array $ table, array $ callback = [] ): mysqli_result |bool |string
184195 {
185196 $ tableName = array_key_first ($ table );
186197 $ sql = "UPDATE $ tableName " ;
@@ -194,6 +205,10 @@ public static function update(int $id, array $table): mysqli_result|bool|string
194205
195206 $ result = self ::$ generatrixDB ->dbConnection ->query ($ sql );
196207
208+ if (count ($ callback ) == 2 && is_callable ($ callback )) {
209+ $ result = call_user_func_array ($ callback , (array )$ result );
210+ }
211+
197212 return match (self ::$ responseType ) {
198213 'JSON ' => json_encode ($ result ),
199214 default => $ result ,
@@ -205,14 +220,19 @@ public static function update(int $id, array $table): mysqli_result|bool|string
205220 *
206221 * @param int $id
207222 * @param array $table
223+ * @param array $callback
208224 * @return bool|mysqli_result|string
209225 */
210- public static function delete (int $ id , array $ table ): mysqli_result |bool |string
226+ public static function delete (int $ id , array $ table, array $ callback = [] ): mysqli_result |bool |string
211227 {
212228 $ sql = "DELETE FROM $ table [0 ] WHERE id = $ id " ;
213229
214230 $ result = self ::$ generatrixDB ->dbConnection ->query ($ sql );
215231
232+ if (count ($ callback ) == 2 && is_callable ($ callback )) {
233+ $ result = call_user_func_array ($ callback , (array )$ result );
234+ }
235+
216236 return match (self ::$ responseType ) {
217237 'JSON ' => json_encode ($ result ),
218238 default => $ result ,
0 commit comments