Skip to content

Latest commit

 

History

History
171 lines (97 loc) · 2.58 KB

BDotTool.md

File metadata and controls

171 lines (97 loc) · 2.58 KB

BDotTool

2017-10-27 -> 2020-07-20

This class contains functions for interacting with arrays using the bdot notation.

escape

2020-07-20

string escape ( str:str )

Returns an escaped string.

So, dots are prefixed with the backslash character.

getDotValue

2017-10-27

mixed getDotValue ( str:path, array:array, mixed:default=null, bool &found=false)

Return the value pointed by path in the given array, or the default value if not found. Also positions the found flag to whether the value was actually found or not.

getPathComponents

2019-08-08

array getPathComponents ( str:path, bool:keepEscapedDots=true)

Returns an array containing the components of the given path.

Escaped dots are returned as is by default, but this method can unescape them on the fly by setting the keepEscapedDots option to false.

Example:

a(BDotTool::getPathComponents("my"));
a(BDotTool::getPathComponents("my.one"));
a(BDotTool::getPathComponents("my.one\.two.three"));
a(BDotTool::getPathComponents("my.one\.two.three", false));

Will output:

array(1) {
  [0] => string(2) "my"
}

array(2) {
  [0] => string(2) "my"
  [1] => string(3) "one"
}

array(3) {
  [0] => string(2) "my"
  [1] => string(8) "one\.two"
  [2] => string(5) "three"
}

array(3) {
  [0] => string(2) "my"
  [1] => string(7) "one.two"
  [2] => string(5) "three"
}

hasDotValue

2017-10-27

bool hasDotValue ( str:path, array:array )

Return whether or not the value pointed by path exists.

setDotValue

2017-10-27

void setDotValue ( str:path, mixed:replacement, array:array )

Sets a value in an array. Note: if the key does not exist, it will be created. Also, if a key along the path is not an array, it will be overwritten and become an array.

unescape

2020-07-20

string unescape ( str:str )

Returns the unescaped version of the given string.

unsetDotValue

2017-10-27

void unsetDotValue ( str:path, array:array )

Unset the value from the given array if it exists.

walk

2017-10-27

void walk ( array:array, callable:callback )

Applies the given callback to every element of the array. The callback receives the value and has the opportunity to change it via the reference; it also receives the current key and the current dotPath.

  • callback ( &?value, key, dotPath )