43 $params[
'segmentationSize'] = $params[
'segmentationSize'] ?? 917504;
44 parent::__construct( $params );
46 $this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_BE;
47 $this->routingPrefix = $params[
'routingPrefix'] ??
'';
63 $charsLeft = 205 - strlen(
$keyspace ) - count( $components );
65 foreach ( $components as &$component ) {
66 $component = strtr( $component,
' ',
'_' );
69 $component = preg_replace_callback(
70 '/[^\x21-\x22\x24\x26-\x39\x3b-\x7e]+/',
71 static function ( $m ) {
72 return rawurlencode( $m[0] );
78 if ( $charsLeft > 33 && strlen( $component ) > $charsLeft ) {
79 $component =
'#' . md5( $component );
82 $charsLeft -= strlen( $component );
85 if ( $charsLeft < 0 ) {
86 return $keyspace .
':BagOStuff-long-key:##' . md5( implode(
':', $components ) );
89 return $keyspace .
':' . implode(
':', $components );
101 if ( preg_match(
'/[^\x21-\x7e]+/', $key ) ) {
102 throw new Exception(
"Key contains invalid characters: $key" );
115 if ( $this->routingPrefix ===
'' ) {
119 if ( $key[0] ===
'/' ) {
120 throw new RuntimeException(
"Key '$key' already contains a route." );
123 return $this->routingPrefix . $key;
131 if ( $this->routingPrefix ===
'' ) {
135 $prefixLength = strlen( $this->routingPrefix );
136 if ( substr( $key, 0, $prefixLength ) === $this->routingPrefix ) {
137 return substr( $key, $prefixLength );
148 if ( $exptime < 0 ) {
157 $expiresAt = min( $exptime, self::TTL_MONTH );
159 $expiresAt = $exptime;
162 return (
int)$expiresAt;