Make code using the Math.CheckerFactory service discoverable

Otherwise IDEs and other tools don't know what's going on.
...->getService() returns mixed.

Change-Id: If0429485941c19eb0e88896cb1ada66a5320bafe
This commit is contained in:
Moritz Schubotz (physikerwelt) 2022-11-22 15:11:26 +01:00 committed by Physikerwelt
parent 14647fa3b1
commit b3e57cbfc2
4 changed files with 9 additions and 8 deletions

View file

@ -2,6 +2,7 @@
namespace MediaWiki\Extension\Math;
use MediaWiki\Extension\Math\InputCheck\InputCheckFactory;
use MediaWiki\MediaWikiServices;
use Psr\Container\ContainerInterface;
@ -24,4 +25,8 @@ final class Math {
->get( 'Math.Config' );
}
public static function getCheckerFactory( ContainerInterface $services = null ): InputCheckFactory {
return ( $services ?: MediaWikiServices::getInstance() )
->get( 'Math.CheckerFactory' );
}
}

View file

@ -689,8 +689,7 @@ abstract class MathRenderer {
* @return bool
*/
protected function doCheck() {
$checker = MediaWikiServices::getInstance()
->getService( 'Math.CheckerFactory' )
$checker = Math::getCheckerFactory()
->newDefaultChecker( $this->tex, $this->getInputType(), $this->rbi );
try {

View file

@ -4,7 +4,6 @@ namespace MediaWiki\Extension\Math;
use DataValues\StringValue;
use InvalidArgumentException;
use MediaWiki\MediaWikiServices;
use ValueValidators\Error;
use ValueValidators\Result;
use ValueValidators\ValueValidator;
@ -31,8 +30,7 @@ class MathValidator implements ValueValidator {
// get input String from value
$tex = $value->getValue();
$checker = MediaWikiServices::getInstance()
->getService( 'Math.CheckerFactory' )
$checker = Math::getCheckerFactory()
->newLocalChecker( $tex, 'tex' );
if ( $checker->isValid() ) {

View file

@ -3,9 +3,9 @@
namespace MediaWiki\Extension\Math\InputCheck;
use HashBagOStuff;
use MediaWiki\Extension\Math\Math;
use MediaWiki\Extension\Math\MathMathML;
use MediaWiki\Http\HttpRequestFactory;
use MediaWiki\MediaWikiServices;
use MediaWikiIntegrationTestCase;
use MockHttpTrait;
use WANObjectCache;
@ -130,8 +130,7 @@ class MathoidCheckerTest extends MediaWikiIntegrationTestCase {
* @return MathoidChecker
*/
private function getMathoidChecker( $tex = '\sin x' ): MathoidChecker {
return MediaWikiServices::getInstance()
->getService( 'Math.CheckerFactory' )
return Math::getCheckerFactory()
->newMathoidChecker( $tex, 'tex' );
}