mirror of
https://github.com/friendica/friendica
synced 2025-04-23 17:50:16 +00:00
Fixed E_NOTICE in listing worker queue and new utilities class added (#5521)
* Fixes for E_NOTICE in workqueue: - introduced class `Friendica\Util\Arrays` which will hold static methods for handling arrays that cannot be done with PHP's functions, like implode() on multi-dimensional arrays - rewrote old-school for() loop to foreach() * Added intial unit test with some tests on empty delimiters and/or sinle and multi-dim array. * Added test for for 3-dimensional arrays, thanks to nupplaphil's feedback.
This commit is contained in:
parent
3da1b9f319
commit
bf87ad4fcf
3 changed files with 166 additions and 2 deletions
49
src/Util/Arrays.php
Normal file
49
src/Util/Arrays.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* @file src/Util/Arrays.php
|
||||
* @author Roland Haeder<https://f.haeder.net/profile/roland>
|
||||
*/
|
||||
namespace Friendica\Util;
|
||||
|
||||
/**
|
||||
* @brief Array utility class
|
||||
*/
|
||||
class Arrays
|
||||
{
|
||||
/**
|
||||
* @brief Private constructor
|
||||
*/
|
||||
private function __construct () {
|
||||
// Utitlities don't have instances
|
||||
}
|
||||
|
||||
/**
|
||||
* @briefs Implodes recursively a multi-dimensional array where a normal implode() will fail.
|
||||
*
|
||||
* @param array $array Array to implode
|
||||
* @param string $glue Glue for imploded elements
|
||||
* @return string String with elements from array
|
||||
*/
|
||||
public static function recursiveImplode (array $array, $glue) {
|
||||
// Init returned string
|
||||
$string = '';
|
||||
|
||||
// Loop through all records
|
||||
foreach ($array as $element) {
|
||||
// Is an array found?
|
||||
if (is_array($element)) {
|
||||
// Invoke cursively
|
||||
$string .= '{' . self::recursiveImplode($element, $glue) . '}' . $glue;
|
||||
} else {
|
||||
// Append normally
|
||||
$string .= $element . $glue;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove last glue
|
||||
$string = trim($string, $glue);
|
||||
|
||||
// Return it
|
||||
return $string;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue