Changeset View
Changeset View
Standalone View
Standalone View
externals/pear-figlet/Text/Figlet.php
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | function loadFont($filename, $loadgerman = true) | ||||||||||||
if (!($fp = fopen($filename, 'rb'))) { | if (!($fp = fopen($filename, 'rb'))) { | ||||||||||||
return self::raiseError('Cannot open figlet font file ' . $filename, 2); | return self::raiseError('Cannot open figlet font file ' . $filename, 2); | ||||||||||||
} | } | ||||||||||||
if (!$compressed) { | if (!$compressed) { | ||||||||||||
/* ZIPed font */ | /* ZIPed font */ | ||||||||||||
if (fread($fp, 2) == 'PK') { | if (fread($fp, 2) == 'PK') { | ||||||||||||
if (!function_exists('zip_open')) { | |||||||||||||
return self::raiseError('Cannot load ZIP compressed fonts since' | |||||||||||||
. ' ZIP PHP extension is not available.', | |||||||||||||
5); | |||||||||||||
} | |||||||||||||
fclose($fp); | fclose($fp); | ||||||||||||
if (!($fp = zip_open($filename))) { | $zip = new ZipArchive(); | ||||||||||||
return self::raiseError('Cannot open figlet font file ' . $filename, 2); | |||||||||||||
valerio.bozzolan: IMPORTANT: It seems `ZipArchive::RDONLY` was introduced since PHP 7.4.3
https://www.php. | |||||||||||||
Done Inline Actionshuh, good find, I didn't consider that the argument would not have also existed since ZipArchive was added in 5.2 Some things to consider
speck: huh, good find, I didn't consider that the argument would not have also existed since… | |||||||||||||
Not Done Inline Actions
Uhmm I'm not bold enough to raise PHP 7.4 as minimum version just for this exact line, since probably the workaround here is reasonable readable and minimal. Here an example ↑ valerio.bozzolan: Uhmm I'm not bold enough to raise PHP 7.4 as minimum version just for this exact line, since… | |||||||||||||
Done Inline ActionsYeah that should be a separate discussion. I'll copy that comment into T15047. speck: Yeah that should be a separate discussion. I'll copy that comment into T15047. | |||||||||||||
$zip_flags = 0; | |||||||||||||
Done Inline Actions✅ The strict check is correct since it must return true on success valerio.bozzolan: ✅ The strict check is correct since it must return `true` on success
https://www.php. | |||||||||||||
if(defined('ZipArchive::RDONLY')) { | |||||||||||||
$zip_flags = ZipArchive::RDONLY; // Flag available since PHP 7.4, unnecessary before | |||||||||||||
} | |||||||||||||
$open_result = $zip->open($filename, $zip_flags); | |||||||||||||
if ($open_result !== true) { | |||||||||||||
return self::raiseError('Cannot open figlet font file ' . | |||||||||||||
$filename . ', got error: ' . $open_result, 2); | |||||||||||||
} | } | ||||||||||||
$name = zip_entry_name(zip_read($fp)); | $name = $zip->getNameIndex(0); | ||||||||||||
zip_close($fp); | $zip->close(); | ||||||||||||
if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { | if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { | ||||||||||||
return self::raiseError('Cannot open figlet font file ' . $filename, 2); | return self::raiseError('Cannot open figlet font file ' . $filename, 2); | ||||||||||||
} | } | ||||||||||||
$compressed = true; | $compressed = true; | ||||||||||||
} else { | } else { | ||||||||||||
flock($fp, LOCK_SH); | flock($fp, LOCK_SH); | ||||||||||||
▲ Show 20 Lines • Show All 336 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
https://www.php.net/manual/en/zip.constants.php#ziparchive.constants.rdonly