27 public function __construct(
string $debugName,
string $pattern ) {
28 $this->debugName = $debugName;
29 $this->pattern = $pattern;
40 if ( $this->prefix !==
'' ) {
41 $match = str_starts_with( $name, $this->prefix );
43 if ( $match && $this->suffix !==
'' ) {
44 $match = str_ends_with( $name, $this->suffix )
45 && strlen( $name ) >= strlen( $this->prefix ) + strlen( $this->suffix );
58 return $this->prefix . $mappedSerial . $this->suffix;
83 if ( $this->
isMatch( $name ) ) {
85 strlen( $this->prefix ),
86 strlen( $name ) - strlen( $this->prefix ) - strlen( $this->suffix ) );
94 private function init() {
95 if ( $this->prefix ===
null ) {
96 $varPos = strpos( $this->pattern,
'$1' );
97 if ( $varPos ===
false ) {
98 throw new \MWException( __CLASS__ .
99 "pattern {$this->debugName} must be of the form \"prefix \$1 suffix\"" );
101 $this->prefix = substr( $this->pattern, 0, $varPos );
102 $this->suffix = substr( $this->pattern, $varPos + strlen(
'$1' ) );