| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math; |
| 4 |
|
| 5 |
use DataValues\StringValue; |
| 6 |
use InvalidArgumentException; |
| 7 |
use ValueValidators\Error; |
| 8 |
use ValueValidators\Result; |
| 9 |
use ValueValidators\ValueValidator; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class MathValidator implements ValueValidator { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public function validate( $value ) { |
| 27 |
if ( !( $value instanceof StringValue ) ) { |
| 28 |
throw new InvalidArgumentException( '$value must be a StringValue' ); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
$tex = $value->getValue(); |
| 33 |
$checker = Math::getCheckerFactory() |
| 34 |
->newLocalChecker( $tex, 'tex' ); |
| 35 |
|
| 36 |
if ( $checker->isValid() ) { |
| 37 |
return Result::newSuccess(); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
return Result::newError( |
| 42 |
[ |
| 43 |
Error::newError( '', null, 'malformed-value', [ $checker->getError() ] ) |
| 44 |
] |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public function setOptions( array $options ) { |
| 54 |
|
| 55 |
} |
| 56 |
} |