* @copyright Copyright (c) 2022, Robert Strutts. * @license MIT */ namespace CodeHydrater; final class consoleApp { public static $is_cli = false; public static function is_cli() { if (static::$is_cli) { return true; } if (defined('STDIN')) { return true; } if (php_sapi_name() === 'cli') { return true; } if (array_key_exists('SHELL', $_ENV)) { return true; } // $argv = $_SERVER['argv'] ?? []; // && count($argv) > 0 if (!isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT'])) { return true; } if (!array_key_exists('REQUEST_METHOD', $_SERVER)) { return true; } return false; } }