From bd0b582b6cac7c7c96e78ddc05d732b61dc28bbe Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 3 Dec 2024 08:23:30 +0000 Subject: [PATCH] Manually implement stream_context_set_options in a php8.1-compatible way --- generated/stream.php | 27 ---------------------- generator/config/specialCasesFunctions.php | 6 ++++- lib/special_cases.php | 27 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/generated/stream.php b/generated/stream.php index e5e0ce9c..11a4c0be 100644 --- a/generated/stream.php +++ b/generated/stream.php @@ -4,33 +4,6 @@ use Safe\Exceptions\StreamException; -/** - * Sets options on the specified context. - * - * @param resource $context The stream or context resource to apply the options to. - * @param array $options The options to set for context. - * - * options must be an associative - * array of associative arrays in the format - * $array['wrapper']['option'] = $value. - * - * Refer to context options and parameters - * for a listing of stream options. - * @return true Returns TRUE on success. - * @throws StreamException - * - */ -function stream_context_set_options($context, array $options): true -{ - error_clear_last(); - $safeResult = \stream_context_set_options($context, $options); - if ($safeResult === false) { - throw StreamException::createFromPhpError(); - } - return $safeResult; -} - - /** * Sets parameters on the specified context. * diff --git a/generator/config/specialCasesFunctions.php b/generator/config/specialCasesFunctions.php index 31febcc4..6fe79b0c 100644 --- a/generator/config/specialCasesFunctions.php +++ b/generator/config/specialCasesFunctions.php @@ -15,5 +15,9 @@ 'simplexml_import_dom', 'simplexml_load_file', 'simplexml_load_string', - 'fgetcsv', // This function need to return false when iterating on an end of file. + // returns literal "true", which php8.1 doesn't support, so we implement + // this one manually and return "bool" + 'stream_context_set_options', + // This function need to return false when iterating on an end of file. + 'fgetcsv', ]; diff --git a/lib/special_cases.php b/lib/special_cases.php index 53244e45..d582692f 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -17,6 +17,7 @@ use Safe\Exceptions\OpensslException; use Safe\Exceptions\PcreException; use Safe\Exceptions\SimplexmlException; +use Safe\Exceptions\StreamException; use Safe\Exceptions\FilesystemException; use const PREG_NO_ERROR; @@ -442,3 +443,29 @@ function fgetcsv($stream, ?int $length = null, string $separator = ",", string $ } return $safeResult; } + +/** + * Sets options on the specified context. + * + * @param resource $context The stream or context resource to apply the options to. + * @param array $options The options to set for context. + * + * options must be an associative + * array of associative arrays in the format + * $array['wrapper']['option'] = $value. + * + * Refer to context options and parameters + * for a listing of stream options. + * @return true Returns TRUE on success. + * @throws StreamException + * + */ +function stream_context_set_options($context, array $options): bool +{ + error_clear_last(); + $safeResult = \stream_context_set_options($context, $options); + if ($safeResult === false) { + throw StreamException::createFromPhpError(); + } + return $safeResult; +}