Applies a patch to the configuration, top-level key by top-level key.
Description
Shared by merge(), replace(), and set(); the three differ only in how the value of a named key is applied, which is carried by $mode:
mergemerges the value into the current one, lists by member identity;replacemerges the value in the same way but swaps lists wholesale;setswaps the whole value in wholesale, without merging.
In every mode a top-level null resets the key it names to its default, a nested null drops the property it names, and an omitted key is left untouched, so all three treat nulls the same way at every depth.
Parameters
$patcharrayrequired- The partial configuration to apply.
$versionintrequired- The schema version the patch was authored against.
$methodstringrequired- The public method the patch was passed to, for misuse reporting.
$modestringrequired- How to apply each named key’s value:
merge,replace, orset.
Source
private function apply( array $patch, int $version, $method, $mode ) {
if ( $version <= 0 || $version > self::LATEST_VERSION ) {
_doing_it_wrong(
esc_html( $method ),
esc_html__( 'A view configuration patch must declare a supported schema version.' ),
'7.1.0'
);
return $this;
}
foreach ( $patch as $key => $value ) {
if ( ! in_array( $key, self::CONFIG_KEYS, true ) ) {
_doing_it_wrong(
esc_html( $method ),
sprintf(
/* translators: %s: the configuration key. */
esc_html__( '"%s" is not a documented view configuration key.' ),
esc_html( $key )
),
'7.1.0'
);
continue;
}
// A null patch value makes the top-level property reset to defaults.
if ( null === $value ) {
$this->config[ $key ] = $this->defaults[ $key ] ?? array();
continue;
}
// set() swaps the whole value in; merge()/replace() merge it into the
// current one, differing only in how they treat lists. In every mode a
// nested null still drops the property it names.
$this->config[ $key ] = 'set' === $mode
? $this->strip_nulls( $value )
: $this->merge_properties( $this->config[ $key ] ?? array(), $value, 'replace' === $mode );
}
return $this;
}
Changelog
| Version | Description |
|---|---|
| 7.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.