Skip to content

Commit

Permalink
Merge pull request #1 from nikolajlovenhardt/master
Browse files Browse the repository at this point in the history
Fixed path for publishing configuration file
  • Loading branch information
esbenp authored Oct 7, 2016
2 parents 632a945 + 9fec299 commit 31141a6
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions src/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,41 @@ class RouteServiceProvider extends ServiceProvider
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
public function boot()
{
$this->loadConfig();

parent::boot($router);
parent::boot();
}

/**
* Register
*/
public function register()
{
$this->registerAssets();
}

/**
* Register assets
*/
private function registerAssets()
{
$this->publishes([
__DIR__.'/../config/optimus.components.php' => config_path('optimus.components.php')
__DIR__ . '/config/optimus.components.php' => config_path('optimus.components.php'),
]);
}

/**
* Load configuration
*/
private function loadConfig()
{
if ($this->app['config']->get('optimus.components') === null) {
$this->app['config']->set('optimus.components', require __DIR__.'/config/optimus.components.php');
/** @var \Illuminate\Config\Repository $config */
$config = $this->app['config'];

if ($config->get('optimus.components') === null) {
$config->set('optimus.components', require __DIR__ . '/config/optimus.components.php');
}
}

Expand All @@ -50,32 +62,40 @@ public function map(Router $router)
$config = $this->app['config']['optimus.components'];

$middleware = $config['protection_middleware'];

$highLevelParts = array_map(function ($namespace) {
return glob(sprintf('%s%s*', $namespace, DIRECTORY_SEPARATOR), GLOB_ONLYDIR);
}, $config['namespaces']);

foreach ($highLevelParts as $part => $partComponents) {
foreach ($partComponents as $componentRoot) {
$component = substr($componentRoot, strrpos($componentRoot, '/')+1);
$namespace = $part . '\\' . $component . '\\Controllers';
$component = substr($componentRoot, strrpos($componentRoot, '/') + 1);

$namespace = sprintf(
'%s\\%s\\Controllers',
$part,
$component
);

$fileNames = [
'routes' => true,
'routes_protected' => true,
'routes_public' => false
'routes_public' => false,
];

foreach ($fileNames as $fileName => $protected) {
$path = sprintf('%s/%s.php', $componentRoot, $fileName);

if (file_exists($path)) {
$router->group([
'middleware' => $protected ? $middleware : [],
'namespace' => $namespace
], function ($router) use ($path) {
require $path;
});
if (!file_exists($path)) {
continue;
}

$router->group([
'middleware' => $protected ? $middleware : [],
'namespace' => $namespace,
], function ($router) use ($path) {
require $path;
});
}
}
}
Expand Down

0 comments on commit 31141a6

Please sign in to comment.