25 public function __construct(
string $debugName,
string $pattern ) {
26 $this->debugName = $debugName;
27 $this->pattern = $pattern;
38 if ( $this->prefix !==
'' ) {
39 $match = str_starts_with( $name, $this->prefix );
41 if ( $match && $this->suffix !==
'' ) {
42 $match = str_ends_with( $name, $this->suffix )
43 && strlen( $name ) >= strlen( $this->prefix ) + strlen( $this->suffix );
56 return $this->prefix . $mappedSerial . $this->suffix;
62 private function init() {
63 if ( $this->prefix ===
null ) {
64 $varPos = strpos( $this->pattern,
'$1' );
65 if ( $varPos ===
false ) {
66 throw new \MWException( __CLASS__ .
67 "pattern {$this->debugName} must be of the form \"prefix \$1 suffix\"" );
69 $this->prefix = substr( $this->pattern, 0, $varPos );
70 $this->suffix = substr( $this->pattern, $varPos + strlen(
'$1' ) );