maj compat nur/sery

This commit is contained in:
Jephté Clain 2025-01-30 08:25:31 +04:00
parent 756502361f
commit b50d881e7f
1 changed files with 11 additions and 6 deletions

View File

@ -310,25 +310,30 @@ class Stream extends AbstractIterator implements IReader, IWriter {
}
/** @var bool faut-il faire un mapping pour la compatibilité avec nur/sery */
const UNSERIALIZE_NURSERY_COMPAT = true;
const NURSERY_COMPAT_ENABLED = true;
/**
* @var string[] mappings pour la compatibilité avec des fichiers générés par
* nur/sery
*/
const UNSERIALIZE_NURSERY_MAPPING = [
const NURSERY_COMPAT_MAPPING = [
'O:22:"nur\sery\php\time\Date":' => 'O:19:"nulib\php\time\Date":',
'O:26:"nur\sery\php\time\DateTime":' => 'O:23:"nulib\php\time\DateTime":',
'O:23:"nur\sery\php\time\Delay":' => 'O:20:"nulib\php\time\Delay":',
];
function unserialize(?array $options=null, bool $close=true, bool $alreadyLocked=false) {
$contents = $this->getContents($close, $alreadyLocked);
if (static::UNSERIALIZE_NURSERY_COMPAT) {
foreach (self::UNSERIALIZE_NURSERY_MAPPING as $from => $to) {
static function nursery_compat_verifix(string $contents): string {
if (static::NURSERY_COMPAT_ENABLED) {
foreach (self::NURSERY_COMPAT_MAPPING as $from => $to) {
$contents = str_replace($from, $to, $contents);
}
}
return $contents;
}
function unserialize(?array $options=null, bool $close=true, bool $alreadyLocked=false) {
$contents = $this->getContents($close, $alreadyLocked);
$contents = self::nursery_compat_verifix($contents);
$args = [$contents];
if ($options !== null) $args[] = $options;
return unserialize(...$args);