Skip to content

Commit

Permalink
[5.x] Remove Str call forwarding for 🌶️ methods (#9637)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
JohnathonKoster and jasonvarga authored Apr 3, 2024
1 parent af95040 commit 8bd663a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,25 @@ public static function safeTruncateReverse($string, $length, $substring = '')
return IlluminateStr::reverse(StaticStringy::safeTruncate(IlluminateStr::reverse($string), $length, $substring));
}

public static function removeRight($string, $cap)
{
if (str_ends_with($string, $cap)) {
return mb_substr($string, 0, mb_strlen($string) - mb_strlen($cap));
}

return $string;
}

public static function ensureLeft($string, $start)
{
return IlluminateStr::start($string, $start);
}

public static function ensureRight($string, $cap)
{
return IlluminateStr::finish($string, $cap);
}

/**
* Implicitly defer all other method calls to either \Stringy\StaticStringy or \Illuminate\Support\Str.
*
Expand All @@ -290,12 +309,12 @@ public static function __callStatic($method, $args)
{
$deferToStringy = [
'append', 'at', 'camelize', 'chars', 'collapseWhitespace', 'containsAny', 'count', 'countSubstr',
'dasherize', 'delimit', 'endsWithAny', 'ensureLeft', 'ensureRight', 'first', 'getEncoding', 'getIterator',
'dasherize', 'delimit', 'endsWithAny', 'first', 'getEncoding', 'getIterator',
'hasLowerCase', 'hasUpperCase', 'htmlDecode', 'htmlEncode', 'humanize', 'indexOf', 'indexOfLast', 'insert',
'isAlpha', 'isAlphanumeric', 'isBase64', 'isBlank', 'isHexadecimal', 'isLowerCase', 'isSerialized',
'isUpperCase', 'last', 'lines', 'longestCommonPrefix', 'longestCommonSubstring', 'longestCommonSuffix',
'lowerCaseFirst', 'offsetExists', 'offsetGet', 'offsetSet', 'offsetUnset', 'pad', 'prepend', 'regexReplace',
'removeLeft', 'removeRight', 'safeTruncate', 'shuffle', 'slice', 'slugify', 'split', 'startsWithAny',
'removeLeft', 'safeTruncate', 'shuffle', 'slice', 'slugify', 'split', 'startsWithAny',
'stripWhitespace', 'surround', 'swapCase', 'tidy', 'titleize', 'toAscii', 'toBoolean', 'toLowerCase',
'toSpaces', 'toTabs', 'toTitleCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'truncate',
'underscored', 'upperCamelize', 'upperCaseFirst',
Expand Down

0 comments on commit 8bd663a

Please sign in to comment.