Variable STANDIN_FIX_PHPConst
STANDIN_FIX_PHP: "\nuse Drupal\\drupflare\\Degradation;\nuse Drupal\\drupflare\\DrupflareServiceProvider;\nuse Drupal\\drupflare\\Exec\\Functions;\nuse Drupal\\drupflare\\Http\\Park;\nuse Drupal\\drupflare\\Http\\SymfonyClient;\nuse Drupal\\drupflare\\Shim\\Exif;\n\nif (!function_exists('cfw_standins_installed')) {\n\tfunction cfw_standins_installed(): bool\n\t{\n\t\treturn true;\n\t}\n\n\t/**\n\t * @param string $capability\n\t * The capability that degraded.\n\t * @param string $why\n\t * Why it did.\n\t * @param string $state\n\t * The module table's word for it: verified, untested or blocked.\n\t */\n\tfunction cfw_degraded($capability, $why, $state = 'blocked'): void\n\t{\n\t\tif (class_exists(Degradation::class)) {\n\t\t\tDegradation::record($capability, $why, $state);\n\t\t}\n\t}\n\n\t/**\n\t * Whether _batch_process() should end this request, read after every operation.\n\t *\n\t * Yields on the operation count or when the host reports the isolate near its ceiling,\n\t * whichever comes first; memory_get_usage() reads 0 in this build, so the host is asked.\n\t *\n\t * @param int $ops\n\t * Operations run so far in this request.\n\t */\n\tfunction cfw_batch_yield($ops): bool\n\t{\n\t\tif ($ops >= 20) {\n\t\t\treturn true;\n\t\t}\n\t\t$fn = function_exists('vrzno_env') ? vrzno_env('cfwStats') : null;\n\t\t$stats = $fn !== null ? json_decode($fn(), true) : null;\n\t\treturn is_array($stats) && ($stats['oversized'] ?? false) === true;\n\t}\n\n\t/**\n\t * The transport a Guzzle client built with no handler gets, read by the pack's chooseHandler().\n\t *\n\t * @return object|null\n\t * A handler, or NULL when the drupflare module is not loaded.\n\t */\n\tfunction cfw_guzzle_handler()\n\t{\n\t\tif (!class_exists(DrupflareServiceProvider::class)) {\n\t\t\treturn null;\n\t\t}\n\t\t$class = DrupflareServiceProvider::pickHandlerClass();\n\t\treturn new $class();\n\t}\n\n\t/**\n\t * What a delivered symfony/http-client's HttpClient::create() answers with, once rewritten.\n\t *\n\t * @param array<string, mixed> $defaultOptions\n\t * The options the caller passed to create().\n\t *\n\t * @return object|null\n\t * A client, or NULL when the drupflare module is not loaded.\n\t */\n\tfunction cfw_symfony_http_client($defaultOptions = [])\n\t{\n\t\tif (!class_exists(SymfonyClient::class)) {\n\t\t\treturn null;\n\t\t}\n\t\treturn SymfonyClient::create((array) $defaultOptions);\n\t}\n\n\tspl_autoload_register(static function ($class) {\n\t\t$map = [\n\t\t\t'ziparchive' => 'Drupal\\drupflare\\Shim\\ZipArchive',\n\t\t\t'finfo' => 'Drupal\\drupflare\\Shim\\Finfo',\n\t\t\t'transliterator' => 'Drupal\\drupflare\\Shim\\Transliterator',\n\t\t\t'gdimage' => 'Drupal\\drupflare\\Shim\\GdImage',\n\t\t\t'redis' => 'Drupal\\drupflare\\Shim\\Redis',\n\t\t\t'redisexception' => 'Drupal\\drupflare\\Shim\\RedisException',\n\t\t];\n\t\t$target = $map[strtolower(ltrim($class, '\\\\'))] ?? null;\n\t\tif ($target !== null && class_exists($target)) {\n\t\t\tclass_alias($target, $class);\n\t\t}\n\t});\n\n\tif (!function_exists('exif_read_data')) {\n\t\t/**\n\t\t * @param string|resource $file\n\t\t * A path or an open stream.\n\t\t * @param string|null $required_sections\n\t\t * Comma-separated sections the result must carry.\n\t\t * @param bool $as_arrays\n\t\t * Return sections as arrays.\n\t\t * @param bool $read_thumbnail\n\t\t * Also read the embedded thumbnail.\n\t\t *\n\t\t * @return array<string, mixed>|false\n\t\t */\n\t\tfunction exif_read_data(\n\t\t\t$file,\n\t\t\t$required_sections = null,\n\t\t\t$as_arrays = false,\n\t\t\t$read_thumbnail = false,\n\t\t) {\n\t\t\tif (!class_exists(Exif::class)) {\n\t\t\t\tcfw_degraded(\n\t\t\t\t\t'exif_read_data',\n\t\t\t\t\t'the drupflare module is not loaded, so there is no Exif reader',\n\t\t\t\t);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn Exif::read($file, $required_sections, (bool) $as_arrays, (bool) $read_thumbnail);\n\t\t}\n\t}\n\n\tif (!function_exists('transliterator_transliterate')) {\n\t\t/**\n\t\t * @param string $id\n\t\t * A transliterator rule id.\n\t\t * @param int $direction\n\t\t * 0 for forward.\n\t\t *\n\t\t * @return object|null\n\t\t */\n\t\tfunction transliterator_create($id, $direction = 0)\n\t\t{\n\t\t\treturn class_exists('Transliterator')\n\t\t\t\t? Transliterator::create((string) $id, (int) $direction)\n\t\t\t\t: null;\n\t\t}\n\t\t/**\n\t\t * @param object|string $transliterator\n\t\t * A transliterator or a rule id.\n\t\t * @param string $string\n\t\t * The text to transliterate.\n\t\t * @param int $start\n\t\t * First byte to transliterate.\n\t\t * @param int $end\n\t\t * One past the last byte, or -1 for the rest.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction transliterator_transliterate($transliterator, $string, $start = 0, $end = -1)\n\t\t{\n\t\t\t$t = is_object($transliterator)\n\t\t\t\t? $transliterator\n\t\t\t\t: transliterator_create((string) $transliterator);\n\t\t\treturn $t === null\n\t\t\t\t? false\n\t\t\t\t: $t->transliterate((string) $string, (int) $start, (int) $end);\n\t\t}\n\t}\n\n\tif (!function_exists('finfo_open')) {\n\t\tif (!defined('FILEINFO_NONE')) {\n\t\t\tdefine('FILEINFO_NONE', 0);\n\t\t}\n\t\tif (!defined('FILEINFO_MIME_TYPE')) {\n\t\t\tdefine('FILEINFO_MIME_TYPE', 16);\n\t\t}\n\t\tif (!defined('FILEINFO_MIME_ENCODING')) {\n\t\t\tdefine('FILEINFO_MIME_ENCODING', 1024);\n\t\t}\n\t\tif (!defined('FILEINFO_MIME')) {\n\t\t\tdefine('FILEINFO_MIME', 1040);\n\t\t}\n\t\tif (!defined('FILEINFO_EXTENSION')) {\n\t\t\tdefine('FILEINFO_EXTENSION', 16777216);\n\t\t}\n\t\t/**\n\t\t * @param int $flags\n\t\t * FILEINFO_* flags.\n\t\t * @param string|null $magic_database\n\t\t * Ignored.\n\t\t *\n\t\t * @return object|false\n\t\t */\n\t\tfunction finfo_open($flags = 0, $magic_database = null)\n\t\t{\n\t\t\treturn class_exists('finfo') ? new finfo((int) $flags) : false;\n\t\t}\n\t\t/**\n\t\t * @param object $finfo\n\t\t * The finfo instance.\n\t\t * @param string $filename\n\t\t * A path.\n\t\t * @param int $flags\n\t\t * FILEINFO_* flags.\n\t\t * @param resource|null $context\n\t\t * Ignored.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction finfo_file($finfo, $filename, $flags = 0, $context = null)\n\t\t{\n\t\t\treturn $finfo->file((string) $filename, (int) $flags);\n\t\t}\n\t\t/**\n\t\t * @param object $finfo\n\t\t * The finfo instance.\n\t\t * @param string $string\n\t\t * The bytes to inspect.\n\t\t * @param int $flags\n\t\t * FILEINFO_* flags.\n\t\t * @param resource|null $context\n\t\t * Ignored.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction finfo_buffer($finfo, $string, $flags = 0, $context = null)\n\t\t{\n\t\t\treturn $finfo->buffer((string) $string, (int) $flags);\n\t\t}\n\t\t/**\n\t\t * @param object $finfo\n\t\t * The finfo instance.\n\t\t * @param int $flags\n\t\t * FILEINFO_* flags.\n\t\t */\n\t\tfunction finfo_set_flags($finfo, $flags)\n\t\t{\n\t\t\treturn $finfo->set_flags((int) $flags);\n\t\t}\n\t\t/**\n\t\t * @param object $finfo\n\t\t * The finfo instance.\n\t\t */\n\t\tfunction finfo_close($finfo): bool\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\t/**\n\t\t * @param string|resource $filename\n\t\t * A path or an open stream.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction mime_content_type($filename)\n\t\t{\n\t\t\t$finfo = finfo_open(FILEINFO_MIME_TYPE);\n\t\t\tif ($finfo === false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (is_resource($filename)) {\n\t\t\t\treturn $finfo->buffer((string) stream_get_contents($filename, -1, 0));\n\t\t\t}\n\t\t\treturn $finfo->file((string) $filename);\n\t\t}\n\t}\n\n\t// #region gd, routed to the image engine\n\t// __CFW_GD__\n\t// #endregion\n\n\t// #region the sleep family, which waits through the park\n\t/**\n\t * Waits through the host, or returns at once and records how short it fell.\n\t *\n\t * @param float|int $ms\n\t * How long to wait, in milliseconds.\n\t * @param string $fn\n\t * The PHP function the caller used, for the degradation row.\n\t *\n\t * @return bool\n\t * Whether the whole wait happened.\n\t */\n\tfunction cfw_sleep_ms($ms, $fn): bool\n\t{\n\t\t$ms = max(0, (int) ceil($ms));\n\t\tif ($ms === 0) {\n\t\t\treturn true;\n\t\t}\n\t\t$waited = class_exists(Park::class) ? Park::sleep($ms) : ['slept' => 0, 'remaining' => 0];\n\t\tif ($waited['slept'] >= $ms) {\n\t\t\treturn true;\n\t\t}\n\t\tcfw_degraded(\n\t\t\t$fn,\n\t\t\tsprintf(\n\t\t\t\t'asked to wait %d ms and waited %d ms: the wait runs through the host, and either no parked run was in progress or the invocation had %d ms of its waiting allowance left',\n\t\t\t\t$ms,\n\t\t\t\t$waited['slept'],\n\t\t\t\t$waited['remaining'],\n\t\t\t),\n\t\t\t'untested',\n\t\t);\n\t\treturn false;\n\t}\n\tif (!function_exists('sleep')) {\n\t\t/** @param int $seconds */\n\t\tfunction sleep($seconds): int\n\t\t{\n\t\t\tcfw_sleep_ms($seconds * 1000, 'sleep');\n\t\t\treturn 0;\n\t\t}\n\t}\n\tif (!function_exists('usleep')) {\n\t\t/** @param int $microseconds */\n\t\tfunction usleep($microseconds): void\n\t\t{\n\t\t\tcfw_sleep_ms($microseconds / 1000, 'usleep');\n\t\t}\n\t}\n\tif (!function_exists('time_nanosleep')) {\n\t\t/**\n\t\t * @param int $seconds\n\t\t * Whole seconds.\n\t\t * @param int $nanoseconds\n\t\t * Nanoseconds past the seconds.\n\t\t */\n\t\tfunction time_nanosleep($seconds, $nanoseconds): bool\n\t\t{\n\t\t\tcfw_sleep_ms($seconds * 1000 + $nanoseconds / 1e6, 'time_nanosleep');\n\t\t\treturn true;\n\t\t}\n\t}\n\tif (!function_exists('time_sleep_until')) {\n\t\t/** @param float $timestamp */\n\t\tfunction time_sleep_until($timestamp): bool\n\t\t{\n\t\t\treturn cfw_sleep_ms(($timestamp - microtime(true)) * 1000, 'time_sleep_until');\n\t\t}\n\t}\n\t// #endregion\n\n\t// #region uniqid, which cannot wait for the clock to move\n\tif (!function_exists('uniqid')) {\n\t\tfunction uniqid(string $prefix = '', bool $more_entropy = false): string\n\t\t{\n\t\t\t// function-static, so it stays ahead across runs the way the C prev_tv did\n\t\t\tstatic $last = 0;\n\t\t\t$last = max((int) floor(microtime(true) * 1000000), $last + 1);\n\t\t\t$id = sprintf('%s%08x%05x', $prefix, intdiv($last, 1000000), $last % 1000000);\n\t\t\treturn $more_entropy ? $id . sprintf('%.8F', random_int(0, 999999999) / 1e8) : $id;\n\t\t}\n\t}\n\t// #endregion\n\n\t// #region the process family, which the exec router answers and which otherwise fails like a failed launch\n\tif (!function_exists('exec')) {\n\t\t/**\n\t\t * @param string $command\n\t\t * The command line.\n\t\t * @param array<string>|null $output\n\t\t * Set to the output lines.\n\t\t * @param int|null $result_code\n\t\t * Set to the exit code.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction exec($command, &$output = null, &$result_code = null)\n\t\t{\n\t\t\tif (class_exists(Functions::class)) {\n\t\t\t\treturn Functions::exec($command, $output, $result_code);\n\t\t\t}\n\t\t\tcfw_degraded('exec', 'a Worker has no process table, so no command can run');\n\t\t\tif (!is_array($output)) {\n\t\t\t\t$output = [];\n\t\t\t}\n\t\t\t$result_code = 127;\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (!function_exists('shell_exec')) {\n\t\t/**\n\t\t * @param string $command\n\t\t * The command line.\n\t\t *\n\t\t * @return string|false|null\n\t\t */\n\t\tfunction shell_exec($command)\n\t\t{\n\t\t\tif (class_exists(Functions::class)) {\n\t\t\t\treturn Functions::shellExec($command);\n\t\t\t}\n\t\t\tcfw_degraded('shell_exec', 'a Worker has no process table, so no command can run');\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (!function_exists('system')) {\n\t\t/**\n\t\t * @param string $command\n\t\t * The command line.\n\t\t * @param int|null $result_code\n\t\t * Set to the exit code.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction system($command, &$result_code = null)\n\t\t{\n\t\t\tif (class_exists(Functions::class)) {\n\t\t\t\treturn Functions::system($command, $result_code);\n\t\t\t}\n\t\t\tcfw_degraded('system', 'a Worker has no process table, so no command can run');\n\t\t\t$result_code = 127;\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (!function_exists('passthru')) {\n\t\t/**\n\t\t * @param string $command\n\t\t * The command line.\n\t\t * @param int|null $result_code\n\t\t * Set to the exit code.\n\t\t *\n\t\t * @return false|null\n\t\t */\n\t\tfunction passthru($command, &$result_code = null)\n\t\t{\n\t\t\tif (class_exists(Functions::class)) {\n\t\t\t\treturn Functions::passthru($command, $result_code);\n\t\t\t}\n\t\t\tcfw_degraded('passthru', 'a Worker has no process table, so no command can run');\n\t\t\t$result_code = 127;\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (!function_exists('proc_open')) {\n\t\t/**\n\t\t * @param array<int, string>|string $command\n\t\t * The command line.\n\t\t * @param array<int, mixed> $descriptor_spec\n\t\t * The pipes to open.\n\t\t * @param array<int, resource> $pipes\n\t\t * Set to the opened pipes.\n\t\t * @param string|null $cwd\n\t\t * Working directory.\n\t\t * @param array<string, string>|null $env_vars\n\t\t * Environment.\n\t\t * @param array<string, mixed>|null $options\n\t\t * Platform options.\n\t\t *\n\t\t * @return resource|false\n\t\t */\n\t\tfunction proc_open(\n\t\t\t$command,\n\t\t\t$descriptor_spec,\n\t\t\t&$pipes,\n\t\t\t$cwd = null,\n\t\t\t$env_vars = null,\n\t\t\t$options = null,\n\t\t) {\n\t\t\tif (class_exists(Functions::class)) {\n\t\t\t\treturn Functions::procOpen(\n\t\t\t\t\t$command,\n\t\t\t\t\t$descriptor_spec,\n\t\t\t\t\t$pipes,\n\t\t\t\t\t$cwd,\n\t\t\t\t\t$env_vars,\n\t\t\t\t\t$options,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcfw_degraded('proc_open', 'a Worker cannot fork, so there is no child process');\n\t\t\t$pipes = [];\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (!function_exists('popen')) {\n\t\t/**\n\t\t * @param string $command\n\t\t * The command line.\n\t\t * @param string $mode\n\t\t * r or w.\n\t\t *\n\t\t * @return resource|false\n\t\t */\n\t\tfunction popen($command, $mode)\n\t\t{\n\t\t\tif (class_exists(Functions::class)) {\n\t\t\t\treturn Functions::popen($command, $mode);\n\t\t\t}\n\t\t\tcfw_degraded('popen', 'a Worker cannot fork, so there is no child process');\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (!function_exists('pclose')) {\n\t\t/** @param resource $handle */\n\t\tfunction pclose($handle): int\n\t\t{\n\t\t\treturn class_exists(Functions::class) ? Functions::pclose($handle) : -1;\n\t\t}\n\t}\n\tif (!function_exists('proc_get_status')) {\n\t\t/**\n\t\t * @param resource $process\n\t\t * A handle from proc_open().\n\t\t *\n\t\t * @return array<string, mixed>|false\n\t\t */\n\t\tfunction proc_get_status($process)\n\t\t{\n\t\t\treturn class_exists(Functions::class) ? Functions::procGetStatus($process) : false;\n\t\t}\n\t}\n\tif (!function_exists('proc_close')) {\n\t\t/** @param resource $process */\n\t\tfunction proc_close($process): int\n\t\t{\n\t\t\treturn class_exists(Functions::class) ? Functions::procClose($process) : -1;\n\t\t}\n\t}\n\tif (!function_exists('proc_terminate')) {\n\t\t/**\n\t\t * @param resource $process\n\t\t * A handle from proc_open().\n\t\t * @param int $signal\n\t\t * The signal number.\n\t\t */\n\t\tfunction proc_terminate($process, $signal = 15): bool\n\t\t{\n\t\t\treturn class_exists(Functions::class)\n\t\t\t\t? Functions::procTerminate($process, $signal)\n\t\t\t\t: false;\n\t\t}\n\t}\n\t// #endregion\n}\n"