Skip to content

Commit 6e66160

Browse files
CI4.1 support.
+ Performance boost.
1 parent fc75980 commit 6e66160

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

Hooks.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,22 @@ public static function preSystem() {
8888

8989
$routes = Services::routes(true);
9090

91-
if(self::$config->enableApiRouting && self::$database->tableExists('api_routes')) {
92-
$routes = Services::routes(true);
93-
/** @var ApiRoute $apiRoutes */
94-
$apiRoutes = (new ApiRouteModel())->find();
95-
foreach($apiRoutes as $route) {
96-
$routes->{$route->method}($route->from, $route->to);
91+
if (self::$config->enableApiRouting) {
92+
93+
try {
94+
/** @var ApiRoute $apiRoutes */
95+
$apiRoutes = (new ApiRouteModel())->find();
96+
97+
if ($apiRoutes->count()) {
98+
$routes = Services::routes(true);
99+
foreach ($apiRoutes as $route) {
100+
$routes->{$route->method}($route->from, $route->to);
101+
}
102+
}
103+
} catch (\mysqli_sql_exception $e) {
104+
97105
}
106+
98107
}
99108

100109
/*

Models/ApiRouteModel.php

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
* @package RestExtension\Models
88
*/
99
class ApiRouteModel extends Model {
10+
11+
public $table = 'api_routes';
12+
public $entityName = 'ApiRoute';
13+
public $returnType = '\RestExtension\Entities\ApiRoute';
14+
public $allowedFields = [
15+
"id",
16+
"method",
17+
"from",
18+
"to",
19+
"cacheable",
20+
"version",
21+
"scope",
22+
"is_public",
23+
];
1024

1125
public $hasOne = [
1226

0 commit comments

Comments
 (0)