File: SerializedValueContainer.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (44 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

namespace Wikimedia\ObjectCache\Serialized;

use stdClass;

/**
 * Helper class for segmenting large cache values without relying
 * on serializing classes.
 *
 * @since 1.34
 * @ingroup Cache
 */
class SerializedValueContainer {
	private const SCHEMA = '__svc_schema__';
	// 64 bit UID
	private const SCHEMA_SEGMENTED = 'CAYCDAgCDw4';
	public const SEGMENTED_HASHES = '__hashes__';

	/**
	 * @param string[] $segmentHashList Ordered list of hashes for each segment
	 * @return stdClass
	 */
	public static function newSegmented( array $segmentHashList ) {
		return (object)[
			self::SCHEMA => self::SCHEMA_SEGMENTED,
			self::SEGMENTED_HASHES => $segmentHashList
		];
	}

	/**
	 * @param mixed $value
	 * @return bool
	 */
	public static function isSegmented( $value ): bool {
		return (
			$value instanceof stdClass &&
			( $value->{self::SCHEMA} ?? null ) === self::SCHEMA_SEGMENTED
		);
	}
}

/** @deprecated class alias since 1.43 */
class_alias( SerializedValueContainer::class, 'SerializedValueContainer' );