MediaWiki master
FilteredRadixSerialMapping.php
Go to the documentation of this file.
1<?php
2
4
6
18 private readonly int $radix;
19
21 private readonly array $badIndexes;
22
23 private readonly bool $uppercase;
24
28 public function __construct( array $config ) {
29 $this->radix = $config['radix'] ?? 10;
30 $this->badIndexes = $config['badIndexes'] ?? [];
31 $this->uppercase = $config['uppercase'] ?? false;
32 }
33
34 public function getSerialIdForIndex( int $index ): string {
35 $index = $this->adjustID( $index );
36 return \Wikimedia\base_convert( (string)$index, 10, $this->radix, 1, !$this->uppercase );
37 }
38
46 private function adjustID( int $id ): int {
47 $pos = ArrayUtils::findLowerBound(
48 fn ( $i ) => $this->badIndexes[$i],
49 count( $this->badIndexes ),
50 static fn ( $a, $b ) => $a <=> $b,
51 $id
52 );
53 return $pos === false ? $id : $id + $pos + 1;
54 }
55}
Since "base" is an overused term in class names and mostly means something else, we will call the bas...
A collection of static methods to play with arrays.
Interface for integer to string mappings for temporary user autocreation.