326af919
mzavalniuk
add artbox-core t...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<?php
namespace artbox\core\helpers;
class UnificatorHelper
{
/**
* Helper which returns unique value according to checker function
* Checker function must return boolean
*
* @param string $value
* @param callable $checker
*
* @return string
*/
public static function unify(string $value, callable $checker): string
{
$baseVal = $value;
$index = 1;
do {
$result = call_user_func($checker, $value);
if (!$result) {
$value = $baseVal . ' ' . $index;
}
$index++;
} while (!$result);
return $value;
}
}
|