Skip to content

Commit a6e4d38

Browse files
authored
Merge pull request #6449 from kenjis/move-kint-to-require-dev
chore: move Kint to `require-dev`
2 parents 8e6bff9 + 2dd3562 commit a6e4d38

File tree

6 files changed

+92
-37
lines changed

6 files changed

+92
-37
lines changed

admin/framework/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
"ext-intl": "*",
1111
"ext-json": "*",
1212
"ext-mbstring": "*",
13-
"kint-php/kint": "^4.2",
1413
"laminas/laminas-escaper": "^2.9",
1514
"psr/log": "^1.1"
1615
},
1716
"require-dev": {
17+
"kint-php/kint": "^4.2",
1818
"codeigniter/coding-standard": "^1.1",
1919
"fakerphp/faker": "^1.9",
2020
"friendsofphp/php-cs-fixer": "3.6.*",

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
"ext-intl": "*",
1111
"ext-json": "*",
1212
"ext-mbstring": "*",
13-
"kint-php/kint": "^4.2",
1413
"laminas/laminas-escaper": "^2.9",
1514
"psr/log": "^1.1"
1615
},
1716
"require-dev": {
17+
"kint-php/kint": "^4.2",
1818
"codeigniter/coding-standard": "^1.1",
1919
"fakerphp/faker": "^1.9",
2020
"friendsofphp/php-cs-fixer": "3.6.*",

system/CodeIgniter.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ public function initialize()
183183
date_default_timezone_set($this->config->appTimezone ?? 'UTC');
184184

185185
$this->initializeKint();
186-
187-
if (! CI_DEBUG) {
188-
Kint::$enabled_mode = false; // @codeCoverageIgnore
189-
}
190186
}
191187

192188
/**
@@ -223,6 +219,20 @@ protected function resolvePlatformExtensions()
223219
* Initializes Kint
224220
*/
225221
protected function initializeKint()
222+
{
223+
if (CI_DEBUG) {
224+
$this->autoloadKint();
225+
$this->configureKint();
226+
} elseif (class_exists(Kint::class)) {
227+
// In case that Kint is already loaded via Composer.
228+
Kint::$enabled_mode = false;
229+
// @codeCoverageIgnore
230+
}
231+
232+
helper('kint');
233+
}
234+
235+
private function autoloadKint(): void
226236
{
227237
// If we have KINT_DIR it means it's already loaded via composer
228238
if (! defined('KINT_DIR')) {
@@ -242,7 +252,10 @@ protected function initializeKint()
242252

243253
require_once SYSTEMPATH . 'ThirdParty/Kint/init.php';
244254
}
255+
}
245256

257+
private function configureKint(): void
258+
{
246259
/** @var \Config\Kint $config */
247260
$config = config(KintConfig::class);
248261

system/Common.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -347,25 +347,6 @@ function db_connect($db = null, bool $getShared = true)
347347
}
348348
}
349349

350-
if (! function_exists('dd')) {
351-
/**
352-
* Prints a Kint debug report and exits.
353-
*
354-
* @param array ...$vars
355-
*
356-
* @codeCoverageIgnore Can't be tested ... exits
357-
*/
358-
function dd(...$vars)
359-
{
360-
// @codeCoverageIgnoreStart
361-
Kint::$aliases[] = 'dd';
362-
Kint::dump(...$vars);
363-
364-
exit;
365-
// @codeCoverageIgnoreEnd
366-
}
367-
}
368-
369350
if (! function_exists('env')) {
370351
/**
371352
* Allows user to retrieve values from the environment
@@ -1109,17 +1090,6 @@ function timer(?string $name = null, ?callable $callable = null)
11091090
}
11101091
}
11111092

1112-
if (! function_exists('trace')) {
1113-
/**
1114-
* Provides a backtrace to the current execution point, from Kint.
1115-
*/
1116-
function trace()
1117-
{
1118-
Kint::$aliases[] = 'trace';
1119-
Kint::trace();
1120-
}
1121-
}
1122-
11231093
if (! function_exists('view')) {
11241094
/**
11251095
* Grabs the current RendererInterface-compatible class

system/ComposerScripts.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ public static function postUpdate()
6969
{
7070
self::recursiveDelete(self::$path);
7171

72-
foreach (self::$dependencies as $dependency) {
72+
foreach (self::$dependencies as $key => $dependency) {
73+
// Kint may be removed.
74+
if (! is_dir($dependency['from']) && strpos($key, 'kint') === 0) {
75+
continue;
76+
}
77+
7378
self::recursiveMirror($dependency['from'], $dependency['to']);
79+
7480
if (isset($dependency['license'])) {
7581
$license = basename($dependency['license']);
7682
copy($dependency['license'], $dependency['to'] . '/' . $license);

system/Helpers/kint_helper.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
// This helper is autoloaded by CodeIgniter.
13+
14+
if (! function_exists('dd')) {
15+
if (class_exists(Kint::class)) {
16+
/**
17+
* Prints a Kint debug report and exits.
18+
*
19+
* @param array ...$vars
20+
*
21+
* @codeCoverageIgnore Can't be tested ... exits
22+
*/
23+
function dd(...$vars)
24+
{
25+
// @codeCoverageIgnoreStart
26+
Kint::$aliases[] = 'dd';
27+
Kint::dump(...$vars);
28+
29+
exit;
30+
// @codeCoverageIgnoreEnd
31+
}
32+
} else {
33+
// In case that Kint is not loaded.
34+
function dd(...$vars)
35+
{
36+
return 0;
37+
}
38+
}
39+
}
40+
41+
if (! function_exists('d') && ! class_exists(Kint::class)) {
42+
// In case that Kint is not loaded.
43+
function d(...$vars)
44+
{
45+
return 0;
46+
}
47+
}
48+
49+
if (! function_exists('trace')) {
50+
if (class_exists(Kint::class)) {
51+
/**
52+
* Provides a backtrace to the current execution point, from Kint.
53+
*/
54+
function trace()
55+
{
56+
Kint::$aliases[] = 'trace';
57+
Kint::trace();
58+
}
59+
} else {
60+
// In case that Kint is not loaded.
61+
function trace()
62+
{
63+
return 0;
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)