Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Lib\Serialization\SerializationModifier Class Reference

Class which can be used to easily modify serializations and arrays. More...

Public Member Functions

 modifyUsingCallback (array $array, $path, $callback)
 

Private Member Functions

 setArrayValueAtKey (array &$array, $path, $value)
 
 getElementsMatchingPath (array $array, array $pathElements, $currentPath='')
 Method to get elements that match the path given.
 
 getElementsForAllKeys (array $array, array $pathElements, $currentPath)
 
 getElementsForKey (array $array, array $pathElements, $currentPath, $key)
 
 getJoinedPath ( $prefix, $key)
 
 getPathParts ( $path)
 

Detailed Description

Class which can be used to easily modify serializations and arrays.

This could easily be factored out into a library.

Author
Addshore

Member Function Documentation

◆ getElementsForAllKeys()

Wikibase\Lib\Serialization\SerializationModifier::getElementsForAllKeys ( array  $array,
array  $pathElements,
  $currentPath 
)
private
Parameters
array$array
string[]$pathElements
string$currentPath
Returns
array

◆ getElementsForKey()

Wikibase\Lib\Serialization\SerializationModifier::getElementsForKey ( array  $array,
array  $pathElements,
  $currentPath,
  $key 
)
private
Parameters
array$array
string[]$pathElements
string$currentPath
string$key
Returns
array

◆ getElementsMatchingPath()

Wikibase\Lib\Serialization\SerializationModifier::getElementsMatchingPath ( array  $array,
array  $pathElements,
  $currentPath = '' 
)
private

Method to get elements that match the path given.

This is called recursively along with getElementsForAllKeys and getElementsForKey The number of calls depends on the depth of the array.

Parameters
array$array
string[]$pathElements
string$currentPath
Returns
array

◆ getJoinedPath()

Wikibase\Lib\Serialization\SerializationModifier::getJoinedPath (   $prefix,
  $key 
)
private
Parameters
string$prefix
string$key
Returns
string

◆ getPathParts()

Wikibase\Lib\Serialization\SerializationModifier::getPathParts (   $path)
private
Parameters
null | string$path
Returns
string[]

◆ modifyUsingCallback()

Wikibase\Lib\Serialization\SerializationModifier::modifyUsingCallback ( array  $array,
  $path,
  $callback 
)
Parameters
array$arraythe array to modify
null | string$paththe path that we want to modify. Element keys should be separated with / characters.
  • characters can be used to match all keys at a given level. null can be used to modify $array directly. Examples: null 'foo/*' 'root/entities/*\/statement/references/*\/snaks/*'
callback$callbackCallback accepts 1 parameter which is the element to touch Callback should return the altered element
Returns
array the altered array

◆ setArrayValueAtKey()

Wikibase\Lib\Serialization\SerializationModifier::setArrayValueAtKey ( array &  $array,
  $path,
  $value 
)
private
Parameters
array$array
string$path
mixed$value

The documentation for this class was generated from the following file: