From c782e9adaa76ff8a701eb7219a7a8815ae4598d9 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Mon, 17 Feb 2020 14:10:36 +0100 Subject: [PATCH] Updates To Kint Loading --- app/Config/App.php | 11 +++++++++ system/Autoloader/Autoloader.php | 6 ----- system/CodeIgniter.php | 38 ++++++++++++++++++++++++++++++-- system/Config/AutoloadConfig.php | 1 - 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/app/Config/App.php b/app/Config/App.php index 2da765fa6b8e..2d5daefb7ba1 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -266,4 +266,15 @@ class App extends BaseConfig */ public $CSPEnabled = false; + /* + |-------------------------------------------------------------------------- + | Kint + |-------------------------------------------------------------------------- + | + | Kint Related configuration + | + */ + public $kintRendererTheme = 'aante-light.css'; + public $kintRendererFolder = false; + } diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 89e786d5607c..46631074455d 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -423,12 +423,6 @@ protected function discoverComposerNamespaces() unset($paths['CodeIgniter\\']); } - // Also get rid of Kint to ensure we use our own copy - if (isset($paths['Kint\\'])) - { - unset($paths['Kint\\']); - } - // Composer stores namespaces with trailing slash. We don't. $newPaths = []; foreach ($paths as $key => $value) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 905eb7a5b243..603b0fa508eb 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -190,11 +190,45 @@ public function initialize() $this->detectEnvironment(); $this->bootstrapEnvironment(); - if (CI_DEBUG) + $this->initializeKint(); + + if (! CI_DEBUG) + { + \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'; - \Kint\Renderer\RichRenderer::$theme = 'aante-light.css'; } + + //Set the kint theme + \Kint\Renderer\RichRenderer::$theme = $this->config->kintRendererTheme; + + //Render kint in place instead of toolbar + \Kint\Renderer\RichRenderer::$folder = $this->config->kintRendererFolder; } //-------------------------------------------------------------------- diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index 6cc9f166bc33..ea4e0fd54158 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -92,7 +92,6 @@ public function __construct() */ $this->psr4 = [ 'CodeIgniter' => realpath(SYSTEMPATH), - 'Kint' => SYSTEMPATH . 'ThirdParty/Kint', ]; if (isset($_SERVER['CI_ENVIRONMENT']) && $_SERVER['CI_ENVIRONMENT'] === 'testing')