|
| 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 | +namespace CodeIgniter\Commands\Utilities; |
| 13 | + |
| 14 | +use CodeIgniter\CLI\BaseCommand; |
| 15 | +use CodeIgniter\CLI\CLI; |
| 16 | +use CodeIgniter\Config\BaseConfig; |
| 17 | +use Kint\Kint; |
| 18 | + |
| 19 | +/** |
| 20 | + * Check the Config values. |
| 21 | + * |
| 22 | + * @see \CodeIgniter\Commands\Utilities\ConfigCheckTest |
| 23 | + */ |
| 24 | +final class ConfigCheck extends BaseCommand |
| 25 | +{ |
| 26 | + /** |
| 27 | + * The group the command is lumped under |
| 28 | + * when listing commands. |
| 29 | + * |
| 30 | + * @var string |
| 31 | + */ |
| 32 | + protected $group = 'CodeIgniter'; |
| 33 | + |
| 34 | + /** |
| 35 | + * The Command's name |
| 36 | + * |
| 37 | + * @var string |
| 38 | + */ |
| 39 | + protected $name = 'config:check'; |
| 40 | + |
| 41 | + /** |
| 42 | + * The Command's short description |
| 43 | + * |
| 44 | + * @var string |
| 45 | + */ |
| 46 | + protected $description = 'Check your Config values.'; |
| 47 | + |
| 48 | + /** |
| 49 | + * The Command's usage |
| 50 | + * |
| 51 | + * @var string |
| 52 | + */ |
| 53 | + protected $usage = 'config:check <classname>'; |
| 54 | + |
| 55 | + /** |
| 56 | + * The Command's arguments |
| 57 | + * |
| 58 | + * @var array<string, string> |
| 59 | + */ |
| 60 | + protected $arguments = [ |
| 61 | + 'classname' => 'The config classname to check. Short classname or FQCN.', |
| 62 | + ]; |
| 63 | + |
| 64 | + /** |
| 65 | + * The Command's options |
| 66 | + * |
| 67 | + * @var array |
| 68 | + */ |
| 69 | + protected $options = []; |
| 70 | + |
| 71 | + /** |
| 72 | + * {@inheritDoc} |
| 73 | + */ |
| 74 | + public function run(array $params) |
| 75 | + { |
| 76 | + if (! isset($params[0])) { |
| 77 | + CLI::error('You must specify a Config classname.'); |
| 78 | + CLI::write(' Usage: ' . $this->usage); |
| 79 | + CLI::write('Example: config:check App'); |
| 80 | + CLI::write(' config:check \'CodeIgniter\Shield\Config\Auth\''); |
| 81 | + |
| 82 | + return EXIT_ERROR; |
| 83 | + } |
| 84 | + |
| 85 | + /** @var class-string<BaseConfig> $class */ |
| 86 | + $class = $params[0]; |
| 87 | + |
| 88 | + $config = config($class); |
| 89 | + |
| 90 | + if ($config === null) { |
| 91 | + CLI::error('No such Config class: ' . $class); |
| 92 | + |
| 93 | + return EXIT_ERROR; |
| 94 | + } |
| 95 | + |
| 96 | + if (defined('KINT_DIR') && Kint::$enabled_mode !== false) { |
| 97 | + ob_start(); |
| 98 | + d($config); |
| 99 | + $output = ob_get_clean(); |
| 100 | + |
| 101 | + $output = trim($output); |
| 102 | + $output = preg_replace('/\x1b\[36m.*┘\x1b\[0m/su', '', $output); |
| 103 | + $output = preg_replace('/\x1b\[36m.*Called from .*\x1b\[0m/su', '', $output); |
| 104 | + $output = trim($output); |
| 105 | + |
| 106 | + CLI::write($output); |
| 107 | + } else { |
| 108 | + ob_start(); |
| 109 | + var_dump($config); |
| 110 | + $output = ob_get_clean(); |
| 111 | + |
| 112 | + $output = preg_replace( |
| 113 | + '!.*system/Commands/Utilities/Config.php.*\n!u', |
| 114 | + '', |
| 115 | + $output |
| 116 | + ); |
| 117 | + |
| 118 | + CLI::write( |
| 119 | + CLI::color($output, 'cyan') |
| 120 | + ); |
| 121 | + } |
| 122 | + |
| 123 | + return EXIT_SUCCESS; |
| 124 | + } |
| 125 | +} |
0 commit comments