Skip to content

Commit

Permalink
Merge branch 'release/1.0.5'
Browse files Browse the repository at this point in the history
Signed-off-by: Stefano Azzolini <[email protected]>

Conflicts:
	classes/API.php
	composer.json
  • Loading branch information
Stefano Azzolini committed Nov 17, 2014
2 parents 6118a9e + 84c64e3 commit 49137b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
22 changes: 12 additions & 10 deletions classes/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ public static function error($message,$status=501){
public static function run(callable $main = null){
$API_VERS = Options::get('base.api_version','');
// Load Routes
$route_file = rtrim(Options::get('base.endpoints',APP_DIR.'/routes.php'),'/');
$route = rtrim(Options::get('base.endpoints',APP_DIR.'/routes.php'),'/');
// Single file
if (is_file($route_file)){
include $route_file;
if (is_file($route)){
include $route;
} else {
// Load directory
$route_file .= rtrim('/'.$API_VERS,'/');
if (is_dir($route_file)){
Route::group("/$API_VERS",function() use ($route_file,$API_VERS){
Event::trigger('api.before');
array_map(function($f){include $f;},glob($route_file.'/*.php'));
Event::trigger('api.after');
});
foreach((array)$API_VERS as $API_NAMESPACE){
$routes = $route . rtrim('/'.$API_NAMESPACE,'/');
if (is_dir($routes)){
Route::group("/$API_NAMESPACE",function() use ($routes,$API_NAMESPACE){
Event::trigger('api.before');
array_map(function($f){include $f;},glob($routes.'/*.php'));
Event::trigger('api.after');
});
}
}
}
Event::trigger('api.run',[Options::get('base.api_version','')]);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "API extensions for Caffeina Core",
"keywords": ["core","api","rest","server"],
"homepage": "http://labs.caffeina.co/tech/core",
"version": "1.0.4",
"version": "1.0.5",
"license": "MIT",
"authors": [
{
Expand Down
3 changes: 2 additions & 1 deletion config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
// Pass the endpoints directory.
// API routes will be loaded in {endpoints}/{api_version}/*.php
'endpoints' => APP_DIR.'/endpoints',
'api_version' => 'v1',
// Enable versions
'api_version' => ['v1'], // can have multiple values
],

/**
Expand Down

0 comments on commit 49137b6

Please sign in to comment.