$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;
}
/**