* * For the full copyright and license information, please view * the LICENSE file that was distributed with this source code. */ namespace CodeIgniter\Security; use CodeIgniter\CLI\CLI; use CodeIgniter\View\Table; /** * Checks php.ini settings * * @used-by \CodeIgniter\Commands\Utilities\PhpIniCheck * @see \CodeIgniter\Security\CheckPhpIniTest */ class CheckPhpIni { /** * @param bool $isCli Set false if you run via Web * * @return string|void HTML string or void in CLI */ public static function run(bool $isCli = true) { $output = static::checkIni(); $thead = ['Directive', 'Global', 'Current', 'Recommended', 'Remark']; $tbody = []; // CLI if ($isCli) { self::outputForCli($output, $thead, $tbody); return; } // Web return self::outputForWeb($output, $thead, $tbody); } private static function outputForCli(array $output, array $thead, array $tbody): void { foreach ($output as $directive => $values) { $current = $values['current']; $notRecommended = false; if ($values['recommended'] !== '') { if ($values['recommended'] !== $values['current']) { $notRecommended = true; } $current = $notRecommended ? CLI::color($values['current'] === '' ? 'n/a' : $values['current'], 'red') : $values['current']; } $directive = $notRecommended ? CLI::color($directive, 'red') : $directive; $tbody[] = [ $directive, $values['global'], $current, $values['recommended'], $values['remark'], ]; } CLI::table($tbody, $thead); } private static function outputForWeb(array $output, array $thead, array $tbody): string { foreach ($output as $directive => $values) { $current = $values['current']; $notRecommended = false; if ($values['recommended'] !== '') { if ($values['recommended'] !== $values['current']) { $notRecommended = true; } if ($values['current'] === '') { $current = 'n/a'; } $current = $notRecommended ? '' . $current . '' : $current; } $directive = $notRecommended ? '' . $directive . '' : $directive; $tbody[] = [ $directive, $values['global'], $current, $values['recommended'], $values['remark'], ]; } $table = new Table(); $template = [ 'table_open' => '