Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderImageModule.php
index 9b50d80..902fa91 100644 (file)
@@ -39,7 +39,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
 
        protected $origin = self::ORIGIN_CORE_SITEWIDE;
 
-       /** @var ResourceLoaderImage[]|null */
+       /** @var ResourceLoaderImage[][]|null */
        protected $imageObjects = null;
        /** @var array */
        protected $images = [];
@@ -113,7 +113,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
         * @throws InvalidArgumentException
         */
        public function __construct( $options = [], $localBasePath = null ) {
-               $this->localBasePath = self::extractLocalBasePath( $options, $localBasePath );
+               $this->localBasePath = static::extractLocalBasePath( $options, $localBasePath );
 
                $this->definition = $options;
        }
@@ -130,7 +130,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                $this->definition = null;
 
                if ( isset( $options['data'] ) ) {
-                       $dataPath = $this->localBasePath . '/' . $options['data'];
+                       $dataPath = $this->getLocalPath( $options['data'] );
                        $data = json_decode( file_get_contents( $dataPath ), true );
                        $options = array_merge( $data, $options );
                }
@@ -259,7 +259,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                                $this->images[$skin] = $this->images['default'] ?? [];
                        }
                        foreach ( $this->images[$skin] as $name => $options ) {
-                               $fileDescriptor = is_string( $options ) ? $options : $options['file'];
+                               $fileDescriptor = is_array( $options ) ? $options['file'] : $options;
 
                                $allowedVariants = array_merge(
                                        ( is_array( $options ) && isset( $options['variants'] ) ) ? $options['variants'] : [],
@@ -452,6 +452,18 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                return array_map( [ __CLASS__, 'safeFileHash' ], $files );
        }
 
+       /**
+        * @param string|ResourceLoaderFilePath $path
+        * @return string
+        */
+       protected function getLocalPath( $path ) {
+               if ( $path instanceof ResourceLoaderFilePath ) {
+                       return $path->getLocalPath();
+               }
+
+               return "{$this->localBasePath}/$path";
+       }
+
        /**
         * Extract a local base path from module definition information.
         *