Commit 1899490c authored by moshe weitzman's avatar moshe weitzman

Revert "Issue #2839515 by AdamPS, willzyx, rpsu: Remove Kint module and create...

Revert "Issue #2839515 by AdamPS, willzyx, rpsu: Remove Kint module and create a kint dumper plugin in devel"

This reverts commit 42f50763.
parent 42f50763
......@@ -44,6 +44,9 @@ This module requires no modules outside of Drupal core.
INCLUDED MODULES AND FEATURES
-----------------------------
Devel Kint - Provides a dpr() function, which pretty prints variables.
Useful during development. Also see similar helpers like dpm(), dvm().
Webprofiler - Adds a debug bar at bottom of all pages with tons of useful
information like a query list, cache hit/miss data, memory profiling, page
speed, php info, session info, etc.
......
......@@ -41,12 +41,7 @@
"require": {
"symfony/var-dumper": "~2.7|^3|^4"
},
"suggest": {
"kint-php/kint": "Kint provides an informative display of arrays/objects. Useful for debugging and developing."
},
"conflict": {
"kint-php/kint": "<3"
},
"suggest": {},
"extra": {
"drush": {
"services": {
......
......@@ -345,34 +345,6 @@ if (!function_exists('ddm')) {
}
}
if (!function_exists('kint')) {
/**
* Prints passed argument(s) using Kint debug tool.
*
* Wrapper for DevelDumperManager::dump().
*
* @see \Drupal\devel\DevelDumperManager::dump()
*/
function kint() {
$args = func_get_args();
return \Drupal::service('devel.dumper')->dump($args, NULL, 'kint');
}
}
if (!function_exists('ksm')) {
/**
* Prints passed argument(s) to the 'message' area of the page.
*
* Wrapper for DevelDumperManager::message().
*
* @see \Drupal\devel\DevelDumperManager::message()
*/
function ksm() {
$args = func_get_args();
return \Drupal::service('devel.dumper')->message($args, NULL, 'kint');
}
}
/**
* Wrapper for DevelDumperManager::message().
*
......
WHAT IS IT?
-----------
Kint for PHP is a tool designed to present your debugging data in the absolutely
best way possible.
In other words, it's var_dump() and debug_backtrace() on steroids. Easy to use,
but powerful and customizable. An essential addition to your development
toolbox.
USAGE
-----
This module allows to use these aliases:
kint($data1, $data2, $data3, ...);
ksm($data1, $data2, $data3, ...)
kint_trace();
But to get the most out of Kint, you will want to use directly the Kint class:
kint_require();
Kint::dump($data);
Learn more about Kint: http://raveren.github.io/kint/
The Kint class function dd() will not work as expected, because this alias
is already defined in devel.module for other purposes.
CONTACTS
--------
Module author:
Alexander Danilenko
danilenko.dn@gmail.com
https://drupal.org/user/1072104
Kint author:
Rokas Šleinius a.k.a. Raveren
raveren@gmail.com
https://github.com/raveren
\ No newline at end of file
name: 'Devel Kint'
type: module
description: 'Wrapper for Kint debugging tool'
package: Development
core: 8.x
tags:
- developer
<?php
use Drupal\Core\Render\Markup;
/**
* Alias of Kint::dump().
*
* Prints passed argument(s) using Kint debug tool.
*/
function kint() {
kint_require();
if (\Drupal::currentUser()->hasPermission('access kint')) {
$args = func_get_args();
if (PHP_SAPI === 'cli') {
s($args);
}
else {
\Kint::dump($args);
}
}
}
/**
* Alias of Kint::trace().
*
* Prints backtrace in Kint debug tool.
*/
function kint_trace() {
kint_require();
if (\Drupal::currentUser()->hasPermission('access kint')) {
call_user_func_array(array('Kint', 'trace'), array());
}
}
/**
* Alias of Kint::kintLite().
*
* Prints with lightweight formatting, using whitespace for formatting instead
* of HTML.
*/
function kint_lite() {
if (\Drupal::currentUser()->hasPermission('access kint')) {
$args = func_get_args();
call_user_func_array('kintLite', $args);
}
}
/**
* Prints passed argument(s) to the 'message' area of the page.
*/
function ksm() {
kint_require();
if (\Drupal::currentUser()->hasPermission('access kint')) {
$args = func_get_args();
$msg = @Kint::dump($args);
drupal_set_message(Markup::create($msg));
}
}
/**
* Load the Kint class.
*/
function kint_require() {
return require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'kint') . '/kint/Kint.class.php';
}
access kint:
description: 'View developer debug output.'
title: 'Access kint information'
restrict access: TRUE
services:
kint.twig.kint_extension:
class: Drupal\kint\Twig\KintExtension
tags:
- { name: twig.extension }
/config.php
/.idea
\ No newline at end of file
This diff is collapsed.
The MIT License (MIT)
Copyright (c) 2013 Rokas Šleinius (raveren@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
# Kint - debugging helper for PHP developers
[![Total Downloads](https://poser.pugx.org/raveren/kint/downloads.png)](https://packagist.org/packages/raveren/kint)
> **New version** v1.0.0 is released with more than two years of active development - changes are too numerous to list, but there's CLI output and literally hundreds of improvements and additions.
![Screenshot](http://raveren.github.com/kint/img/preview.png)
## What am I looking at?
At first glance Kint is just a pretty replacement for **[var_dump()](http://php.net/manual/en/function.var-dump.php)**, **[print_r()](http://php.net/manual/en/function.print-r.php)** and **[debug_backtrace()](http://php.net/manual/en/function.debug-backtrace.php)**.
However, it's much, *much* more than that. Even the excellent `xdebug` var_dump improvements don't come close - you will eventually wonder how you developed without it.
Just to list some of the most useful features:
* The **variable name and place in code** where Kint was called from is displayed;
* You can **disable all Kint output easily and on the fly** - so you can even debug live systems without anyone knowing (even though you know you shouldn't be doing that!:).
* **CLI is detected** and formatted for automatically (but everything can be overridden on the fly) - if your setup supports it, the output is colored too:
![Kint CLI output](http://i.imgur.com/6B9MCLw.png)
* **Debug backtraces** are finally fully readable, actually informative and a pleasure to the eye.
* Kint has been **in active development for more than six years** and is shipped with [Drupal 8](https://www.drupal.org/) by default as part of its devel suite. You can trust it not being abandoned or getting left behind in features.
* Variable content is **displayed in the most informative way** - and you *never, ever* miss anything! Kint guarantees you see every piece of physically available information about everything you are dumping*;
* <sup>in some cases, the content is truncated where it would otherwise be too large to view anyway - but the user is always made aware of that;</sup>
* Some variable content types have an alternative display - for example you will be able see `JSON` in its raw form - but also as an associative array:
![Kint displays data intelligently](http://i.imgur.com/9P57Ror.png)
There are more than ten custom variable type displays inbuilt and more are added periodically.
## Installation and Usage
One of the main goals of Kint is to be **zero setup**.
[Download the archive](https://github.com/raveren/kint/releases/download/1.0.2/kint.zip) and simply
```php
<?php
require '/kint/Kint.class.php';
```
**Or, if you use Composer:**
```json
"require": {
"raveren/kint": "^1.0"
}
```
Or just run `composer require raveren/kint`
**That's it, you can now use Kint to debug your code:**
```php
########## DUMP VARIABLE ###########################
Kint::dump($GLOBALS, $_SERVER); // pass any number of parameters
// or simply use d() as a shorthand:
d($_SERVER);
########## DEBUG BACKTRACE #########################
Kint::trace();
// or via shorthand:
d(1);
############# BASIC OUTPUT #########################
# this will show a basic javascript-free display
s($GLOBALS);
######### WHITESPACE FORMATTED OUTPUT ##############
# this will be garbled if viewed in browser as it is whitespace-formatted only
~d($GLOBALS); // just prepend with the tilde
########## MISCELLANEOUS ###########################
# this will disable kint completely
Kint::enabled(false);
ddd('Get off my lawn!'); // no effect
Kint::enabled(true);
ddd( 'this line will stop the execution flow because Kint was just re-enabled above!' );
```
Note, that Kint *does* have configuration (like themes and IDE integration!), but it's in need of being rewritten, so I'm not documenting it yet.
## Tips & Tricks
* Kint is enabled by default, call `Kint::enabled(false);` to turn its funcionality completely off. The *best practice* is to enable Kint in DEVELOPMENT environment only (or for example `Kint::enabled($_SERVER['REMOTE_ADDR'] === '<your IP>');`) - so even if you accidentally leave a dump in production, no one will know.
* `sd()` and `ddd()` are shorthands for `s();die;` and `d();die;` respectively.
* **Important:** The older shorthand `dd()` is deprecated due to compatibility issues and will eventually be removed. Use the analogous `ddd()` instead.
* When looking at Kint output, press <kbd>D</kbd> on the keyboard and you will be able to traverse the tree with arrows and tab keys - and expand/collapse nodes with space or enter.
* Double clicking the `[+]` sign in the output will expand/collapse ALL nodes; triple clicking big blocks of text will select it all.
* Clicking the tiny arrows on the right of the output open it in a separate window where you can keep it for comparison.
* To catch output from Kint just assign it to a variable<sup>beta</sup>
```php
$o = Kint::dump($GLOBALS);
// yes, the assignment is automatically detected, and $o
// now holds whatever was going to be printed otherwise.
// it also supports modifiers (read on) for the variable:
~$o = Kint::dump($GLOBALS); // this output will be in whitespace
```
* There are a couple of real-time modifiers you can use:
* `~d($var)` this call will output in plain text format.
* `+d($var)` will disregard depth level limits and output everything (careful, this can hang your browser on huge objects)
* `!d($var)` will show expanded rich output.
* `-d($var)` will attempt to `ob_clean` the previous output so if you're dumping something inside a HTML page, you will still see Kint output.
You can combine modifiers too: `~+d($var)`
* To force a specific dump output type just pass it to the `Kint::enabled()` method. Available options are: `Kint::MODE_RICH` (default), `Kint::MODE_PLAIN`, `Kint::MODE_WHITESPACE` and `Kint::MODE_CLI`:
```php
Kint::enabled(Kint::MODE_WHITESPACE);
$kintOutput = Kint::dump($GLOBALS);
// now $kintOutput can be written to a text log file and
// be perfectly readable from there
```
* To change display theme, use `Kint::$theme = '<theme name>';` where available options are: `'original'` (default), `'solarized'`, `'solarized-dark'` and `'aante-light'`. Here's an (outdated) preview:
![Kint themes](http://raveren.github.io/kint/img/theme-preview.png)
* Kint also includes a naïve profiler you may find handy. It's for determining relatively which code blocks take longer than others:
```php
Kint::dump( microtime() ); // just pass microtime()
sleep( 1 );
Kint::dump( microtime(), 'after sleep(1)' );
sleep( 2 );
ddd( microtime(), 'final call, after sleep(2)' );
```
![Kint profiling feature](http://i.imgur.com/tmHUMW4.png)
----
[Visit the project page](http://raveren.github.com/kint/) for documentation, configuration, and more advanced usage examples.
### Author
**Rokas Šleinius** (Raveren)
### License
Licensed under the MIT License
{
"name": "raveren/kint",
"description": "Kint - debugging helper for PHP developers",
"keywords": ["kint", "php", "debug"],
"type": "library",
"homepage": "https://github.com/raveren/kint",
"license": "MIT",
"authors": [
{
"name": "Rokas Šleinius",
"homepage": "https://github.com/raveren"
},
{
"name": "Contributors",
"homepage": "https://github.com/raveren/kint/contributors"
}
],
"require": {
"php": ">=5.1.0"
},
"autoload": {
"files": ["Kint.class.php"]
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
\ No newline at end of file
<?php
isset( $GLOBALS['_kint_settings'] ) or $GLOBALS['_kint_settings'] = array();
$_kintSettings = &$GLOBALS['_kint_settings'];
/** @var bool if set to false, kint will become silent, same as Kint::enabled(false) or Kint::$enabled = false */
$_kintSettings['enabled'] = true;
/**
* @var bool whether to display where kint was called from
*/
$_kintSettings['displayCalledFrom'] = true;
/**
* @var string format of the link to the source file in trace entries. Use %f for file path, %l for line number.
* Defaults to xdebug.file_link_format if not set.
*
* [!] EXAMPLE (works with for phpStorm and RemoteCall Plugin):
*
* $_kintSettings['fileLinkFormat'] = 'http://localhost:8091/?message=%f:%l';
*
*/
$_kintSettings['fileLinkFormat'] = ini_get( 'xdebug.file_link_format' );
/**
* @var array base directories of your application that will be displayed instead of the full path. Keys are paths,
* values are replacement strings
*
* Defaults to array( $_SERVER['DOCUMENT_ROOT'] => '&lt;ROOT&gt;' )
*
* [!] EXAMPLE (for Kohana framework):
*
* $_kintSettings['appRootDirs'] = array(
* APPPATH => 'APPPATH', // make sure the constants are already defined at the time of including this config file
* SYSPATH => 'SYSPATH',
* MODPATH => 'MODPATH',
* DOCROOT => 'DOCROOT',
* );
*
* [!] EXAMPLE #2 (for a semi-universal approach)
*
* $_kintSettings['appRootDirs'] = array(
* realpath( __DIR__ . '/../../..' ) => 'ROOT', // go up as many levels as needed in the realpath() param
* );
*
* $_kintSettings['fileLinkFormat'] = 'http://localhost:8091/?message=%f:%l';
*
*/
$_kintSettings['appRootDirs'] = isset( $_SERVER['DOCUMENT_ROOT'] )
? array( $_SERVER['DOCUMENT_ROOT'] => '&lt;ROOT&gt;' )
: array();
/** @var int max length of string before it is truncated and displayed separately in full. Zero or false to disable */
$_kintSettings['maxStrLength'] = 80;
/** @var array possible alternative char encodings in order of probability, eg. array('windows-1251') */
$_kintSettings['charEncodings'] = array(
'UTF-8',
'Windows-1252', # Western; includes iso-8859-1, replace this with windows-1251 if you have Russian code
'euc-jp', # Japanese
# all other charsets cannot be differentiated by PHP and/or are not supported by mb_* functions,
# I need a better means of detecting the codeset, no idea how though :(
// 'iso-8859-13', # Baltic
// 'windows-1251', # Cyrillic
// 'windows-1250', # Central European
// 'shift_jis', # Japanese
// 'iso-2022-jp', # Japanese
);
/** @var int max array/object levels to go deep, if zero no limits are applied */
$_kintSettings['maxLevels'] = 7;
/** @var string name of theme for rich view */
$_kintSettings['theme'] = 'original';
/** @var bool enable detection when Kint is command line. Formats output with whitespace only; does not HTML-escape it */
$_kintSettings['cliDetection'] = true;
/** @var bool in addition to above setting, enable detection when Kint is run in *UNIX* command line.
* Attempts to add coloring, but if seen as plain text, the color information is visible as gibberish
*/
$_kintSettings['cliColors'] = true;
unset( $_kintSettings );
\ No newline at end of file
<?php
class Kint_Decorators_Plain
{
private static $_enableColors;
private static $_cliEffects = array(
# effects
'bold' => '1', 'dark' => '2',
'italic' => '3', 'underline' => '4',
'blink' => '5', 'reverse' => '7',
'concealed' => '8', 'default' => '39',
# colors
'black' => '30', 'red' => '31',
'green' => '32', 'yellow' => '33',
'blue' => '34', 'magenta' => '35',
'cyan' => '36', 'light_gray' => '37',
'dark_gray' => '90', 'light_red' => '91',
'light_green' => '92', 'light_yellow' => '93',
'light_blue' => '94', 'light_magenta' => '95',
'light_cyan' => '96', 'white' => '97',
# backgrounds
'bg_default' => '49', 'bg_black' => '40',
'bg_red' => '41', 'bg_green' => '42',
'bg_yellow' => '43', 'bg_blue' => '44',
'bg_magenta' => '45', 'bg_cyan' => '46',
'bg_light_gray' => '47', 'bg_dark_gray' => '100',
'bg_light_red' => '101', 'bg_light_green' => '102',
'bg_light_yellow' => '103', 'bg_light_blue' => '104',
'bg_light_magenta' => '105', 'bg_light_cyan' => '106',
'bg_white' => '107',
);
private static $_utfSymbols = array(
'┌', '═', '┐',
'│',
'└', '─', '┘',
);
private static $_winShellSymbols = array(
"\xda", "\xdc", "\xbf",
"\xb3",
"\xc0", "\xc4", "\xd9",
);
private static $_htmlSymbols = array(
"&#9484;", "&#9604;", "&#9488;",
"&#9474;",
"&#9492;", "&#9472;", "&#9496;",
);
public static function decorate( kintVariableData $kintVar, $level = 0 )
{
$output = '';
if ( $level === 0 ) {
$name = $kintVar->name ? $kintVar->name : 'literal';
$kintVar->name = null;
$output .= self::_title( $name );
}
$space = str_repeat( $s = ' ', $level );
$output .= $space . self::_drawHeader( $kintVar );
if ( $kintVar->extendedValue !== null ) {
$output .= ' ' . ( $kintVar->type === 'array' ? '[' : '(' ) . PHP_EOL;
if ( is_array( $kintVar->extendedValue ) ) {
foreach ( $kintVar->extendedValue as $v ) {
$output .= self::decorate( $v, $level + 1 );
}
} elseif ( is_string( $kintVar->extendedValue ) ) {
$output .= $space . $s . $kintVar->extendedValue . PHP_EOL; # depth too great or similar
} else {
$output .= self::decorate( $kintVar->extendedValue, $level + 1 ); //it's kintVariableData
}
$output .= $space . ( $kintVar->type === 'array' ? ']' : ')' ) . PHP_EOL;
} else {
$output .= PHP_EOL;
}
return $output;
}
public static function decorateTrace( $traceData )
{
$output = self::_title( 'TRACE' );
$lastStep = count( $traceData );
foreach ( $traceData as $stepNo => $step ) {
$title = str_pad( ++$stepNo . ': ', 4, ' ' );
$title .= self::_colorize(
( isset( $step['file'] ) ? self::_buildCalleeString( $step ) : 'PHP internal call' ),
'title'
);
if ( !empty( $step['function'] ) ) {
$title .= ' ' . $step['function'];
if ( isset( $step['args'] ) ) {
$title .= '(';
if ( empty( $step['args'] ) ) {
$title .= ')';
} else {
}
$title .= PHP_EOL;
}
}
$output .= $title;
if ( !empty( $step['args'] ) ) {
$appendDollar = $step['function'] === '{closure}' ? '' : '$';
$i = 0;
foreach ( $step['args'] as $name => $argument ) {
$argument = kintParser::factory(
$argument,
$name ? $appendDollar . $name : '#' . ++$i
);
$argument->operator = $name ? ' =' : ':';
$maxLevels = Kint::$maxLevels;
if ( $maxLevels ) {
Kint::$maxLevels = $maxLevels + 2;
}
$output .= self::decorate( $argument, 2 );
if ( $maxLevels ) {
Kint::$maxLevels = $maxLevels;
}
}
$output .= ' )' . PHP_EOL;
}
if ( !empty( $step['object'] ) ) {
$output .= self::_colorize(
' ' . self::_char( '─', 27 ) . ' Callee object ' . self::_char( '─', 34 ),
'title'
);
$maxLevels = Kint::$maxLevels;
if ( $maxLevels ) {
# in cli the terminal window is filled too quickly to display huge objects
Kint::$maxLevels = Kint::enabled() === Kint::MODE_CLI
? 1
: $maxLevels + 1;
}
$output .= self::decorate( kintParser::factory( $step['object'] ), 1 );
if ( $maxLevels ) {
Kint::$maxLevels = $maxLevels;
}
}
if ( $stepNo !== $lastStep ) {
$output .= self::_colorize( self::_char( '─', 80 ), 'title' );
}
}
return $output;
}
private static function _colorize( $text, $type, $nlAfter = true )
{
$nlAfter = $nlAfter ? PHP_EOL : '';
switch ( Kint::enabled() ) {
case Kint::MODE_PLAIN:
if ( !self::$_enableColors ) return $text . $nlAfter;
switch ( $type ) {
case 'value':
$text = "<i>{$text}</i>";
break;
case 'type':
$text = "<b>{$text}</b>";
break;
case 'title':
$text = "<u>{$text}</u>";
break;
}
return $text . $nlAfter;
break;
case Kint::MODE_CLI:
if ( !self::$_enableColors ) return $text . $nlAfter;
$optionsMap = array(
'title' => "\x1b[36m", # cyan
'type' => "\x1b[35;1m", # magenta bold
'value' => "\x1b[32m", # green
);
return $optionsMap[ $type ] . $text . "\x1b[0m" . $nlAfter;
break;
case Kint::MODE_WHITESPACE:
default:
return $text . $nlAfter;
break;
}
}
private static function _char( $char, $repeat = null )
{
switch ( Kint::enabled() ) {
case Kint::MODE_PLAIN:
$char = self::$_htmlSymbols[ array_search( $char, self::$_utfSymbols, true ) ];
break;
case Kint::MODE_CLI:
$inWindowsShell = PHP_SAPI === 'cli' && DIRECTORY_SEPARATOR !== '/';
if ( $inWindowsShell ) {
$char = self::$_winShellSymbols[ array_search( $char, self::$_utfSymbols, true ) ];
}
break;
case Kint::MODE_WHITESPACE:
default:
break;
}
return $repeat ? str_repeat( $char, $repeat ) : $char;
}
private static function _title( $text )
{
$escaped = kintParser::escape( $text );
$lengthDifference = strlen( $escaped ) - strlen( $text );
return
self::_colorize(
self::_char( '┌' ) . self::_char( '─', 78 ) . self::_char( '┐' ) . PHP_EOL
. self::_char( '│' ),
'title',
false
)
. self::_colorize( str_pad( $escaped, 78 + $lengthDifference, ' ', STR_PAD_BOTH ), 'title', false )
. self::_colorize( self::_char( '│' ) . PHP_EOL
. self::_char( '└' ) . self::_char( '─', 78 ) . self::_char( '┘' ),
'title'
);
}
public static function wrapStart()
{
if ( Kint::enabled() === Kint::MODE_PLAIN ) {
return '<pre class="-kint">';