6use UnexpectedValueException;
30 public function __construct(
string $debugName,
string $pattern ) {
31 $this->debugName = $debugName;
32 $this->pattern = $pattern;
43 if ( $this->prefix !==
'' ) {
44 $match = str_starts_with( $name, $this->prefix );
46 if ( $match && $this->suffix !==
'' ) {
47 $match = str_ends_with( $name, $this->suffix )
48 && strlen( $name ) >= strlen( $this->prefix ) + strlen( $this->suffix );
60 public function generate( $mappedSerial, ?
string $year =
null ) {
62 return $this->prefix .
63 ( $year ? $year .
'-' :
'' ) .
108 if ( $this->isMatch( $name ) ) {
109 return substr( $name,
110 strlen( $this->prefix ),
111 strlen( $name ) - strlen( $this->prefix ) - strlen( $this->suffix ) );
119 private function init() {
120 if ( $this->prefix ===
null ) {
121 $varPos = strpos( $this->pattern,
'$1' );
122 if ( $varPos ===
false ) {
123 throw new UnexpectedValueException( __CLASS__ .
124 "pattern {$this->debugName} must be of the form \"prefix \$1 suffix\"" );
126 $this->prefix = substr( $this->pattern, 0, $varPos );
127 $this->suffix = substr( $this->pattern, $varPos + strlen(
'$1' ) );
132 return $this->pattern;
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.