From 15b43dc9a9d9afbb9478046b2dbb944ba5e2ff07 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 27 Nov 2014 18:27:19 +0000 Subject: [PATCH] Moved routesInDirectory() function to service provider --- .../RoutingServiceProvider.php | 35 +++++++++++++++++++ app/config/app.php | 4 ++- app/routes.php | 18 +--------- 3 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 app/CachetHq/Cachet/Support/ServiceProviders/RoutingServiceProvider.php diff --git a/app/CachetHq/Cachet/Support/ServiceProviders/RoutingServiceProvider.php b/app/CachetHq/Cachet/Support/ServiceProviders/RoutingServiceProvider.php new file mode 100644 index 000000000..6cc443515 --- /dev/null +++ b/app/CachetHq/Cachet/Support/ServiceProviders/RoutingServiceProvider.php @@ -0,0 +1,35 @@ +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(); + } + } + } + +} diff --git a/app/config/app.php b/app/config/app.php index 507517767..3aa8e2a87 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -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', + ), /* diff --git a/app/routes.php b/app/routes.php index 2dfbd51c0..551c61d54 100644 --- a/app/routes.php +++ b/app/routes.php @@ -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'); \ No newline at end of file