Skip to content

Commit

Permalink
remove config repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Recca Tsai committed Aug 21, 2016
1 parent cf5995e commit 8284664
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return [
'enabled' => true,
'whitelists' => [],
'router' => [
'route' => [
'prefix' => 'terminal',
'as' => 'terminal.',
'middleware' => ['web'],
Expand Down
23 changes: 12 additions & 11 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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';
});
}
Expand Down
7 changes: 3 additions & 4 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8284664

Please sign in to comment.