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