Skip to content

Commit cf29732

Browse files
author
Mike Harrison
committed
add const to Debugger class for default response key
init $responseKey as the default response key moved setting the response key from config into the service provider
1 parent 8762ebe commit cf29732

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Debugger.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ class Debugger
1616
/**
1717
* @var string
1818
*/
19-
protected $responseKey;
19+
const DEFAULT_RESPONSE_KEY = 'debug';
20+
21+
/**
22+
* @var string
23+
*/
24+
protected $responseKey = self::DEFAULT_RESPONSE_KEY;
2025

2126
/**
2227
* @var Storage
@@ -39,8 +44,6 @@ public function __construct(Storage $storage, Event $event)
3944
$this->storage = $storage;
4045
$this->event = $event;
4146

42-
$this->responseKey = config('api-debugger.response_key', 'debug');
43-
4447
$this->event->listen(RequestHandled::class, function (RequestHandled $event) {
4548
$this->updateResponse($event->request, $event->response);
4649
});

src/ServiceProvider.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function boot()
2424
$config = $this->app['config'];
2525
if ($config['api-debugger.enabled']) {
2626
$this->registerCollections($config['api-debugger.collections']);
27+
28+
$this->setResponseKey($config['api-debugger.response_key']);
2729
}
2830
}
2931

@@ -62,4 +64,19 @@ protected function registerCollections(array $collections)
6264
$debugger->populateWith($this->app->make($collection));
6365
}
6466
}
67+
68+
/**
69+
* Set the response key for the debug object
70+
* (default: debug)
71+
*
72+
* @param string key
73+
*/
74+
protected function setResponseKey($key)
75+
{
76+
$debugger = $this->app->make(Debugger::class);
77+
78+
if($key !== Debugger::DEFAULT_RESPONSE_KEY){
79+
$debugger->setResponseKey($key);
80+
}
81+
}
6582
}

0 commit comments

Comments
 (0)