X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderImageModule.php;h=902fa91b7936c6ed456699eed9d00a26731b24f2;hb=9d37c792b2ee408b6a01b43a1a649e6074c11c34;hp=9b50d80f6990f1e4cb0d3128ca49fccb091a5b0c;hpb=c9e671dbebf2fbdda7ecbf35562dacb7de04cec0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderImageModule.php b/includes/resourceloader/ResourceLoaderImageModule.php index 9b50d80f69..902fa91b79 100644 --- a/includes/resourceloader/ResourceLoaderImageModule.php +++ b/includes/resourceloader/ResourceLoaderImageModule.php @@ -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. *