Upgrade to 3.5.7
This commit is contained in:
@@ -250,7 +250,7 @@ class Str
|
||||
*/
|
||||
public static function contains(string $string = null, string $needle, bool $caseInsensitive = false): bool
|
||||
{
|
||||
return call_user_func($caseInsensitive === true ? 'stristr' : 'strstr', $string, $needle) !== false;
|
||||
return call_user_func($caseInsensitive === true ? 'stripos' : 'strpos', $string, $needle) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -962,17 +962,32 @@ class Str
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string The string with placeholders
|
||||
* @param string|null $string The string with placeholders
|
||||
* @param array $data Associative array with placeholders as
|
||||
* keys and replacements as values
|
||||
* @param string $fallback A fallback if a token does not have any matches
|
||||
* @param string|array|null $fallback An options array that contains:
|
||||
* - fallback: if a token does not have any matches
|
||||
* - callback: to be able to handle each matching result
|
||||
* - start: start placeholder
|
||||
* - end: end placeholder
|
||||
* A simple fallback string is supported for compatibility (but deprecated).
|
||||
* @param string $start Placeholder start characters
|
||||
* @param string $end Placeholder end characters
|
||||
*
|
||||
* @todo Deprecate `string $fallback` and `$start`/`$end` arguments with warning in 3.6.0
|
||||
* @todo Remove `$start` and `$end` parameters, rename `$fallback` to `$options` and only support `array` type for `$options` in 3.7.0
|
||||
*
|
||||
* @return string The filled-in string
|
||||
*/
|
||||
public static function template(string $string = null, array $data = [], string $fallback = null, string $start = '{{', string $end = '}}'): string
|
||||
public static function template(string $string = null, array $data = [], $fallback = null, string $start = '{{', string $end = '}}'): string
|
||||
{
|
||||
return preg_replace_callback('!' . $start . '(.*?)' . $end . '!', function ($match) use ($data, $fallback) {
|
||||
$options = $fallback;
|
||||
$fallback = is_string($options) === true ? $options : ($options['fallback'] ?? null);
|
||||
$callback = is_a(($options['callback'] ?? null), 'Closure') === true ? $options['callback'] : null;
|
||||
$start = (string)($options['start'] ?? $start);
|
||||
$end = (string)($options['end'] ?? $end);
|
||||
|
||||
return preg_replace_callback('!' . $start . '(.*?)' . $end . '!', function ($match) use ($data, $fallback, $callback) {
|
||||
$query = trim($match[1]);
|
||||
|
||||
// if the placeholder contains a dot, it is a query
|
||||
@@ -991,6 +1006,11 @@ class Str
|
||||
$result = $fallback;
|
||||
}
|
||||
|
||||
// callback on result if given
|
||||
if ($callback !== null) {
|
||||
$result = $callback((string)$result, $query, $data);
|
||||
}
|
||||
|
||||
// if we still don't have a result, keep the original placeholder
|
||||
return $result ?? $match[0];
|
||||
}, $string);
|
||||
|
Reference in New Issue
Block a user