Class which can be used to easily modify serializations and arrays.
More...
Class which can be used to easily modify serializations and arrays.
This could easily be factored out into a library.
- Copyright
- GPL-2.0-or-later
◆ getPathParts()
Wikibase\Lib\Serialization\SerializationModifier::getPathParts |
( |
?string |
$path | ) |
|
|
private |
- Parameters
-
- Returns
- string[]
◆ modifyUsingCallbacks()
Wikibase\Lib\Serialization\SerializationModifier::modifyUsingCallbacks |
( |
array |
$array, |
|
|
array |
$modifications |
|
) |
| |
- Parameters
-
array | $array | The array to modify. |
| (callable|callable[])[] | $modifications Mapping from paths to modifications. Array keys are paths: Element keys should be separated with / characters.
- characters can be used to match all keys at a given level. Empty string can be used to modify $array directly. Examples: '' 'foo/*' 'root/entities/*\/statement/references/*\/snaks/*' More specific paths always run first (e.g. foo/bar before foo), so that array elements added by callbacks are never matched against other paths. Elements are callbacks or lists of callbacks: Callback accepts 1 parameter which is the element to touch Callback should return the altered element
|
- Returns
- array The altered array.
◆ modifyUsingUnflattenedCallbacks()
Wikibase\Lib\Serialization\SerializationModifier::modifyUsingUnflattenedCallbacks |
( |
& |
$value, |
|
|
array |
$modifications |
|
) |
| |
|
private |
Iterates the value and modifications and runs all the needed sub-modifications, then runs the modifications of the current array level ('' key), if any.
- Parameters
-
mixed | $value | The value to modify (usually an array except on leaf nodes). |
array | $modifications | Modifications as returned by unflattenPaths. |
◆ unflattenPaths()
Wikibase\Lib\Serialization\SerializationModifier::unflattenPaths |
( |
array |
$array | ) |
|
|
private |
Turn a flat array with paths as keys into a nested structure.
Example input:
[
'' => 'cb0',
'claims' => 'cb1',
'claims/foo' => 'cb2',
'claims/*\/bar' => 'cb3',
'label' => 'cb4',
]
Example output:
[
'' => 'cb0',
'claims' => [
'' => 'cb1',
'foo' => [ '' => 'cb2' ],
'*' => [
'bar' => [ '' => 'cb3' ],
],
],
'label' => [ '' => 'cb4' ],
]
- Parameters
-
- Returns
- array
The documentation for this class was generated from the following file: