Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\Validators\StringLengthValidator Class Reference

StringLengthValidator checks a string's length. More...

+ Inheritance diagram for Wikibase\Repo\Validators\StringLengthValidator:
+ Collaboration diagram for Wikibase\Repo\Validators\StringLengthValidator:

Public Member Functions

 __construct ( $minLength, $maxLength, $measure='strlen', $errorCodePrefix='')
 
 validate ( $value)
 
 setOptions (array $options)
 

Private Member Functions

 truncateValue ( $value, $truncateAt=32)
 Truncates the value to the max length, if the value is larger than some maximum length. More...
 

Private Attributes

 $minLength
 
 $maxLength
 
 $measure
 
 $errorCodePrefix
 

Detailed Description

StringLengthValidator checks a string's length.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\Validators\StringLengthValidator::__construct (   $minLength,
  $maxLength,
  $measure = 'strlen',
  $errorCodePrefix = '' 
)
Parameters
int$minLength
int$maxLength
callable | string$measureThe function to use to measure the string's length. Use 'strlen' for byte length and 'mb_strlen' for character length. A callable can be used to provide an alternative measure.
string$errorCodePrefix

Member Function Documentation

◆ setOptions()

Wikibase\Repo\Validators\StringLengthValidator::setOptions ( array  $options)
See also
ValueValidator::setOptions()
Parameters
array$options

◆ truncateValue()

Wikibase\Repo\Validators\StringLengthValidator::truncateValue (   $value,
  $truncateAt = 32 
)
private

Truncates the value to the max length, if the value is larger than some maximum length.

To be used only for informative purposes (such as error messages) when the value is already known to be longer than the maximum specified in the constructor.

Parameters
string$value
int$truncateAtThe length after which to truncate. Note that this is unrelated to the max length we validate against.
Returns
string

◆ validate()

Wikibase\Repo\Validators\StringLengthValidator::validate (   $value)
See also
ValueValidator::validate()
Parameters
string$valueThe value to validate
Returns
Result

Member Data Documentation

◆ $errorCodePrefix

Wikibase\Repo\Validators\StringLengthValidator::$errorCodePrefix
private

◆ $maxLength

Wikibase\Repo\Validators\StringLengthValidator::$maxLength
private

◆ $measure

Wikibase\Repo\Validators\StringLengthValidator::$measure
private

◆ $minLength

Wikibase\Repo\Validators\StringLengthValidator::$minLength
private

The documentation for this class was generated from the following file: