Download the PHP package lsrur/inspector without Composer
On this page you can find all versions of the php package lsrur/inspector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lsrur/inspector
More information about lsrur/inspector
Files in lsrur/inspector
Package inspector
Short Description Laravel Inspector, debugging and profiling tools for Web Artisans
License MIT
Informations about the package inspector
Laravel Inspector
- At a Glance
- Installation
- Configuration
- Usage
- Messages
- Timers
- Redirects
- Dump and die
- Exceptions
- VIEW/AJAX/API requests, how it works
- License
At a Glance
![]() |
![]() |
---|---|
Messages | Exceptions |
![]() |
![]() |
---|---|
idd() - Dump and die on steroids | idd() SQLs page |
![]() |
![]() |
---|---|
Laravel Inspector as the default Exception renderer | Timers and Timeline |
![]() |
![]() |
---|---|
Redirection | API/Ajax calls |
![]() |
![]() |
---|---|
Using Postman REST client app | laravel_inspector=dump parameter |
Available Collectors | Information about |
---|---|
MessageCollector | User's messages and dumps |
ExceptionCollector | Exceptions |
DBCollector | Queries, including execution time and parameters binding |
TimersCollector | Timers and time stamps |
RoutesCollector | Application routes |
RequestCollector | Current Request |
ResponseCollector | Current Response |
SessionCollector | Session variables |
ServerCollector | $_SERVER dump |
More to come... |
Installation
This package was tested under PHP 5.6, PHP 7, Laravel 5.2 and Laravel 5.3-Dev
Installing the package via composer:
Next, add InspectorServiceProvider to the providers array in config/app.php
:
And this Facade in the same configuration file:
For usage only during development and not during production,
do not edit the config/app.php
and add the following to your AppServiceProvider
:
Configuration
In order to use Inspector as the default exceptions renderer, add the following line in the file app/Exceptions/Handler.php
of your Laravel project:
For usage only during development:
Usage
Laravel inspector can be invoked using the Facade, the provided helper functions and a Blade directive:
Laravel inspector will only be active if the config variable app.debug
is true.
Anyway, you can temporarily turn Inspector off (just for the current request) with:
Messages
You can inspect objects and variables with the following methods, each of which has its own output format:
Method | Description |
---|---|
log([string $description,] mixed $data) |
Outputs data with "log" format |
info([string $description,] mixed $data) |
Outputs data with "info" format |
error([string $description,] mixed $data) |
Outputs data with "error" format |
warning([string $description,] mixed $data) |
Outputs data with "warning" format |
success([string $description,] mixed $data) |
Outputs data with "success" format |
table([string $description,] mixed $data) |
Outputs data inside a table |
Examples:
Additionally, you can use the "inspect" helper function to quickly inspect objects and variables.
Grouping Messages
Laravel Inspector allows you to group messages into nodes and subnodes:
In addition to the ability to group information, each group and subgroup excecution time will be measured and shown. If you forget to close a group, Laravel Inspector will automatically do it at the end of the script, but the excecution time for that group can not be taken.
Timers
Method | Description |
---|---|
time(string $timerName) |
Starts a timer |
timeEnd(string $timerName) |
Ends a timer |
timeStamp(string $name) |
Adds a single marker to the timeline |
Examples:
Redirects
Laravel Inspector handles redirects smoothly; showing the collectors bag for both, the original and the target views.
Dump and die
The dd()
method (or idd()
helper) will dump the entire collectors bag and terminates the script:
As the rest of the package, this feature intelligently determines how will be the format of the output, even if the call was performed from CLI.
Another way to make an inspection, but without interrupting the flow of the request/response, is by adding the parameter laravel_inspector=dump
to the URL:
http://myapp.dev/contacts?id=1&laravel_inspector=dump
Thus, Laravel Inspector wont be activated until the a terminable middleware is reached.
Exceptions
The function addException()
will inspect our caught exceptions:
Optionally, you can setup LI as the default exception renderer during development time (app.debug=true). Refer to the configuration to do so.
VIEW/AJAX/API requests, how it works
Laravel Inspector (LI) automatically detects the type of the request/response pair and determines the output format. If a View response is detected, the code needed to elegantly show the collected information in the browser console will be injected as a javascript into that view. Along with this, LI will also add a small piece of pure javascript code that serves as a generic http interceptor, which will examine subsequent AJAX calls looking for information injected by LI (this interceptor was tested under pure javascript, Angular 1.x ($http) and jQuery ($.ajax) and should work with any js framework). The interceptor also adds a header in each client AJAX call to let LI know that the interceptor is present. Then, from Laravel side, during an AJAX request or a JSON response, LI will send a script to be interpreted (and properly rendered in the browsers console) by the interceptor, OR a pure Json if that header is not present and then assuming that the request was sent from cURL, a REST client app or something else.
If you are developing, for example, an SPA and using Laravel only for the API but not to serve the web page/s, you can include the following code in your client app to take full advantage of all formatting features of Laravel Inspector.
License
Laravel Inspector is licensed under the MIT License.