Skip to content

Commit

Permalink
Merge pull request #2564 from codeigniter4/kint3
Browse files Browse the repository at this point in the history
Updated loader and composer script to use Kint 3.3 for #2373
  • Loading branch information
lonnieezell authored Feb 21, 2020
2 parents 481d573 + 018b1dc commit 578c21f
Show file tree
Hide file tree
Showing 95 changed files with 10,555 additions and 167 deletions.
1 change: 0 additions & 1 deletion app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,4 @@ class App extends BaseConfig
| - http://www.w3.org/TR/CSP/
*/
public $CSPEnabled = false;

}
62 changes: 62 additions & 0 deletions app/Config/Kint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php namespace Config;

use Kint\Renderer\Renderer;
use CodeIgniter\Config\BaseConfig;

class Kint extends BaseConfig
{
/*
|--------------------------------------------------------------------------
| Kint
|--------------------------------------------------------------------------
|
| We use Kint's RichRenderer and CLIRenderer. This area contains options
| that you can set to customize how Kint works for you.
|
| For details on these settings, see Kint's docs:
| https://kint-php.github.io/kint/
|
*/

/*
|--------------------------------------------------------------------------
| Global Settings
|--------------------------------------------------------------------------
*/

public $plugins = null;

public $maxDepth = 6;

public $displayCalledFrom = true;

public $expanded = false;

/*
|--------------------------------------------------------------------------
| RichRenderer Settings
|--------------------------------------------------------------------------
*/
public $richTheme = 'aante-light.css';

public $richFolder = false;

public $richSort = Renderer::SORT_FULL;

public $richObjectPlugins = null;

public $richTabPlugins = null;

/*
|--------------------------------------------------------------------------
| CLI Settings
|--------------------------------------------------------------------------
*/
public $cliColors = true;

public $cliForceUTF8 = false;

public $cliDetectWidth = true;

public $cliMinWidth = 40;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ext-curl": "*",
"ext-intl": "*",
"ext-json": "*",
"kint-php/kint": "^2.1",
"kint-php/kint": "^3.3",
"psr/log": "^1.1",
"laminas/laminas-escaper": "^2.6"
},
Expand Down
64 changes: 62 additions & 2 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,74 @@ public function initialize()
$this->detectEnvironment();
$this->bootstrapEnvironment();

if (CI_DEBUG)
$this->initializeKint();

if (! CI_DEBUG)
{
require_once SYSTEMPATH . 'ThirdParty/Kint/kint.php';
\Kint::$enabled_mode = false;
}
}

//--------------------------------------------------------------------

/**
* Initializes Kint
*/
protected function initializeKint()
{
// If we have KINT_DIR it means it's already loaded via composer
if (! defined('KINT_DIR'))
{
spl_autoload_register(function ($class) {
$class = explode('\\', $class);

if ('Kint' !== array_shift($class))
{
return;
}

$file = SYSTEMPATH . 'ThirdParty/Kint/' . implode('/', $class) . '.php';

file_exists($file) && require_once $file;
});

require_once SYSTEMPATH . 'ThirdParty/Kint/init.php';
}

/**
* Config\Kint
*/
$config = config('Config\Kint');

\Kint::$max_depth = $config->maxDepth;
\Kint::$display_called_from = $config->displayCalledFrom;
\Kint::$expanded = $config->expanded;

if (! empty($config->plugins) && is_array($config->plugins))
{
\Kint::$plugins = $config->plugins;
}

\Kint\Renderer\RichRenderer::$theme = $config->richTheme;
\Kint\Renderer\RichRenderer::$folder = $config->richFolder;
\Kint\Renderer\RichRenderer::$sort = $config->richSort;
if (! empty($config->richObjectPlugins) && is_array($config->richObjectPlugins))
{
\Kint\Renderer\RichRenderer::$object_plugins = $config->richObjectPlugins;
}
if (! empty($config->richTabPlugins) && is_array($config->richTabPlugins))
{
\Kint\Renderer\RichRenderer::$tab_plugins = $config->richTabPlugins;
}

\Kint\Renderer\CliRenderer::$cli_colors = $config->cliColors;
\Kint\Renderer\CliRenderer::$force_utf8 = $config->cliForceUTF8;
\Kint\Renderer\CliRenderer::$detect_width = $config->cliDetectWidth;
\Kint\Renderer\CliRenderer::$min_terminal_width = $config->cliMinWidth;
}

//--------------------------------------------------------------------

/**
* Launch the application!
*
Expand Down
35 changes: 29 additions & 6 deletions system/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ protected static function removeDir($dir)
}
}

protected static function copyDir($source, $dest)
{
$dir = opendir($source);
@mkdir($dest);

while (false !== ( $file = readdir($dir)))
{
if (( $file !== '.' ) && ( $file !== '..' ))
{
if (is_dir($source . '/' . $file))
{
static::copyDir($source . '/' . $file, $dest . '/' . $file);
}
else
{
copy($source . '/' . $file, $dest . '/' . $file);
}
}
}

closedir($dir);
}

/**
* Moves the Laminas Escaper files into our base repo so that it's
* available for packaged releases where the users don't user Composer.
Expand Down Expand Up @@ -194,9 +217,9 @@ public static function moveEscaper()
*/
public static function moveKint()
{
$filename = 'vendor/kint-php/kint/build/kint-aante-light.php';
$dir = 'vendor/kint-php/kint/src';

if (is_file($filename))
if (is_dir($dir))
{
$base = basename(__DIR__) . '/' . static::$basePath . 'Kint';

Expand All @@ -212,10 +235,10 @@ public static function moveKint()
mkdir($base, 0755);
}

if (! static::moveFile($filename, $base . '/kint.php'))
{
die('Error moving: ' . $filename);
}
static::copyDir($dir, $base);
static::copyDir($dir . '/../resources', $base . '/resources');
copy($dir . '/../init.php', $base . '/init.php');
copy($dir . '/../init_helpers.php', $base . '/init_helpers.php');
}
}
}
Loading

0 comments on commit 578c21f

Please sign in to comment.