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