provide recursiveArraySearch as Helper function and make available through API
This commit is contained in:
parent
42492338fc
commit
6b320a2604
2 changed files with 38 additions and 1 deletions
|
@ -360,7 +360,7 @@ class OC_Helper {
|
|||
}else{
|
||||
$mimeType='application/octet-stream';
|
||||
}
|
||||
|
||||
|
||||
if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){
|
||||
$info = @strtolower(finfo_file($finfo,$path));
|
||||
if($info){
|
||||
|
@ -679,4 +679,30 @@ class OC_Helper {
|
|||
}
|
||||
return $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief performs a search in a nested array
|
||||
* @param haystack the array to be searched
|
||||
* @param needle the search string
|
||||
* @param $index optional, only search this key name
|
||||
* @return the key of the matching field, otherwise false
|
||||
*
|
||||
* performs a search in a nested array
|
||||
*
|
||||
* taken from http://www.php.net/manual/en/function.array-search.php#97645
|
||||
*/
|
||||
public static function recursiveArraySearch($haystack, $needle, $index = null) {
|
||||
$aIt = new RecursiveArrayIterator($haystack);
|
||||
$it = new RecursiveIteratorIterator($aIt);
|
||||
|
||||
while($it->valid()) {
|
||||
if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) {
|
||||
return $aIt->key();
|
||||
}
|
||||
|
||||
$it->next();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,4 +320,15 @@ class Util {
|
|||
public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) {
|
||||
return(\OC_Helper::mb_str_replace($search, $replace, $subject, $encoding, $count));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief performs a search in a nested array
|
||||
* @param haystack the array to be searched
|
||||
* @param needle the search string
|
||||
* @param $index optional, only search this key name
|
||||
* @return the key of the matching field, otherwise false
|
||||
*/
|
||||
public static function recursiveArraySearch($haystack, $needle, $index = null) {
|
||||
return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue