Laravel5.5 Source Detailed –laravel-debugbar and the use of Elementui-ajax considerations
Regarding the processing of laravel to the middleware, please refer to the middleware to test the other text,
Laravel5.5 source code Detailed-middleware middleware analysis
This is just a quick record of the Debugbar transaction process.
I am capturing middleware in the then function of Illuminate\pipeline\pipeline, and I find that the following middleware
Array:6 [
0 => "Illuminate\foundation\http\middleware\checkformaintenancemode"
1 => "Illuminate\ Foundation\http\middleware\validatepostsize "
2 =>" App\http\middleware\trimstrings "
3 =>" Illuminate \foundation\http\middleware\convertemptystringstonull "
4 =>" App\http\middleware\trustproxies "
5 => "Barryvdh\debugbar\middleware\injectdebugbar"
]
Array:6 [
0 =>] app\http\middleware\ Encryptcookies "
1 =>" Illuminate\cookie\middleware\addqueuedcookiestoresponse "
2 =>" Illuminate\ Session\middleware\startsession "
3 =>" Illuminate\view\middleware\shareerrorsfromsession "
4 =>" App\http\middleware\verifycsrftoken "
5 =>" Illuminate\routing\middleware\substitutebindings "
]
Which includes this barryvdh\debugbar\middleware\injectdebugbar, which was discovered and introduced in the Vendor\composer\installed.json when the Larave was started,
The configuration of the
Laravel-debugbar in Barryvdh\laravel-debugbar\config\debugbar, which is explained in more detail, is not repeated here. By the way, this class is registered in the Barryvdh\debugbar\serviceprovider,
<?php namespace Barryvdh\debugbar;
Use barryvdh\debugbar\middleware\debugbarenabled;
Use Barryvdh\debugbar\middleware\injectdebugbar;
Use Debugbar\dataformatter\dataformatter;
Use Debugbar\dataformatter\dataformatterinterface;
Use Illuminate\contracts\http\kernel;
Use Illuminate\routing\router;
Use Illuminate\session\sessionmanager;
Class ServiceProvider extends \illuminate\support\serviceprovider {protected $defer = false; Public Function Register () {$configPath = __dir__. '/..
/config/debugbar.php ';
$this->mergeconfigfrom ($configPath, ' Debugbar ');
$this->app->alias (Dataformatter::class, Dataformatterinterface::class); $this->app->singleton (Laraveldebugbar::class, function () {$debugbar = new Laraveldebugbar ($this-&G
T;app); if ($this->app->bound (Sessionmanager::class)) {$sessionManager = $this->app->make (session ManageR::class);
$httpDriver = new Symfonyhttpdriver ($sessionManager);
$debugbar->sethttpdriver ($httpDriver);
return $debugbar;
}
);
$this->app->alias (laraveldebugbar::class, ' Debugbar '); $this->app->singleton (' Command.debugbar.clear ', function ($app) {return new console\cle
Arcommand ($app [' Debugbar ']);
}
);
$this->commands ([' command.debugbar.clear ']); ///There are many event-handling features registered here, which are the public Function boot () {$configPath = __dir__ that may be used when processing the request. '/..
/config/debugbar.php ';
$this->publishes ([$configPath => $this->getconfigpath ()], ' config '); $routeConfig = [' namespace ' => ' barryvdh\debugbar\controllers ', ' prefix ' => $this->app[' Config ']->get (' Debugbar.route_prefix '), ' domain ' => $this->app[' config ']->get (' Debugbar.route_domain '), ' middleware ' => [Debugbarenabled::class],]; $this->getrouter ()->group ($routeConfig, function ($router) {$router->get (' Open ', [' u
Ses ' => ' openhandlercontroller@handle ', ' as ' => ' Debugbar.openhandler ',]); $router->get (' Clockwork/{id} ', [' Uses ' => ' openhandlercontroller@clockwork ', ' as '
=> ' Debugbar.clockwork ',]); $router->get (' assets/stylesheets ', [' Uses ' => ' assetcontroller@css ', ' as ' => ' de
Bugbar.assets.css ',]); $router->get (' Assets/javascript ', [' Uses ' => ' assetcontroller@js ', ' as ' => ' Debu
Gbar.assets.js ',]);
});
$this->registermiddleware (Injectdebugbar::class); } protected function Getrouter () {return $this->app[' router '];
} protected function Getconfigpath () {return Config_path (' debugbar.php '); } protected function Publishconfig ($configPath) {$this->publishes ([$configPath => config_path (' Debu
Gbar.php ')], ' config ');
} protected function Registermiddleware ($middleware) {$kernel = $this->app[kernel::class];
$kernel->pushmiddleware ($middleware); The public Function provides () {return [' Debugbar ', ' command.debugbar.clear ', Dataformatterinterface::class
, Laraveldebugbar::class]; }
}
Focus here, the handle function that actually handles response and request is in Barryvdh\debugbar\middleware\injectdebugbar,
<?php namespace Barryvdh\debugbar\middleware;
Use Error;
Use Closure;
Use Exception;
Use Illuminate\http\request;
Use Barryvdh\debugbar\laraveldebugbar;
Use Illuminate\contracts\container\container;
Use Illuminate\contracts\debug\exceptionhandler;
Use Symfony\component\debug\exception\fatalthrowableerror;
Class Injectdebugbar {protected $container;
protected $debugbar;
protected $except = []; Public function __construct (Container $container, Laraveldebugbar $debugbar) {$this->container = $containe
R
$this->debugbar = $debugbar;
$this->except = config (' debugbar.except ')?: [];
The public function handle ($request, Closure $next) {//If Debugbar is not enabled, or if the incoming request is empty, it is returned directly.
if (! $this->debugbar->isenabled () | | $this->inexceptarray ($request)) {return $next ($request);
}//Registration transaction Function $this->debugbar->boot (); try {/** @var \illuminate\http\response $response//You can see that the handle is processed, that is, in (back and forth two times after handle) back to the processing function,//So here first $next ()
$response = $next ($request);
catch (Exception $e) {$response = $this->handleexception ($request, $e);
The catch (Error $error) {$e = new Fatalthrowableerror ($error);
$response = $this->handleexception ($request, $e); //Handle the post, then the Debugbar work time after next () Modify the response to add the Debugbar $this->DEBUGB
Ar->modifyresponse ($request, $response);
After processing, return the result returns $response; }
The above paragraph, what really works is this sentence: $this->debugbar->modifyresponse ($request, $response), it is the place where Debugbar modifies response, Look at the Barryvdh\debugbar\laraveldebugbar, please note the comments,
Public Function ModifyResponse (Request $request, Response $response) {//If not enabled, return directly to Response $app = $thi
s->app;
if (! $this->isenabled () | | $this->isdebugbarrequest ()) {return $response; }//Show the HTTP Response Exception in the Debugbar, when available//if there is an HTTP exception, the print appears if (IS
Set ($response->exception)) {$this->addthrowable ($response->exception);
//Do not debug settings information, default is unwanted if ($this->shouldcollect (' config ', false)) {try {
$configCollector = new Configcollector ();
$configCollector->setdata ($app [' config ']->all ());
$this->addcollector ($configCollector);
The catch (\exception $e) {$this->addthrowable new Exception ( ' Cannot add Configcollector to Laravel Debugbar: '. $e->getmessage (), $e; GetCode (), $e)); }//If binding session debugging if ($this->app->bound (Sessionmanager::class)) {/** @var \i
Lluminate\session\sessionmanager $sessionManager * * * $sessionManager = $app->make (sessionmanager::class);
$httpDriver = new Symfonyhttpdriver ($sessionManager, $response);
$this->sethttpdriver ($httpDriver);
if ($this->shouldcollect (' session ') &&! $this->hascollector (' session ')) {try {
$this->addcollector (New Sessioncollector ($sessionManager));
The catch (\exception $e) {$this->addthrowable new Exception ( ' Cannot add Sessioncollector to Laravel Debugbar: '.
$e->getmessage (), $e->getcode (), $e
) );
}} else {$sessionManager = null; //Seemingly the meaning of this sentence is, if only one session is debugged?
has not entered the source code to delve into.
if ($this->shouldcollect (' Symfony_request ', true) &&! $this->hascollector (' request ')) {try {
$this->addcollector (New Requestcollector ($request, $response, $sessionManager));
The catch (\exception $e) {$this->addthrowable new Exception ( ' Cannot add Symfonyrequestcollector to Laravel Debugbar: '.
$e->getmessage (), $e->getcode (), $e)
); }//If you want to support clockwork debugging (for example, support for Chrome clockwork Debugging) if ($app [' Config ']->get (' debugbar.clockwork ') ) &&! $this->hascollector (' Clockwork ')) {try {$this->addcollector (new Clockworkcollector $r Equest,$response, $sessionManager));
The catch (\exception $e) {$this->addthrowable new Exception ( ' Cannot add Clockworkcollector to Laravel Debugbar: '.
$e->getmessage (), $e->getcode (), $e)
);
$this->addclockworkheaders ($response); //First of all, this is not a redirect () Request (Refresh page)//This judgment of the statement prototype is $this->statuscode >= && $this->st
Atuscode < 400;
function prototypes in vendor\symfony\http-foundation\response.php, if ($response->isredirection ()) {try {
$this->stackdata ();
The catch (\exception $e) {$app [' Log ']->error (' Debugbar Exception: '. $e->getmessage ()); } elseif (///If Ajax is requested, and debugging Ajax is already set, this is handled in $this->isjsonrequest ($request) &&am
P $app [' config ']->get (' Debugbar.capture_ajax ', True)} {try {$this->sendda
Tainheaders (TRUE); if ($app [' Config ']->get (' debugbar.add_ajax_timing ', false)] {$this->addservertimingheaders ($res
Ponse); {\exception $e) {$app [' Log ']->error (' Debugbar Exception: '. $e->getmessage (
)); } elseif (///If headers has content-type this label and is not HTML, then it should be JSON data//Obviously, only the Content-type=json data
Operations,//For other types of data, such as pictures, MSWord, and so on, then throw the exception directly ($response->headers->has (' Content-type ') && Strpos ($response->headers->get (' Content-type '), ' html ') = = false) | | $request->getrequestformat ()!== ' html ' | | $response->getcontent () = = False) {try {//Just collect + store data, don ' t INJ
ECT it. $this->collECT ();
The catch (\exception $e) {$app [' Log ']->error (' Debugbar Exception: '. $e->getmessage ());
} elseif ($app [' Config ']->get (' Debugbar.inject ', True)} {//For ordinary situations, Debugbar will modify the response here and inject the render
try {$this->injectdebugbar ($response);
The catch (\exception $e) {$app [' Log ']->error (' Debugbar Exception: '. $e->getmessage ());
} return $response; }
The use of the $app [' config '] is the original,
Repository {#24
#items: array:13 [
app] =>