-
-
Notifications
You must be signed in to change notification settings - Fork 7
Support Laravel Debugbar 4 (Laravel 13) #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
austinderrick
wants to merge
3
commits into
wintercms:main
Choose a base branch
from
austinderrick:wip/laravel-13
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,21 +1,28 @@ | ||
| <?php namespace Winter\Debugbar\Classes; | ||
|
|
||
| use Barryvdh\Debugbar\LaravelDebugbar; | ||
| use DebugBar\JavascriptRenderer; | ||
| use Fruitcake\LaravelDebugbar\LaravelDebugbar; | ||
|
|
||
| class WinterDebugbar extends LaravelDebugbar | ||
| { | ||
| /** | ||
| * Returns a winterized JavascriptRenderer for this instance | ||
| * Returns the JavascriptRenderer for this instance with Winter's styling applied. | ||
| * | ||
| * @param string $baseUrl | ||
| * @param string $basePathng | ||
| * @return JavascriptRenderer | ||
| * Laravel Debugbar 4 performs the renderer configuration inside getJavascriptRenderer(), | ||
| * so we defer to the parent to build and cache the renderer and then register Winter's | ||
| * stylesheet via the renderer's asset API (the renderer is cached, so the CSS is only | ||
| * added the first time it is built). | ||
| */ | ||
| public function getJavascriptRenderer($baseUrl = null, $basePath = null) | ||
| public function getJavascriptRenderer(?string $baseUrl = null, ?string $basePath = null): JavascriptRenderer | ||
| { | ||
| if ($this->jsRenderer === null) { | ||
| $this->jsRenderer = new JavascriptRenderer($this, $baseUrl, $basePath); | ||
| $alreadyBuilt = $this->jsRenderer !== null; | ||
|
|
||
| $renderer = parent::getJavascriptRenderer($baseUrl, $basePath); | ||
|
|
||
| if (!$alreadyBuilt) { | ||
| $renderer->addAssets(cssFiles: ['debugbar.css'], basePath: __DIR__ . '/../assets/css'); | ||
| } | ||
| return $this->jsRenderer; | ||
|
|
||
| return $renderer; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,14 +3,51 @@ | |
| namespace Winter\Debugbar\Middleware; | ||
|
|
||
| use Backend\Facades\BackendAuth; | ||
| use Barryvdh\Debugbar\Middleware\InjectDebugbar as BaseMiddleware; | ||
| use Closure; | ||
| use Fruitcake\LaravelDebugbar\LaravelDebugbar; | ||
| use Illuminate\Foundation\Application; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Throwable; | ||
| use Winter\Storm\Support\Facades\Config; | ||
|
|
||
| class InjectDebugbar extends BaseMiddleware | ||
| /** | ||
| * Injects the Debugbar into the response, gated by the winter.debugbar permissions. | ||
| * | ||
| * Laravel Debugbar 4 removed its own InjectDebugbar middleware in favour of a | ||
| * RequestHandled event listener (registered by the base ServiceProvider) that injects | ||
| * the Debugbar unconditionally. This middleware replicates the legacy behaviour: it boots | ||
| * the Debugbar, restricts request storage and injection to authorised users, and performs | ||
| * the response handling itself via LaravelDebugbar::handleResponse(). Because handleResponse() | ||
| * flags the response as modified, the base event listener becomes a no-op for this request. | ||
| */ | ||
| class InjectDebugbar | ||
| { | ||
| /** | ||
| * The Laravel Application | ||
| * | ||
| * @var Application | ||
| */ | ||
| protected $app; | ||
|
|
||
| /** | ||
| * The Debugbar instance | ||
| * | ||
| * @var LaravelDebugbar | ||
| */ | ||
| protected $debugbar; | ||
|
|
||
| /** | ||
| * Create a new middleware instance. | ||
| * | ||
| * @param Application $app | ||
| * @param LaravelDebugbar $debugbar | ||
| */ | ||
| public function __construct(Application $app, LaravelDebugbar $debugbar) | ||
| { | ||
| $this->app = $app; | ||
| $this->debugbar = $debugbar; | ||
| } | ||
|
|
||
| /** | ||
| * Handle an incoming request. | ||
| * | ||
|
|
@@ -20,18 +57,14 @@ class InjectDebugbar extends BaseMiddleware | |
| */ | ||
| public function handle($request, Closure $next) | ||
| { | ||
| if (!$this->debugbar->isEnabled() || $this->inExceptArray($request)) { | ||
| if (!$this->debugbar->isEnabled() || $this->debugbar->requestIsExcluded($request)) { | ||
| return $next($request); | ||
| } | ||
|
|
||
| $this->debugbar->boot(); | ||
|
|
||
| try { | ||
| /** @var \Illuminate\Http\Response $response */ | ||
| $response = $next($request); | ||
| } catch (Throwable $e) { | ||
| $response = $this->handleException($request, $e); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this try / catch removed? |
||
| /** @var \Illuminate\Http\Response $response */ | ||
| $response = $next($request); | ||
|
|
||
| // Database table might not exist yet | ||
| try { | ||
|
|
@@ -49,14 +82,21 @@ public function handle($request, Closure $next) | |
| $this->debugbar->setStorage(null); | ||
| } | ||
|
|
||
| // Modify the response to add the Debugbar if allowed | ||
| // Only inject the Debugbar into the response if the user is allowed to view it | ||
| if ( | ||
| ($user && $user->hasAccess('winter.debugbar.access_debugbar')) || | ||
| Config::get('winter.debugbar::allow_public_access', false) | ||
| !($user && $user->hasAccess('winter.debugbar.access_debugbar')) && | ||
| !Config::get('winter.debugbar::allow_public_access', false) | ||
| ) { | ||
| $this->debugbar->modifyResponse($request, $response); | ||
| // Prevent the visual Debugbar from being injected while still allowing | ||
| // permitted requests to be stored (handled by setStorage above) | ||
| Config::set('debugbar.inject', false); | ||
| } | ||
|
|
||
| // Modify the response to add the Debugbar (and store the request, when permitted). | ||
| // This flags the response as modified, so the base ServiceProvider's RequestHandled | ||
| // listener will skip re-processing it. | ||
| $this->debugbar->handleResponse($request, $response); | ||
|
|
||
| return $response; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't need the FQCN here, it's already imported in this file