Moved routesInDirectory() function to service provider

This commit is contained in:
Elliot Hesp 2014-11-27 18:27:19 +00:00
parent 66b9b881c8
commit 15b43dc9a9
3 changed files with 39 additions and 18 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace CachetHQ\Cachet\Support\ServiceProviders;
use Illuminate\Support\ServiceProvider;
use RecursiveDirectoryIterator;
class RoutingServiceProvider extends ServiceProvider {
public function register() {}
public function boot() {
$this->routesInDirectory();
}
/**
* Organise Routes
* @param string $app
*/
private function routesInDirectory($app = '') {
$routeDir = app_path('routes/' . $app . ($app !== '' ? '/' : null));
$iterator = new RecursiveDirectoryIterator($routeDir);
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
foreach ($iterator as $route) {
$isDotFile = strpos($route->getFilename(), '.') === 0;
if (!$isDotFile && !$route->isDir()) {
require $routeDir . $route->getFilename();
}
}
}
}

View File

@ -123,9 +123,11 @@ return array(
'Illuminate\Workbench\WorkbenchServiceProvider',
'Dingo\Api\Provider\ApiServiceProvider',
'Thujohn\Rss\RssServiceProvider',
'CachetHQ\Cachet\Support\ServiceProviders\RepositoryServiceProvider',
'Thujohn\Rss\RssServiceProvider',
'CachetHQ\Cachet\Support\ServiceProviders\RoutingServiceProvider',
),
/*

View File

@ -5,20 +5,4 @@ Route::model('incident', 'Incident');
Route::model('incident_template', 'IncidentTemplate');
Route::model('setting', 'Setting');
Route::model('webhook', 'WebHook');
Route::model('user', 'User');
routesInDirectory();
function routesInDirectory($app = '') {
$routeDir = app_path('routes/' . $app . ($app !== '' ? '/' : null));
$iterator = new RecursiveDirectoryIterator($routeDir);
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
foreach ($iterator as $route) {
$isDotFile = strpos($route->getFilename(), '.') === 0;
if (!$isDotFile && !$route->isDir()) {
require $routeDir . $route->getFilename();
}
}
}
Route::model('user', 'User');