*/
class ResourceLoader implements LoggerAwareInterface {
/** @var int */
- protected static $filterCacheVersion = 8;
+ const CACHE_VERSION = 8;
/** @var bool */
protected static $debugMode = null;
'resourceloader',
'filter',
$filter,
- self::$filterCacheVersion, md5( $data )
+ self::CACHE_VERSION,
+ md5( $data )
);
$result = $cache->get( $key );
$object->setConfig( $this->getConfig() );
$object->setLogger( $this->logger );
} else {
- if ( !isset( $info['class'] ) ) {
- $class = ResourceLoaderFileModule::class;
- } else {
- $class = $info['class'];
- }
+ $class = $info['class'] ?? ResourceLoaderFileModule::class;
/** @var ResourceLoaderModule $object */
$object = new $class( $info );
$object->setConfig( $this->getConfig() );
* - new XmlJsCode( '{}' )
* - new stdClass() // (object) []
*
- * @param Array $array
+ * @param array $array
*/
private static function trimArray( array &$array ) {
$i = count( $array );
*
* @param array $configuration List of configuration values keyed by variable name
* @return string JavaScript code
+ * @throws Exception
*/
public static function makeConfigSetScript( array $configuration ) {
- return Xml::encodeJsCall(
+ $js = Xml::encodeJsCall(
'mw.config.set',
[ $configuration ],
self::inDebugMode()
);
+ if ( $js === false ) {
+ throw new Exception(
+ 'JSON serialization of config data failed. ' .
+ 'This usually means the config data is not valid UTF-8.'
+ );
+ }
+ return $js;
}
/**
* Global state and $wgRequest are evil, but we're using it right
* now and sometimes we need to be able to force ResourceLoader to
* re-evaluate the context because it has changed (e.g. in the test suite).
+ *
+ * @internal For use by unit tests
+ * @codeCoverageIgnore
*/
public static function clearCache() {
self::$debugMode = null;