Skip to content

Commit d5c63c8

Browse files
committedApr 25, 2023
Update Figlet implementation to be PHP8 compatible
Summary: As of PHP ~v8 the `zip_open` and associated functions have been deprecated and removed. The replacement is the `ZipArchive` API. This updates the figlet implementation to use this API which has been present in PHP since 5.2. Additionally in PHP 8 the use of squiggly brackets for indexing into arrays is also deprecated. This updates to remove two uses of squiggly brackets and replace with square brackets. These two deprecations would result in being unable to load differential revisions in which someone had commented using figlet remarkup. Refs T13588 Test Plan: Applied these changes to an install and loaded a revision that had comments where someone utilized figlet remarkup. The revision loaded properly and the figlet comment rendered properly. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21860
1 parent a83cb99 commit d5c63c8

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed
 

‎externals/pear-figlet/Text/Figlet.php

+10-15
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,15 @@ function loadFont($filename, $loadgerman = true)
140140
if (!$compressed) {
141141
/* ZIPed font */
142142
if (fread($fp, 2) == 'PK') {
143-
if (!function_exists('zip_open')) {
144-
return self::raiseError('Cannot load ZIP compressed fonts since'
145-
. ' ZIP PHP extension is not available.',
146-
5);
147-
}
148-
149143
fclose($fp);
150-
151-
if (!($fp = zip_open($filename))) {
152-
return self::raiseError('Cannot open figlet font file ' . $filename, 2);
144+
$zip = new ZipArchive();
145+
$open_result = $zip->open($filename, ZipArchive::RDONLY);
146+
if ($open_result !== true) {
147+
return self::raiseError('Cannot open figlet font file ' .
148+
$filename . ', got error: ' . $open_result, 2);
153149
}
154-
155-
$name = zip_entry_name(zip_read($fp));
156-
zip_close($fp);
150+
$name = zip->getNameIndex(0);
151+
$zip->close();
157152

158153
if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) {
159154
return self::raiseError('Cannot open figlet font file ' . $filename, 2);
@@ -231,7 +226,7 @@ function loadFont($filename, $loadgerman = true)
231226
$i = hexdec(substr($i, 2));
232227
} else {
233228
// If octal
234-
if ($i{0} === '0' && $i !== '0' || substr($i, 0, 2) == '-0') {
229+
if ($i[0] === '0' && $i !== '0' || substr($i, 0, 2) == '-0') {
235230
$i = octdec($i);
236231
}
237232
}
@@ -274,7 +269,7 @@ function lineEcho($str, $inhtml = false)
274269
$lt = hexdec(substr($str, $i+2, 4));
275270
$i += 5;
276271
} else {
277-
$lt = ord($str{$i});
272+
$lt = ord($str[$i]);
278273
}
279274

280275
$hb = preg_quote($this->hardblank, '/');
@@ -497,4 +492,4 @@ function _skip(&$fp)
497492
private static function raiseError($message, $code = 1) {
498493
throw new Exception($message);
499494
}
500-
}
495+
}

0 commit comments

Comments
 (0)
Failed to load comments.