mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-24 15:44:33 +00:00
b12b4f740f
Change-Id: Ia46f76a89b26c830aab70ebf5fcc222711c325d1
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
use DataValues\StringValue;
|
|
use ValueValidators\Error;
|
|
use ValueValidators\Result;
|
|
use ValueValidators\ValueValidator;
|
|
|
|
/**
|
|
* @author Duc Linh Tran
|
|
* @author Julian Hilbig
|
|
* @author Moritz Schubotz
|
|
*/
|
|
class MathValidator implements ValueValidator {
|
|
|
|
/**
|
|
* Validates a value with MathInputCheckRestbase
|
|
*
|
|
* @param StringValue $value The value to validate
|
|
*
|
|
* @return \ValueValidators\Result
|
|
* @throws InvalidArgumentException if not called with a StringValue
|
|
*/
|
|
public function validate( $value ) {
|
|
if ( !( $value instanceof StringValue ) ) {
|
|
throw new InvalidArgumentException( '$value must be a StringValue' );
|
|
}
|
|
|
|
// get input String from value
|
|
$tex = $value->getValue();
|
|
|
|
$checker = new MathInputCheckRestbase( $tex );
|
|
if ( $checker->isValid() ) {
|
|
return Result::newSuccess();
|
|
}
|
|
|
|
// TeX string is not valid
|
|
return Result::newError(
|
|
[
|
|
Error::newError( null, null, 'malformed-value', [ $checker->getError() ] )
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @see ValueValidator::setOptions()
|
|
*
|
|
* @param array $options
|
|
*/
|
|
public function setOptions( array $options ) {
|
|
// Do nothing. This method shouldn't even be in the interface.
|
|
}
|
|
}
|