From: Bartosz DziewoƄski Date: Mon, 30 Mar 2015 16:51:10 +0000 (+0200) Subject: resourceloader: Throw InvalidArgumentException for invalid constructor arguments X-Git-Tag: 1.31.0-rc.0~11914^2~1 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=7aeadb7f680aedaca143665fb31099f047464745 resourceloader: Throw InvalidArgumentException for invalid constructor arguments (But not for exceptions about missing files.) Per Legoktm's comments on 8edbfb5feb708f80d63f118f9b00eb341278f68a. Change-Id: I725f846476d2d97d3d820bc22674f7b5aab812bb --- diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index a46c9316c5..db10b2c74e 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -174,7 +174,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * to $wgResourceBasePath * * Below is a description for the $options array: - * @throws MWException + * @throws InvalidArgumentException * @par Construction options: * @code * array( @@ -255,14 +255,14 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { case 'skinScripts': case 'skinStyles': if ( !is_array( $option ) ) { - throw new MWException( + throw new InvalidArgumentException( "Invalid collated file path list error. " . "'$option' given, array expected." ); } foreach ( $option as $key => $value ) { if ( !is_string( $key ) ) { - throw new MWException( + throw new InvalidArgumentException( "Invalid collated file path list key error. " . "'$key' given, string expected." ); diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php index 4b16a121b5..d12975a548 100644 --- a/includes/resourceloader/ResourceLoaderImage.php +++ b/includes/resourceloader/ResourceLoaderImage.php @@ -44,7 +44,7 @@ class ResourceLoaderImage { * @param string|array $descriptor Path to image file, or array structure containing paths * @param string $basePath Directory to which paths in descriptor refer * @param array $variants - * @throws MWException + * @throws InvalidArgumentException */ public function __construct( $name, $module, $descriptor, $basePath, $variants ) { $this->name = $name; @@ -61,11 +61,11 @@ class ResourceLoaderImage { } ); $extensions = array_unique( $extensions ); if ( count( $extensions ) !== 1 ) { - throw new MWException( "File type for different image files of '$name' not the same." ); + throw new InvalidArgumentException( "File type for different image files of '$name' not the same." ); } $ext = $extensions[0]; if ( !isset( self::$fileTypes[$ext] ) ) { - throw new MWException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)." ); + throw new InvalidArgumentException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)." ); } $this->extension = $ext; } diff --git a/includes/resourceloader/ResourceLoaderImageModule.php b/includes/resourceloader/ResourceLoaderImageModule.php index 28aebdf99d..88ba59752b 100644 --- a/includes/resourceloader/ResourceLoaderImageModule.php +++ b/includes/resourceloader/ResourceLoaderImageModule.php @@ -85,7 +85,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule { * ), * ) * @endcode - * @throws MWException + * @throws InvalidArgumentException */ public function __construct( $options = array(), $localBasePath = null ) { $this->localBasePath = self::extractLocalBasePath( $options, $localBasePath ); @@ -103,16 +103,16 @@ class ResourceLoaderImageModule extends ResourceLoaderModule { $selectorWithVariant = isset( $options['selectorWithVariant'] ) && $options['selectorWithVariant']; if ( $selectorWithoutVariant && !$selectorWithVariant ) { - throw new MWException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." ); + throw new InvalidArgumentException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." ); } if ( $selectorWithVariant && !$selectorWithoutVariant ) { - throw new MWException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." ); + throw new InvalidArgumentException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." ); } if ( $selector && $selectorWithVariant ) { - throw new MWException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." ); + throw new InvalidArgumentException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." ); } if ( !$prefix && !$selector && !$selectorWithVariant ) { - throw new MWException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." ); + throw new InvalidArgumentException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." ); } foreach ( $options as $member => $option ) { @@ -120,7 +120,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule { case 'images': case 'variants': if ( !is_array( $option ) ) { - throw new MWException( + throw new InvalidArgumentException( "Invalid list error. '$option' given, array expected." ); }