aboutsummaryrefslogtreecommitdiffstats
path: root/includes/user/TempUser/ReadableNumericSerialMapping.php
blob: dc6d9cc7c7280e1247a3291b79af79c9beffcf49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php

namespace MediaWiki\User\TempUser;

/**
 * Simple serial mapping for ASCII decimal numbers with hyphens for readability
 *
 * @since 1.44
 */
class ReadableNumericSerialMapping implements SerialMapping {
	private int $offset;

	/**
	 * @param array $config
	 */
	public function __construct( $config ) {
		$this->offset = $config['offset'] ?? 0;
	}

	public function getSerialIdForIndex( int $index ): string {
		$mapped = (string)( $index + $this->offset );
		return rtrim( chunk_split( $mapped, 5, '-' ), '-' );
	}
}