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