MediaWiki master
HistoryBlobUtils.php
Go to the documentation of this file.
1<?php
2
3// NO_NAMESPACE Compatibility with serialized objects in permanent storage
4
6
8
14 public static function getAllowedClasses() {
15 return [
16 ConcatenatedGzipHistoryBlob::class,
17 DiffHistoryBlob::class,
18 HistoryBlobCurStub::class,
19 HistoryBlobStub::class
20 ];
21 }
22
30 public static function unserialize( string $str, bool $allowDouble = false ) {
31 $obj = unserialize( $str, [ 'allowed_classes' => self::getAllowedClasses() ] );
32 if ( is_string( $obj ) && $allowDouble ) {
33 // Correct for old double-serialization bug (needed by HistoryBlobStub only)
34 $obj = unserialize( $obj, [ 'allowed_classes' => self::getAllowedClasses() ] );
35 }
36 foreach ( self::getAllowedClasses() as $class ) {
37 if ( $obj instanceof $class ) {
38 return $obj;
39 }
40 }
41 return null;
42 }
43
50 public static function unserializeArray( string $str ): array {
51 $array = unserialize( $str, [ 'allowed_classes' => false ] );
52 if ( !is_array( $array ) ) {
53 throw new BlobAccessException( "Expected array in serialized string" );
54 }
55 return $array;
56 }
57}
static unserializeArray(string $str)
Unserialize array data with no classes.
static unserialize(string $str, bool $allowDouble=false)
Unserialize a HistoryBlob.
static getAllowedClasses()
Get the classes which are allowed to be contained in a text or ES row.
Exception representing a failure to access a data blob.