diff --git a/config/terminal.php b/config/terminal.php index ddf6633..e6006de 100644 --- a/config/terminal.php +++ b/config/terminal.php @@ -3,7 +3,7 @@ return [ 'enabled' => true, 'whitelists' => [], - 'router' => [ + 'route' => [ 'prefix' => 'terminal', 'as' => 'terminal.', 'middleware' => ['web'], diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index b0b6475..5fea222 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -2,9 +2,9 @@ namespace Recca0120\Terminal; -use Illuminate\Contracts\Config\Repository as ConfigContract; use Illuminate\Http\Request; use Illuminate\Routing\Router; +use Illuminate\Support\Arr; use Illuminate\Support\ServiceProvider as BaseServiceProvider; class ServiceProvider extends BaseServiceProvider @@ -19,20 +19,20 @@ class ServiceProvider extends BaseServiceProvider /** * Bootstrap any application services. * - * @param \Illuminate\Http\Request $Request - * @param \Illuminate\Routing\Router $router - * @param \Illuminate\Contracts\Config\Repository $config + * @param \Illuminate\Http\Request $Request + * @param \Illuminate\Routing\Router $router * * @return void */ - public function boot(Request $request, Router $router, ConfigContract $config) + public function boot(Request $request, Router $router) { $this->handlePublishes(); - - if ($config->get('app.debug') === true || + $debugEnabled = $this->app['config']->get('app.debug', false); + $config = $this->app['config']->get('terminal', []); + if ($debugEnabled === true || in_array( $request->getClientIp(), - $config->get('terminal.whitelists', []) + Arr::get($config, 'whitelists', []) ) === true ) { $this->loadViewsFrom(__DIR__.'/../resources/views', 'terminal'); @@ -54,15 +54,16 @@ public function register() * register routes. * * @param Illuminate\Routing\Router $router + * @param array $config * * @return void */ - public function handleRoutes(Router $router, ConfigContract $config) + public function handleRoutes(Router $router, $config = []) { if ($this->app->routesAreCached() === false) { - $router->group(array_merge($config->get('terminal.router'), [ + $router->group(array_merge([ 'namespace' => $this->namespace, - ]), function (Router $router) { + ], Arr::get($config, 'route', [])), function (Router $router) { require __DIR__.'/Http/routes.php'; }); } diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 85c85e1..a65abfa 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -41,10 +41,9 @@ public function test_boot() $view->shouldReceive('addNamespace')->with('terminal', m::any()); $config - ->shouldReceive('get')->with('app.debug')->andReturn(true) - ->shouldReceive('get')->with('terminal', [])->andReturn([]) - ->shouldReceive('set')->with('terminal', m::any()) - ->shouldReceive('get')->with('terminal.router')->andReturn([]); + ->shouldReceive('get')->with('app.debug', false)->once()->andReturn(true) + ->shouldReceive('get')->with('terminal', [])->twice()->andReturn([]) + ->shouldReceive('set')->with('terminal', m::any())->once(); $app ->shouldReceive('offsetGet')->with('config')->andReturn($config)