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