This commit is contained in:
Bastian Allgeier
2020-07-07 12:40:13 +02:00
parent 5f025ac2c2
commit f79d2e960c
176 changed files with 10532 additions and 5343 deletions

View File

@@ -341,7 +341,7 @@ class Str
* @param string $rep The element, which should be added if the string is too long. Ellipsis is the default.
* @return string The shortened string
*/
public static function excerpt($string, $chars = 140, $strip = true, $rep = '…')
public static function excerpt($string, $chars = 140, $strip = true, $rep = ' …')
{
if ($strip === true) {
$string = strip_tags(str_replace('<', ' <', $string));
@@ -361,7 +361,7 @@ class Str
return $string;
}
return static::substr($string, 0, mb_strrpos(static::substr($string, 0, $chars), ' ')) . ' ' . $rep;
return static::substr($string, 0, mb_strrpos(static::substr($string, 0, $chars), ' ')) . $rep;
}
/**
@@ -897,10 +897,25 @@ class Str
{
return preg_replace_callback('!' . $start . '(.*?)' . $end . '!', function ($match) use ($data, $fallback) {
$query = trim($match[1]);
// if the placeholder contains a dot, it is a query
if (strpos($query, '.') !== false) {
return (new Query($match[1], $data))->result() ?? $fallback;
try {
$result = (new Query($match[1], $data))->result();
} catch (Exception $e) {
$result = null;
}
} else {
$result = $data[$query] ?? null;
}
return $data[$query] ?? $fallback;
// if we don't have a result, use the fallback if given
if ($result === null && $fallback !== null) {
$result = $fallback;
}
// if we still don't have a result, keep the original placeholder
return $result ?? $match[0];
}, $string);
}