-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
332 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
*/ | ||
'except' => [ | ||
'*telescope*', | ||
'*horizon*', | ||
], | ||
|
||
/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the guanguans/laravel-soar. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\LaravelSoar\Http\Controllers; | ||
|
||
use DateTime; | ||
use Guanguans\LaravelSoar\SoarDebugBar; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Routing\Controller; | ||
|
||
/** | ||
* This is modified from the https://github.com/barryvdh/laravel-debugbar. | ||
* | ||
* @see https://github.com/barryvdh/laravel-debugbar/blob/master/src/Controllers/AssetController.php | ||
*/ | ||
class AssetController extends Controller | ||
{ | ||
public function __construct(SoarDebugBar $debugBar) | ||
{ | ||
$this->debugBar = $debugBar; | ||
} | ||
|
||
/** | ||
* Return the javascript for the DebugBar. | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function js() | ||
{ | ||
$renderer = $this->debugBar->getJavascriptRenderer(); | ||
$content = $renderer->dumpAssetsToString('js'); | ||
$response = new Response( | ||
$content, | ||
200, | ||
['Content-Type' => 'text/javascript'] | ||
); | ||
|
||
return $this->cacheResponse($response); | ||
} | ||
|
||
/** | ||
* Return the stylesheets for the DebugBar. | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function css() | ||
{ | ||
$renderer = $this->debugBar->getJavascriptRenderer(); | ||
$content = $renderer->dumpAssetsToString('css'); | ||
$response = new Response( | ||
$content, | ||
200, | ||
['Content-Type' => 'text/css'] | ||
); | ||
|
||
return $this->cacheResponse($response); | ||
} | ||
|
||
/** | ||
* Cache the response 1 year (31536000 sec). | ||
*/ | ||
protected function cacheResponse(Response $response) | ||
{ | ||
$response->setSharedMaxAge(31536000); | ||
$response->setMaxAge(31536000); | ||
$response->setExpires(new DateTime('+1 year')); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the guanguans/laravel-soar. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
$routeOptions = [ | ||
'namespace' => 'Guanguans\LaravelSoar\Http\Controllers', | ||
'prefix' => app('config')->get('soar.route_prefix', 'soar-debugbar'), | ||
'domain' => app('config')->get('soar.route_domain', null), | ||
'middleware' => [], | ||
]; | ||
|
||
app('router')->group($routeOptions, function ($router) { | ||
$router->get('assets/stylesheets', [ | ||
'uses' => 'AssetController@css', | ||
'as' => 'soar.debugbar.assets.css', | ||
]); | ||
|
||
$router->get('assets/javascript', [ | ||
'uses' => 'AssetController@js', | ||
'as' => 'soar.debugbar.assets.js', | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the guanguans/laravel-soar. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\LaravelSoar; | ||
|
||
/** | ||
* This is modified from the https://github.com/barryvdh/laravel-debugbar. | ||
* | ||
* @see https://github.com/barryvdh/laravel-debugbar/blob/master/src/JavascriptRenderer.php | ||
*/ | ||
class JavascriptRenderer extends \DebugBar\JavascriptRenderer | ||
{ | ||
// Use XHR handler by default, instead of jQuery | ||
protected $ajaxHandlerBindToJquery = false; | ||
|
||
protected $ajaxHandlerBindToXHR = true; | ||
|
||
/** | ||
* Set the URL Generator. | ||
* | ||
* @param \Illuminate\Routing\UrlGenerator $url | ||
* | ||
* @deprecated | ||
*/ | ||
public function setUrlGenerator($url) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function renderHead() | ||
{ | ||
$cssRoute = route('soar.debugbar.assets.css', [ | ||
'v' => $this->getModifiedTime('css'), | ||
'theme' => config('debugbar.theme', 'auto'), | ||
]); | ||
|
||
$jsRoute = route('soar.debugbar.assets.js', [ | ||
'v' => $this->getModifiedTime('js'), | ||
]); | ||
|
||
$cssRoute = preg_replace('/\Ahttps?:/', '', $cssRoute); | ||
$jsRoute = preg_replace('/\Ahttps?:/', '', $jsRoute); | ||
|
||
$html = "<link rel='stylesheet' type='text/css' property='stylesheet' href='{$cssRoute}'>"; | ||
$html .= "<script src='{$jsRoute}'></script>"; | ||
|
||
if ($this->isJqueryNoConflictEnabled()) { | ||
$html .= '<script>jQuery.noConflict(true);</script>'."\n"; | ||
} | ||
|
||
$html .= $this->getInlineHtml(); | ||
|
||
return $html; | ||
} | ||
|
||
protected function getInlineHtml() | ||
{ | ||
$html = ''; | ||
|
||
foreach (['head', 'css', 'js'] as $asset) { | ||
foreach ($this->getAssets('inline_'.$asset) as $item) { | ||
$html .= $item."\n"; | ||
} | ||
} | ||
|
||
return $html; | ||
} | ||
|
||
/** | ||
* Get the last modified time of any assets. | ||
* | ||
* @param string $type 'js' or 'css' | ||
* | ||
* @return int | ||
*/ | ||
protected function getModifiedTime($type) | ||
{ | ||
$files = $this->getAssets($type); | ||
|
||
$latest = 0; | ||
foreach ($files as $file) { | ||
$mtime = filemtime($file); | ||
if ($mtime > $latest) { | ||
$latest = $mtime; | ||
} | ||
} | ||
|
||
return $latest; | ||
} | ||
|
||
/** | ||
* Return assets as a string. | ||
* | ||
* @param string $type 'js' or 'css' | ||
* | ||
* @return string | ||
*/ | ||
public function dumpAssetsToString($type) | ||
{ | ||
$files = $this->getAssets($type); | ||
|
||
$content = ''; | ||
foreach ($files as $file) { | ||
$content .= file_get_contents($file)."\n"; | ||
} | ||
|
||
return $content; | ||
} | ||
|
||
/** | ||
* Makes a URI relative to another. | ||
* | ||
* @param string|array $uri | ||
* @param string $root | ||
* | ||
* @return array|string | ||
*/ | ||
protected function makeUriRelativeTo($uri, $root) | ||
{ | ||
if (! $root) { | ||
return $uri; | ||
} | ||
|
||
if (is_array($uri)) { | ||
$uris = []; | ||
foreach ($uri as $u) { | ||
$uris[] = $this->makeUriRelativeTo($u, $root); | ||
} | ||
|
||
return $uris; | ||
} | ||
|
||
if ('/' === substr($uri ?? '', 0, 1) || preg_match('/^([a-zA-Z]+:\/\/|[a-zA-Z]:\/|[a-zA-Z]:\\\)/', $uri ?? '')) { | ||
return $uri; | ||
} | ||
|
||
return rtrim($root, '/')."/$uri"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the guanguans/laravel-soar. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\LaravelSoar; | ||
|
||
use DebugBar\DataCollector\MemoryCollector; | ||
use DebugBar\DataCollector\MessagesCollector; | ||
use DebugBar\DataCollector\PhpInfoCollector; | ||
use DebugBar\DebugBar; | ||
|
||
class SoarDebugBar extends DebugBar | ||
{ | ||
public function __construct() | ||
{ | ||
$this->addCollector(new PhpInfoCollector()); | ||
$this->addCollector(new MessagesCollector()); | ||
$this->addCollector(new MemoryCollector()); | ||
$this->jsRenderer = new JavascriptRenderer($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters