PrefixSuffix
PrefixSuffix class. Handles prefixes and suffixes in page filenames. Prefixes can be dates or numbers, and suffixes are typically language codes.
Table of Contents
Constants
- DEFAULT_SEPARATORS : array<string|int, string> = ['-', '_']
- PREFIX_BASE : mixed = '(|.*\/)(([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-...
- PREFIX_PART : mixed = 2
- PREFIX_SUFFIX_PART : mixed = 7
- PREFIX_TAIL : mixed = '(.*)'
- SUFFIX_PATTERN : mixed = '(.*)\.' . \Cecil\Config::LANG_CODE_PATTERN
- PREFIX_BASE : mixed = '(|.*\/)(([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-...
Methods
- getPrefix() : string|null
- Returns the prefix if exists.
- getSuffix() : string|null
- Returns the suffix if exists.
- hasPrefix() : bool
- Returns true if the string contains a prefix.
- hasSuffix() : bool
- Returns true if the string contains a suffix.
- sub() : string
- Returns string without the prefix and the suffix (if exists).
- subPrefix() : string
- Returns string without the prefix (if exists).
- get() : string|null
- Returns the prefix or the suffix if exists.
- getPattern() : string
- Returns expreg pattern by $type.
- has() : bool
- Returns true if the string contains a prefix or a suffix.
- buildPrefixPattern() : string
- Builds the prefix regex pattern from configured separators.
- matchPrefix() : bool
- Matches string with prefix pattern.
Constants
DEFAULT_SEPARATORS
public
array<string|int, string>
DEFAULT_SEPARATORS
= ['-', '_']
Default prefix separators.
PREFIX_BASE
private
mixed
PREFIX_BASE
= '(|.*\/)(([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])|[0-9]+)'
PREFIX_PART
private
mixed
PREFIX_PART
= 2
PREFIX_SUFFIX_PART
private
mixed
PREFIX_SUFFIX_PART
= 7
PREFIX_TAIL
private
mixed
PREFIX_TAIL
= '(.*)'
SUFFIX_PATTERN
private
mixed
SUFFIX_PATTERN
= '(.*)\.' . \Cecil\Config::LANG_CODE_PATTERN
Methods
getPrefix()
Returns the prefix if exists.
public
static getPrefix(string $string[, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : string|null
Parameters
- $string : string
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Allowed separator characters
Return values
string|nullgetSuffix()
Returns the suffix if exists.
public
static getSuffix(string $string) : string|null
Parameters
- $string : string
Return values
string|nullhasPrefix()
Returns true if the string contains a prefix.
public
static hasPrefix(string $string[, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : bool
Parameters
- $string : string
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Allowed separator characters
Return values
boolhasSuffix()
Returns true if the string contains a suffix.
public
static hasSuffix(string $string) : bool
Parameters
- $string : string
Return values
boolsub()
Returns string without the prefix and the suffix (if exists).
public
static sub(string $string[, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : string
Parameters
- $string : string
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Allowed separator characters
Return values
stringsubPrefix()
Returns string without the prefix (if exists).
public
static subPrefix(string $string[, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : string
Parameters
- $string : string
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Allowed separator characters
Return values
stringget()
Returns the prefix or the suffix if exists.
protected
static get(string $string, string $type[, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : string|null
Parameters
- $string : string
- $type : string
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Prefix separators (used only for type "prefix")
Return values
string|nullgetPattern()
Returns expreg pattern by $type.
protected
static getPattern(string $type[, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : string
Parameters
- $type : string
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Prefix separators (used only for type "prefix")
Tags
Return values
stringhas()
Returns true if the string contains a prefix or a suffix.
protected
static has(string $string, string $type[, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : bool
Parameters
- $string : string
- $type : string
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Prefix separators (used only for type "prefix")
Return values
boolbuildPrefixPattern()
Builds the prefix regex pattern from configured separators.
private
static buildPrefixPattern(array<string|int, string> $separators) : string
Parameters
- $separators : array<string|int, string>
-
Allowed separator characters between prefix and slug
Return values
stringmatchPrefix()
Matches string with prefix pattern.
private
static matchPrefix(string $string[, array<string|int, mixed>|null &$matches = null ][, array<string|int, string> $separators = self::DEFAULT_SEPARATORS ]) : bool
Parameters
- $string : string
-
String to test
- $matches : array<string|int, mixed>|null = null
-
Output parameter populated with preg_match() matches
- $separators : array<string|int, string> = self::DEFAULT_SEPARATORS
-
Allowed separator characters
Return values
bool —True when the string matches the prefix pattern