@@ -1134,6 +1134,18 @@ protected function parseGetParameterArray($get,$name,$characters) {
1134
1134
return $ values ;
1135
1135
}
1136
1136
1137
+ protected function applyAfterCreate ($ callback ,$ database ,$ table ,$ id ) {
1138
+ if (is_callable ($ callback ,true )) {
1139
+ $ fields = $ this ->findPrimaryKeys ($ table ,$ database );
1140
+ if (count ($ fields )!=1 ) $ this ->exitWith404 ('1pk ' );
1141
+ if ($ result = $ this ->db ->query ("SELECT * FROM ! WHERE ! = ? " ,array ($ table , $ fields [0 ], $ id ))) {
1142
+ $ object = $ this ->db ->fetchAssoc ($ result );
1143
+ $ callback ($ database ,$ table ,$ object );
1144
+ $ this ->db ->close ($ result );
1145
+ }
1146
+ }
1147
+ }
1148
+
1137
1149
protected function applyTableAuthorizer ($ callback ,$ action ,$ database ,&$ tables ) {
1138
1150
if (is_callable ($ callback ,true )) foreach ($ tables as $ i =>$ table ) {
1139
1151
if (!$ callback ($ action ,$ database ,$ table )) {
@@ -1467,7 +1479,10 @@ protected function createObject($input,$tables) {
1467
1479
array_unshift ($ params , $ tables [0 ]);
1468
1480
$ result = $ this ->db ->query ('INSERT INTO ! ( ' .$ keys .') VALUES ( ' .$ values .') ' ,$ params );
1469
1481
if (!$ result ) return null ;
1470
- return $ this ->db ->insertId ($ result );
1482
+ $ insertId = $ this ->db ->insertId ($ result );
1483
+ extract ($ this ->settings );
1484
+ $ this ->applyAfterCreate ($ after_create ,$ database ,$ tables [0 ],$ insertId );
1485
+ return $ insertId ;
1471
1486
}
1472
1487
1473
1488
protected function createObjects ($ inputs ,$ tables ) {
@@ -2109,6 +2124,7 @@ public function __construct($config) {
2109
2124
$ input_validator = isset ($ input_validator )?$ input_validator :null ;
2110
2125
$ auto_include = isset ($ auto_include )?$ auto_include :null ;
2111
2126
$ allow_origin = isset ($ allow_origin )?$ allow_origin :null ;
2127
+ $ after_create = isset ($ after_create )?$ after_create :null ;
2112
2128
2113
2129
$ db = isset ($ db )?$ db :null ;
2114
2130
$ method = isset ($ method )?$ method :null ;
@@ -2160,7 +2176,7 @@ public function __construct($config) {
2160
2176
}
2161
2177
2162
2178
$ this ->db = $ db ;
2163
- $ this ->settings = compact ('method ' , 'request ' , 'get ' , 'post ' , 'origin ' , 'database ' , 'table_authorizer ' , 'record_filter ' , 'column_authorizer ' , 'tenancy_function ' , 'input_sanitizer ' , 'input_validator ' , 'auto_include ' , 'allow_origin ' );
2179
+ $ this ->settings = compact ('method ' , 'request ' , 'get ' , 'post ' , 'origin ' , 'database ' , 'table_authorizer ' , 'record_filter ' , 'column_authorizer ' , 'tenancy_function ' , 'input_sanitizer ' , 'input_validator ' , 'after_create ' , ' auto_include ' , 'allow_origin ' );
2164
2180
}
2165
2181
2166
2182
public static function php_crud_api_transform (&$ tables ) {
0 commit comments