Skip to content

Commit

Permalink
Use HttpFoundation request
Browse files Browse the repository at this point in the history
Use methods that are always available.

Conflicts:
	src/LaravelDebugBar.php
  • Loading branch information
barryvdh committed Feb 2, 2015
1 parent d57ca9b commit caa8c24
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/LaravelDebugBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public function getJavascriptRenderer($baseUrl = null, $basePath = null)
/**
* Modify the response and inject the debugbar (or data in headers)
*
* @param \Illuminate\Http\Request $request
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\HttpFoundation\Response $response
* @return \Symfony\Component\HttpFoundation\Response
*/
Expand Down Expand Up @@ -490,14 +490,14 @@ public function modifyResponse($request, $response)
}
}

if ($response->isRedirection() || !($request instanceof \Illuminate\Http\Request)) {
if ($response->isRedirection()) {
try {
$this->stackData();
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif (
($request->isXmlHttpRequest() || $request->wantsJson()) and
$this->isJsonRequest($request) and
$app['config']->get('debugbar.capture_ajax', true)
) {
try {
Expand All @@ -508,7 +508,7 @@ public function modifyResponse($request, $response)
} elseif (
($response->headers->has('Content-Type') and
strpos($response->headers->get('Content-Type'), 'html') === false)
|| 'html' !== $request->format()
|| $request->getRequestFormat() !== 'html'
) {
try {
// Just collect + store data, don't inject it.
Expand Down Expand Up @@ -548,6 +548,22 @@ protected function isDebugbarRequest()
{
return $this->app['request']->segment(1) == '_debugbar';
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @return bool
*/
protected function isJsonRequest($request)
{
// If XmlHttpRequest, return true
if ($request->isXmlHttpRequest()) {
return true;
}

// Check if the request wants Json
$acceptable = $request->getAcceptableContentTypes();
return (isset($acceptable[0]) && $acceptable[0] == 'application/json');
}

/**
* Collects the data from the collectors
Expand Down

0 comments on commit caa8c24

Please sign in to comment.