39 protected $origin = self::ORIGIN_CORE_SITEWIDE;
115 $this->localBasePath = static::extractLocalBasePath( $options,
$localBasePath );
117 $this->definition = $options;
124 if ( $this->definition ===
null ) {
129 $this->definition =
null;
131 if ( isset( $options[
'data'] ) ) {
133 $data = json_decode( file_get_contents( $dataPath ),
true );
134 $options = array_merge( $data, $options );
144 $prefix = isset( $options[
'prefix'] ) && $options[
'prefix'];
145 $selector = isset( $options[
'selector'] ) && $options[
'selector'];
147 && $options[
'selectorWithoutVariant'];
149 && $options[
'selectorWithVariant'];
152 throw new InvalidArgumentException(
153 "Given 'selectorWithoutVariant' but no 'selectorWithVariant'."
157 throw new InvalidArgumentException(
158 "Given 'selectorWithVariant' but no 'selectorWithoutVariant'."
162 throw new InvalidArgumentException(
163 "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given."
167 throw new InvalidArgumentException(
168 "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given."
172 foreach ( $options as $member => $option ) {
176 if ( !is_array( $option ) ) {
177 throw new InvalidArgumentException(
178 "Invalid list error. '$option' given, array expected."
181 if ( !isset( $option[
'default'] ) ) {
183 $option = [
'default' => $option ];
185 foreach ( $option as $skin => $data ) {
186 if ( !is_array( $data ) ) {
187 throw new InvalidArgumentException(
188 "Invalid list error. '$data' given, array expected."
192 $this->{$member} = $option;
196 $this->{$member} = (bool)$option;
200 case 'selectorWithoutVariant':
201 case 'selectorWithVariant':
202 $this->{$member} = (string)$option;
206 $this->selectorWithoutVariant = $this->selectorWithVariant = (string)$option;
251 if ( $this->imageObjects ===
null ) {
253 $this->imageObjects = [];
255 if ( !isset( $this->imageObjects[$skin] ) ) {
256 $this->imageObjects[$skin] = [];
257 if ( !isset( $this->images[$skin] ) ) {
258 $this->images[$skin] = $this->images[
'default'] ?? [];
260 foreach ( $this->images[$skin] as
$name => $options ) {
261 $fileDescriptor = is_array( $options ) ? $options[
'file'] : $options;
263 $allowedVariants = array_merge(
264 ( is_array( $options ) && isset( $options[
'variants'] ) ) ? $options[
'variants'] : [],
267 if ( isset( $this->variants[$skin] ) ) {
268 $variantConfig = array_intersect_key(
269 $this->variants[$skin],
270 array_fill_keys( $allowedVariants,
true )
280 $this->localBasePath,
284 $this->imageObjects[$skin][$image->getName()] = $image;
288 return $this->imageObjects[$skin];
299 if ( $this->globalVariants ===
null ) {
301 $this->globalVariants = [];
303 if ( !isset( $this->globalVariants[$skin] ) ) {
304 $this->globalVariants[$skin] = [];
305 if ( !isset( $this->variants[$skin] ) ) {
306 $this->variants[$skin] = $this->variants[
'default'] ?? [];
308 foreach ( $this->variants[$skin] as
$name =>
$config ) {
310 $this->globalVariants[$skin][] =
$name;
315 return $this->globalVariants[$skin];
333 $selectors[
'selectorWithoutVariant'],
340 $rules[] =
"$selector {\n\t$declarations\n}";
342 foreach ( $image->getVariants() as $variant ) {
345 $selectors[
'selectorWithVariant'],
349 '{variant}' => $variant,
352 $rules[] =
"$selector {\n\t$declarations\n}";
356 $style = implode(
"\n", $rules );
357 return [
'all' => $style ];
377 $imageDataUri = $this->useDataURI ? $image->
getDataUri(
$context, $variant,
'original' ) :
false;
378 $primaryUrl = $imageDataUri ?: $image->
getUrl(
$context, $script, $variant,
'original' );
383 return implode(
"\n\t", $declarations );
399 $primaryUrl = CSSMin::buildUrlValue( $primary );
400 $fallbackUrl = CSSMin::buildUrlValue(
$fallback );
402 "background-image: $fallbackUrl;",
403 "background-image: linear-gradient(transparent, transparent), $primaryUrl;",
422 $summary = parent::getDefinitionSummary(
$context );
430 'selectorWithoutVariant',
431 'selectorWithVariant',
433 $options[$member] = $this->{$member};
437 'options' => $options,
452 $files[] = $image->getPath(
$context );
454 $files = array_values( array_unique( $files ) );
455 return array_map( [ __CLASS__,
'safeFileHash' ], $files );
464 return $path->getLocalPath();
467 return "{$this->localBasePath}/$path";
485 if ( array_key_exists(
'localBasePath', $options ) ) {
496 return self::LOAD_STYLES;