Skip to content

Commit 49137b6

Browse files
author
Stefano Azzolini
committed
Merge branch 'release/1.0.5'
Signed-off-by: Stefano Azzolini <stefano.azzolini@caffeinalab.com> Conflicts: classes/API.php composer.json
2 parents 6118a9e + 84c64e3 commit 49137b6

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

classes/API.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ public static function error($message,$status=501){
1919
public static function run(callable $main = null){
2020
$API_VERS = Options::get('base.api_version','');
2121
// Load Routes
22-
$route_file = rtrim(Options::get('base.endpoints',APP_DIR.'/routes.php'),'/');
22+
$route = rtrim(Options::get('base.endpoints',APP_DIR.'/routes.php'),'/');
2323
// Single file
24-
if (is_file($route_file)){
25-
include $route_file;
24+
if (is_file($route)){
25+
include $route;
2626
} else {
2727
// Load directory
28-
$route_file .= rtrim('/'.$API_VERS,'/');
29-
if (is_dir($route_file)){
30-
Route::group("/$API_VERS",function() use ($route_file,$API_VERS){
31-
Event::trigger('api.before');
32-
array_map(function($f){include $f;},glob($route_file.'/*.php'));
33-
Event::trigger('api.after');
34-
});
28+
foreach((array)$API_VERS as $API_NAMESPACE){
29+
$routes = $route . rtrim('/'.$API_NAMESPACE,'/');
30+
if (is_dir($routes)){
31+
Route::group("/$API_NAMESPACE",function() use ($routes,$API_NAMESPACE){
32+
Event::trigger('api.before');
33+
array_map(function($f){include $f;},glob($routes.'/*.php'));
34+
Event::trigger('api.after');
35+
});
36+
}
3537
}
3638
}
3739
Event::trigger('api.run',[Options::get('base.api_version','')]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "API extensions for Caffeina Core",
55
"keywords": ["core","api","rest","server"],
66
"homepage": "http://labs.caffeina.co/tech/core",
7-
"version": "1.0.4",
7+
"version": "1.0.5",
88
"license": "MIT",
99
"authors": [
1010
{

config.sample.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// Pass the endpoints directory.
1010
// API routes will be loaded in {endpoints}/{api_version}/*.php
1111
'endpoints' => APP_DIR.'/endpoints',
12-
'api_version' => 'v1',
12+
// Enable versions
13+
'api_version' => ['v1'], // can have multiple values
1314
],
1415

1516
/**

0 commit comments

Comments
 (0)