3.4.0
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user