*/
class ResourceLoaderImageModule extends ResourceLoaderModule {
+ /** @var array|null */
protected $definition = null;
/**
protected $origin = self::ORIGIN_CORE_SITEWIDE;
+ /** @var ResourceLoaderImage[]|null */
+ protected $imageObjects = null;
+ /** @var array */
protected $images = [];
+ /** @var string|null */
protected $defaultColor = null;
+ protected $useDataURI = true;
+ /** @var array|null */
+ protected $globalVariants = null;
+ /** @var array */
protected $variants = [];
+ /** @var string|null */
protected $prefix = null;
protected $selectorWithoutVariant = '.{prefix}-{name}';
protected $selectorWithVariant = '.{prefix}-{name}-{variant}';
*
* @param array $options List of options; if not given or empty, an empty module will be
* constructed
- * @param string $localBasePath Base path to prepend to all local paths in $options. Defaults
+ * @param string|null $localBasePath Base path to prepend to all local paths in $options. Defaults
* to $IP
*
* Below is a description for the $options array:
$option = [ 'default' => $option ];
}
foreach ( $option as $skin => $data ) {
- if ( !is_array( $option ) ) {
+ if ( !is_array( $data ) ) {
throw new InvalidArgumentException(
- "Invalid list error. '$option' given, array expected."
+ "Invalid list error. '$data' given, array expected."
);
}
}
$this->{$member} = $option;
break;
+ case 'useDataURI':
+ $this->{$member} = (bool)$option;
+ break;
case 'defaultColor':
case 'prefix':
case 'selectorWithoutVariant':
/**
* Get CSS selector templates used by this module.
- * @return string
+ * @return string[]
*/
public function getSelectors() {
$this->loadFromDefinition();
*/
public function getImages( ResourceLoaderContext $context ) {
$skin = $context->getSkin();
- if ( !isset( $this->imageObjects ) ) {
+ if ( $this->imageObjects === null ) {
$this->loadFromDefinition();
$this->imageObjects = [];
}
*/
public function getGlobalVariants( ResourceLoaderContext $context ) {
$skin = $context->getSkin();
- if ( !isset( $this->globalVariants ) ) {
+ if ( $this->globalVariants === null ) {
$this->loadFromDefinition();
$this->globalVariants = [];
}
$script,
$variant = null
) {
- $imageDataUri = $image->getDataUri( $context, $variant, 'original' );
+ $imageDataUri = $this->useDataURI ? $image->getDataUri( $context, $variant, 'original' ) : false;
$primaryUrl = $imageDataUri ?: $image->getUrl( $context, $script, $variant, 'original' );
$declarations = $this->getCssDeclarations(
$primaryUrl,
'selectorWithVariant',
] as $member ) {
$options[$member] = $this->{$member};
- };
+ }
$summary[] = [
'options' => $options,
* Extract a local base path from module definition information.
*
* @param array $options Module definition
- * @param string $localBasePath Path to use if not provided in module definition. Defaults
+ * @param string|null $localBasePath Path to use if not provided in module definition. Defaults
* to $IP
* @return string Local base path
*/