Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SerializedValueContainer | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
newSegmented | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
isSegmented | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Wikimedia\ObjectCache\Serialized; |
4 | |
5 | use stdClass; |
6 | |
7 | /** |
8 | * Helper class for segmenting large cache values without relying |
9 | * on serializing classes. |
10 | * |
11 | * @since 1.34 |
12 | * @ingroup Cache |
13 | */ |
14 | class SerializedValueContainer { |
15 | private const SCHEMA = '__svc_schema__'; |
16 | // 64 bit UID |
17 | private const SCHEMA_SEGMENTED = 'CAYCDAgCDw4'; |
18 | public const SEGMENTED_HASHES = '__hashes__'; |
19 | |
20 | /** |
21 | * @param string[] $segmentHashList Ordered list of hashes for each segment |
22 | * @return stdClass |
23 | */ |
24 | public static function newSegmented( array $segmentHashList ) { |
25 | return (object)[ |
26 | self::SCHEMA => self::SCHEMA_SEGMENTED, |
27 | self::SEGMENTED_HASHES => $segmentHashList |
28 | ]; |
29 | } |
30 | |
31 | /** |
32 | * @param mixed $value |
33 | * @return bool |
34 | */ |
35 | public static function isSegmented( $value ): bool { |
36 | return ( |
37 | $value instanceof stdClass && |
38 | ( $value->{self::SCHEMA} ?? null ) === self::SCHEMA_SEGMENTED |
39 | ); |
40 | } |
41 | } |
42 | |
43 | /** @deprecated class alias since 1.43 */ |
44 | class_alias( SerializedValueContainer::class, 'SerializedValueContainer' ); |