From 7490ed68d602f3d08a52109ef900428ee6cab49e Mon Sep 17 00:00:00 2001 From: Nicolas Perraut Date: Thu, 7 May 2020 11:28:13 +0200 Subject: [PATCH 1/2] Add split() to Stringable class --- src/Illuminate/Support/Stringable.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 652e150d00db..442ff15fc9a8 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -193,6 +193,25 @@ public function explode($delimiter, $limit = PHP_INT_MAX) { return collect(explode($delimiter, $this->value, $limit)); } + + /** + * Split string by a regular expression. + * + * @param string $pattern + * @param int $limit + * @param int $flags + * @return \Illuminate\Support\Collection + */ + public function split($pattern, $limit = -1, $flags = 0) + { + $keywords = preg_split($pattern, $this->value, $limit, $flags); + + if(! $keywords) { + return collect(); + } + + return collect($keywords); + } /** * Cap a string with a single instance of a given value. From 87bb1352e9e15c28700ffdd3656b429ceddf4e7d Mon Sep 17 00:00:00 2001 From: Nicolas Perraut Date: Thu, 7 May 2020 11:39:21 +0200 Subject: [PATCH 2/2] Fix StyleCI lint --- src/Illuminate/Support/Stringable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 442ff15fc9a8..91e0be9cf776 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -193,7 +193,7 @@ public function explode($delimiter, $limit = PHP_INT_MAX) { return collect(explode($delimiter, $this->value, $limit)); } - + /** * Split string by a regular expression. * @@ -206,7 +206,7 @@ public function split($pattern, $limit = -1, $flags = 0) { $keywords = preg_split($pattern, $this->value, $limit, $flags); - if(! $keywords) { + if (! $keywords) { return collect(); }