Skip to content

Commit d4ebe58

Browse files
committed
Use HttpFoundation request
Use methods that are always available.
1 parent 51f7b4b commit d4ebe58

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/LaravelDebugBar.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public function getJavascriptRenderer($baseUrl = null, $basePath = null)
441441
/**
442442
* Modify the response and inject the debugbar (or data in headers)
443443
*
444-
* @param \Illuminate\Http\Request $request
444+
* @param \Symfony\Component\HttpFoundation\Request $request
445445
* @param \Symfony\Component\HttpFoundation\Response $response
446446
* @return \Symfony\Component\HttpFoundation\Response
447447
*/
@@ -501,14 +501,14 @@ public function modifyResponse($request, $response)
501501
}
502502
}
503503

504-
if ($response->isRedirection() || !($request instanceof \Illuminate\Http\Request)) {
504+
if ($response->isRedirection()) {
505505
try {
506506
$this->stackData();
507507
} catch (\Exception $e) {
508508
$app['log']->error('Debugbar exception: ' . $e->getMessage());
509509
}
510510
} elseif (
511-
($request->isXmlHttpRequest() || $request->wantsJson()) and
511+
$this->isJsonRequest($request) and
512512
$app['config']->get('laravel-debugbar::config.capture_ajax', true)
513513
) {
514514
try {
@@ -519,7 +519,7 @@ public function modifyResponse($request, $response)
519519
} elseif (
520520
($response->headers->has('Content-Type') and
521521
strpos($response->headers->get('Content-Type'), 'html') === false)
522-
|| 'html' !== $request->format()
522+
|| $request->getRequestFormat() !== 'html'
523523
) {
524524
try {
525525
// Just collect + store data, don't inject it.
@@ -559,6 +559,22 @@ protected function isDebugbarRequest()
559559
{
560560
return $this->app['request']->segment(1) == '_debugbar';
561561
}
562+
563+
/**
564+
* @param \Symfony\Component\HttpFoundation\Request $request
565+
* @return bool
566+
*/
567+
protected function isJsonRequest($request)
568+
{
569+
// If XmlHttpRequest, return true
570+
if ($request->isXmlHttpRequest()) {
571+
return true;
572+
}
573+
574+
// Check if the request wants Json
575+
$acceptable = $request->getAcceptableContentTypes();
576+
return (isset($acceptable[0]) && $acceptable[0] == 'application/json');
577+
}
562578

563579
/**
564580
* Collects the data from the collectors

0 commit comments

Comments
 (0)