Cradle  0.3.3
Simple library for creating Web-based applications
Basic Class Reference

Digger Basic Class. More...

Static Public Member Functions

static replace ($templateText, $hashReplacements, $leftQualifier="[", $rightQualifier="]")
 
static inPatterns ($value, $patternList, $returnPattern=false)
 
static pathValue ($array, $basePath=null, $keyPrefix=null, $keyPostfix=null)
 
static initClass ($class, $config=null)
 

Detailed Description

Digger Basic Class.

Digger class of common simple basic functions

Version
3.0
Author
Digger mrdig.nosp@m.ger@.nosp@m.sad-s.nosp@m.yste.nosp@m.ms.ru

Member Function Documentation

static initClass (   $class,
  $config = null 
)
static

To initialize some class by configuration array.
Only the public methods will be initialized.

Parameters
class$classSome class
array$configConfiguration array
static inPatterns (   $value,
  $patternList,
  $returnPattern = false 
)
static

Checks if a value matches any of patterns

Example:

Basic::inPatterns( "someString", array("^some", "ing$", "\.php$") );
//-------------
// Will return: TRUE
Basic::inPatterns( "some data in text", array("data", "need", "to find"), true );
//-------------
// Will return: "data"
Parameters
string$valueSubject for matching.
array$patternListArray of regular expressions (patterns).
Returns
boolean | string TRUE (or pattern) if specified value matches one of patterns from list. FALSE if no matches.
static pathValue (   $array,
  $basePath = null,
  $keyPrefix = null,
  $keyPostfix = null 
)
static

To create a two-dimensional array from multidimensional array by replacing a sequence of keys of the original array to the single path contains this sequence.

Parameters
array$arrayInput multidimensional array
string$basePath(Optional)
string$keyPrefix(Optional) Prefix for key (for example: '[' )
string$keyPostfix(Optional) Postfix for key (for example: ']' )
Returns
array two-dimensional array

Example:

$inputArray = [
'a' => [
'b' => [
'c' => 'value'
]
]
];
print_r(self::pathValue($inputArray));
print_r(self::pathValue($inputArray, 'base'));
print_r(self::pathValue($inputArray, 'base', '[', ']'));
//--- Output:
Array {
'a/b/c' => 'value'
}
Array {
'base/a/b/c' => 'value'
}
Array {
'[base/a/b/c]' => 'value'
}
static replace (   $templateText,
  $hashReplacements,
  $leftQualifier = "[",
  $rightQualifier = "]" 
)
static

To replace keys in the text template by values.

Example:

$text = "some text with some [KEY1] and [KEY2] ...";
$replacements = array("[KEY1]" => "Value1", "[KEY2]" => "Value2");
echo Basic::replace($text, $replacements);
//-------------
// Will output: some text with some Value1 and Value2 ..
Parameters
string$templateTextTemplate text.
hash$hashReplacementsHash array of replacements.
string$leftQualifierLeft qualifier (by default = '[').
string$rightQualifierRight qualifier (by default = ']').
Returns
string Template text with replacements.

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