From cdbd1cbdcc501877e834f9137e32b7b3f34f7632 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Tue, 8 Jan 2019 01:57:02 +0800 Subject: [PATCH 01/27] Sqlsrv test WIP --- Str.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Str.php b/Str.php index fbe8ed4f..5bfe6a06 100644 --- a/Str.php +++ b/Str.php @@ -8,6 +8,8 @@ namespace Windwalker\String; +use Windwalker\Utilities\Arr; + /** * The StringHelper class. * @@ -25,6 +27,29 @@ class Str const ENCODING_US_ASCII = 'US-ASCII'; + /** + * Convert all to string. + * + * @param mixed $data The data to convert. + * @param bool $dump If is array or object, will dump it if this argument set to TRUE. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + public static function toString($data, bool $dump = true): string + { + if (is_array($data)) { + $data = $dump ? Arr::dump($data) : 'Array()'; + } + + if (is_object($data)) { + $data = $dump ? Arr::dump($data) : sprintf('[Object %s]', get_class($data)); + } + + return (string) $data; + } + /** * at * From 519b909644c1987fe4e5a901ea25e3788ca5faa3 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 13 Jan 2019 15:43:16 +0800 Subject: [PATCH 02/27] version --- Str.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Str.php b/Str.php index 5bfe6a06..c2b1ad58 100644 --- a/Str.php +++ b/Str.php @@ -35,7 +35,7 @@ class Str * * @return string * - * @since __DEPLOY_VERSION__ + * @since 3.5 */ public static function toString($data, bool $dump = true): string { From 40b37d0adaed91d1c94a0134b15db72a201f5e56 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 13 Jan 2019 16:21:45 +0800 Subject: [PATCH 03/27] update php limit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index af004826..26753db7 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/ventoviro/windwalker-string", "license": "LGPL-2.0-or-later", "require": { - "php": ">=5.5.9" + "php": ">=7.1.3" }, "require-dev": { "windwalker/test": "~3.0", From a2ad68fecb9b9e1c99fe89732e631a2d47a568dc Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 13 Jan 2019 16:39:07 +0800 Subject: [PATCH 04/27] Update package test --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5309d487..7b69eda5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,10 @@ sudo: false dist: trusty php: - - 5.5 - - 5.6 - - 7.0 - 7.1 + - 7.2 + - 7.3 + before_script: - composer update --dev From 37e6edc2e09213a70472ce04bba06bac9fb7eaf7 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Thu, 18 Apr 2019 12:29:08 +0800 Subject: [PATCH 05/27] to string support callable --- Str.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Str.php b/Str.php index c2b1ad58..74b15aad 100644 --- a/Str.php +++ b/Str.php @@ -17,15 +17,15 @@ */ class Str { - const CASE_SENSITIVE = true; + public const CASE_SENSITIVE = true; - const CASE_INSENSITIVE = false; + public const CASE_INSENSITIVE = false; - const ENCODING_DEFAULT_ISO = 'ISO-8859-1'; + public const ENCODING_DEFAULT_ISO = 'ISO-8859-1'; - const ENCODING_UTF8 = 'UTF-8'; + public const ENCODING_UTF8 = 'UTF-8'; - const ENCODING_US_ASCII = 'US-ASCII'; + public const ENCODING_US_ASCII = 'US-ASCII'; /** * Convert all to string. @@ -39,6 +39,10 @@ class Str */ public static function toString($data, bool $dump = true): string { + if (is_callable($data)) { + return static::toString($data()); + } + if (is_array($data)) { $data = $dump ? Arr::dump($data) : 'Array()'; } From 11ec6e8266dddc91d5345dc48eb0d163f26436d8 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Thu, 18 Apr 2019 23:21:01 +0800 Subject: [PATCH 06/27] Support DOM functions --- Str.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Str.php b/Str.php index 74b15aad..60fb5d9e 100644 --- a/Str.php +++ b/Str.php @@ -43,6 +43,10 @@ public static function toString($data, bool $dump = true): string return static::toString($data()); } + if (is_stringable($data)) { + return (string) $data; + } + if (is_array($data)) { $data = $dump ? Arr::dump($data) : 'Array()'; } From b727f81c096aed47cdd1fbccf35d1b7fc844c5e8 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 27 Apr 2019 19:15:30 +0800 Subject: [PATCH 07/27] Fix all test --- Test/InflectorTest.php | 5 +++-- Test/SimpleTemplateTest.php | 2 +- Test/StringObjectTest.php | 2 +- Test/Utf8StringTest.php | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Test/InflectorTest.php b/Test/InflectorTest.php index 73e59445..e6c36b0f 100644 --- a/Test/InflectorTest.php +++ b/Test/InflectorTest.php @@ -89,7 +89,7 @@ public function seedSinglePlural() * * @since 2.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -154,11 +154,12 @@ public function testAddRule() * * @throws \ReflectionException * @covers \Windwalker\String\StringInflector::addRule - * @expectedException InvalidArgumentException * @since 2.0 */ public function testAddRuleException() { + $this->expectException(\InvalidArgumentException::class); + TestHelper::invoke($this->StringInflector, 'addRule', new \stdClass(), 'singular'); } diff --git a/Test/SimpleTemplateTest.php b/Test/SimpleTemplateTest.php index df5a23ec..28601d10 100644 --- a/Test/SimpleTemplateTest.php +++ b/Test/SimpleTemplateTest.php @@ -23,7 +23,7 @@ class SimpleTemplateTest extends \PHPUnit\Framework\TestCase * * @return void */ - protected function tearDown() + protected function tearDown(): void { } diff --git a/Test/StringObjectTest.php b/Test/StringObjectTest.php index 1eb1c16d..78c1239d 100644 --- a/Test/StringObjectTest.php +++ b/Test/StringObjectTest.php @@ -29,7 +29,7 @@ class StringObjectTest extends TestCase * * @return void */ - protected function tearDown() + protected function tearDown(): void { } diff --git a/Test/Utf8StringTest.php b/Test/Utf8StringTest.php index 63fdd6ce..6127725f 100644 --- a/Test/Utf8StringTest.php +++ b/Test/Utf8StringTest.php @@ -29,7 +29,7 @@ class Utf8StringTest extends \PHPUnit\Framework\TestCase * * @return void */ - protected function setUp() + protected function setUp(): void { } @@ -39,7 +39,7 @@ protected function setUp() * * @return void */ - protected function tearDown() + protected function tearDown(): void { } From e0a58f89cdcbcede92e7fda16b9408188880f90f Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 28 Apr 2019 14:01:00 +0800 Subject: [PATCH 08/27] Use strict and fix tests --- Mbstring.php | 2 +- SimpleTemplate.php | 2 +- Str.php | 2 +- StringHelper.php | 2 +- StringInflector.php | 2 +- StringNormalise.php | 2 +- StringObject.php | 2 +- Test/InflectorTest.php | 2 +- Test/MbstringTest.php | 2 +- Test/NormaliseTest.php | 2 +- Test/SimpleTemplateTest.php | 2 +- Test/StrTest.php | 2 +- Test/StringHelperTest.php | 2 +- Test/StringObjectTest.php | 2 +- Test/Utf8StringTest.php | 2 +- Utf8String.php | 2 +- functions.php | 2 +- phputf8/mbstring/core.php | 8 ++++---- phputf8/native/core.php | 2 +- phputf8/ord.php | 2 +- phputf8/str_ireplace.php | 2 +- phputf8/str_pad.php | 2 +- phputf8/str_split.php | 4 ++-- phputf8/strcasecmp.php | 2 +- phputf8/strcspn.php | 2 +- phputf8/stristr.php | 2 +- phputf8/strrev.php | 2 +- phputf8/strspn.php | 2 +- phputf8/substr_replace.php | 2 +- phputf8/trim.php | 2 +- phputf8/ucfirst.php | 2 +- phputf8/ucwords.php | 2 +- phputf8/utf8.php | 2 +- phputf8/utils/ascii.php | 2 +- phputf8/utils/bad.php | 2 +- phputf8/utils/patterns.php | 2 +- phputf8/utils/position.php | 2 +- phputf8/utils/specials.php | 2 +- phputf8/utils/unicode.php | 2 +- phputf8/utils/validation.php | 2 +- 40 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Mbstring.php b/Mbstring.php index a3c87fa3..e37e412b 100644 --- a/Mbstring.php +++ b/Mbstring.php @@ -1,4 +1,4 @@ - Date: Fri, 7 Jun 2019 01:43:19 +0800 Subject: [PATCH 09/27] Add Collection::explode() return Collection #579 --- StringObject.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/StringObject.php b/StringObject.php index 1b97477a..9025bfef 100644 --- a/StringObject.php +++ b/StringObject.php @@ -605,13 +605,6 @@ public function indexOfLast($search) */ public function explode($delimiter, $limit = null) { - // Fix HHVM default explode limit issue - // @see https://github.com/facebook/hhvm/issues/7696 - // @see https://3v4l.org/fllad - if ($limit === null) { - $limit = defined('HHVM_VERSION') ? 0x7FFFFFFF : PHP_INT_MAX; - } - return explode($delimiter, $this->string, $limit); } From d1befa073d56e0bc5d55edae8f228cb27f40b8e7 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Fri, 7 Jun 2019 14:19:41 +0800 Subject: [PATCH 10/27] Fix test --- StringObject.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/StringObject.php b/StringObject.php index 9025bfef..074f7727 100644 --- a/StringObject.php +++ b/StringObject.php @@ -605,6 +605,10 @@ public function indexOfLast($search) */ public function explode($delimiter, $limit = null) { + if ($limit === null) { + return explode($delimiter, $this->string); + } + return explode($delimiter, $this->string, $limit); } From f749dca0501dcdd90c05293631e029caa5c620dc Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 27 Jul 2019 01:11:14 +0800 Subject: [PATCH 11/27] Fix 7.4 test --- Mbstring.php | 2 +- phputf8/utils/validation.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mbstring.php b/Mbstring.php index e37e412b..6e48ede2 100644 --- a/Mbstring.php +++ b/Mbstring.php @@ -617,7 +617,7 @@ public static function isUtf8($str) $len = strlen($str); for ($i = 0; $i < $len; $i++) { - $in = ord($str{$i}); + $in = ord($str[$i]); if ($mState === 0) { // When mState is zero we expect either a US-ASCII character or a diff --git a/phputf8/utils/validation.php b/phputf8/utils/validation.php index c49dd378..13c89ada 100644 --- a/phputf8/utils/validation.php +++ b/phputf8/utils/validation.php @@ -32,7 +32,7 @@ function utf8_is_valid($str) $len = strlen($str); for ($i = 0; $i < $len; $i++) { - $in = ord($str{$i}); + $in = ord($str[$i]); if ($mState == 0) { // When mState is zero we expect either a US-ASCII character or a From f42410f02750662fcf2878c210b1538988318d57 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Fri, 23 Aug 2019 23:32:24 +0800 Subject: [PATCH 12/27] Add strip html tags --- StringObject.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/StringObject.php b/StringObject.php index 074f7727..597d8270 100644 --- a/StringObject.php +++ b/StringObject.php @@ -627,4 +627,20 @@ function ($new) use ($callback) { } ); } + + /** + * clearHtml + * + * @param string|null $allowTags + * + * @return StringObject + * + * @since __DEPLOY_VERSION__ + */ + public function stripHtmlTags(?string $allowTags = null) + { + return $this->cloneInstance(function (self $new) use ($allowTags) { + $new->string = strip_tags($new->string, $allowTags); + }); + } } From 0abc05a9e69f75e489721f699b729faf7612fe35 Mon Sep 17 00:00:00 2001 From: megamount Date: Sun, 20 Oct 2019 17:46:54 +0800 Subject: [PATCH 13/27] Prepare for 3.5.13 release. --- StringObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StringObject.php b/StringObject.php index 597d8270..e3250b26 100644 --- a/StringObject.php +++ b/StringObject.php @@ -635,7 +635,7 @@ function ($new) use ($callback) { * * @return StringObject * - * @since __DEPLOY_VERSION__ + * @since 3.5.13 */ public function stripHtmlTags(?string $allowTags = null) { From c96dd3fe5cb7259527f96892c50df4585639432e Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 26 Oct 2019 23:42:26 +0800 Subject: [PATCH 14/27] Use phpunit 7 to test --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7b69eda5..51256dcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,11 @@ php: - 7.2 - 7.3 +before_install: + - composer global require phpunit/phpunit ^7.0 before_script: - composer update --dev script: - - phpunit --configuration phpunit.travis.xml + - /home/travis/.config/composer/vendor/bin/phpunit --configuration phpunit.travis.xml From b4134de5f8256946cd5afd52709c4238cfb296d2 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 26 Oct 2019 23:53:58 +0800 Subject: [PATCH 15/27] Str::pipe() #654 --- StringObject.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/StringObject.php b/StringObject.php index e3250b26..a90b302e 100644 --- a/StringObject.php +++ b/StringObject.php @@ -628,6 +628,20 @@ function ($new) use ($callback) { ); } + /** + * pipe + * + * @param callable $callback + * + * @return static + * + * @since __DEPLOY_VERSION__ + */ + public function pipe(callable $callback): self + { + return $callback($this); + } + /** * clearHtml * From cf8936945a131509f2c96c99aa4b47922c2ea7bc Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 27 Oct 2019 15:37:03 +0800 Subject: [PATCH 16/27] Some dev use dev-master --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 26753db7..bce2d9b8 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "require-dev": { "windwalker/test": "~3.0", - "windwalker/utilities": "~3.0" + "windwalker/utilities": "dev-master" }, "suggest": { "windwalker/utilities": "Install ~3.0 if you require SimpleTemplate template engine." From 69e9614a896152589022372d5d17fd90d68d550d Mon Sep 17 00:00:00 2001 From: megamount Date: Sun, 27 Oct 2019 15:38:41 +0800 Subject: [PATCH 17/27] Prepare for 3.5.14 release. --- StringObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StringObject.php b/StringObject.php index a90b302e..8f9319aa 100644 --- a/StringObject.php +++ b/StringObject.php @@ -635,7 +635,7 @@ function ($new) use ($callback) { * * @return static * - * @since __DEPLOY_VERSION__ + * @since 3.5.14 */ public function pipe(callable $callback): self { From 04a93df08bd46d43a70945b1989edbaa92d03572 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 8 Feb 2020 15:00:44 +0800 Subject: [PATCH 18/27] Move some ww4 classes to v3 #676 --- StrNormalise.php | 226 ++++++++++++++++++++++++++++++++++++++++++++ StringNormalise.php | 2 + 2 files changed, 228 insertions(+) create mode 100644 StrNormalise.php diff --git a/StrNormalise.php b/StrNormalise.php new file mode 100644 index 00000000..e704b2c8 --- /dev/null +++ b/StrNormalise.php @@ -0,0 +1,226 @@ + Date: Sat, 8 Feb 2020 16:44:37 +0800 Subject: [PATCH 19/27] Prepare for 3.5.17 release. --- StrNormalise.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/StrNormalise.php b/StrNormalise.php index e704b2c8..b140241b 100644 --- a/StrNormalise.php +++ b/StrNormalise.php @@ -4,7 +4,7 @@ * Part of ww4 project. * * @copyright Copyright (C) 2019 __ORGANIZATION__. - * @license __LICENSE__ + * @license LGPL-2.0-or-later */ declare(strict_types=1); @@ -16,7 +16,7 @@ /** * The StrNotmalise class. * - * @since __DEPLOY_VERSION__ + * @since 3.5.17 */ class StrNormalise { From 777756cca434f68dd822409b7a370020df7a5cab Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Tue, 14 Jul 2020 12:53:03 +0800 Subject: [PATCH 20/27] Fix str bracket --- phputf8/ord.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/phputf8/ord.php b/phputf8/ord.php index 9a6ec24b..aa06d053 100644 --- a/phputf8/ord.php +++ b/phputf8/ord.php @@ -27,36 +27,36 @@ function utf8_ord($chr) return $ord0; } - if (!isset($chr{1})) { + if (!isset($chr[1])) { trigger_error('Short sequence - at least 2 bytes expected, only 1 seen'); return false; } - $ord1 = ord($chr{1}); + $ord1 = ord($chr[1]); if ($ord0 >= 192 && $ord0 <= 223) { return ($ord0 - 192) * 64 + ($ord1 - 128); } - if (!isset($chr{2})) { + if (!isset($chr[2])) { trigger_error('Short sequence - at least 3 bytes expected, only 2 seen'); return false; } - $ord2 = ord($chr{2}); + $ord2 = ord($chr[2]); if ($ord0 >= 224 && $ord0 <= 239) { return ($ord0 - 224) * 4096 + ($ord1 - 128) * 64 + ($ord2 - 128); } - if (!isset($chr{3})) { + if (!isset($chr[3])) { trigger_error('Short sequence - at least 4 bytes expected, only 3 seen'); return false; } - $ord3 = ord($chr{3}); + $ord3 = ord($chr[3]); if ($ord0 >= 240 && $ord0 <= 247) { return ($ord0 - 240) * 262144 + ($ord1 - 128) * 4096 @@ -64,12 +64,12 @@ function utf8_ord($chr) + ($ord3 - 128); } - if (!isset($chr{4})) { + if (!isset($chr[4])) { trigger_error('Short sequence - at least 5 bytes expected, only 4 seen'); return false; } - $ord4 = ord($chr{4}); + $ord4 = ord($chr[4]); if ($ord0 >= 248 && $ord0 <= 251) { return ($ord0 - 248) * 16777216 + ($ord1 - 128) * 262144 @@ -78,7 +78,7 @@ function utf8_ord($chr) + ($ord4 - 128); } - if (!isset($chr{5})) { + if (!isset($chr[5])) { trigger_error('Short sequence - at least 6 bytes expected, only 5 seen'); return false; @@ -89,7 +89,7 @@ function utf8_ord($chr) + ($ord2 - 128) * 262144 + ($ord3 - 128) * 4096 + ($ord4 - 128) * 64 - + (ord($chr{5}) - 128); + + (ord($chr[5]) - 128); } if ($ord0 >= 254 && $ord0 <= 255) { From 4a538abc09634f8e94ac78c23f4043c5627d06e6 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Fri, 7 Aug 2020 11:24:32 +0800 Subject: [PATCH 21/27] Fix for 7.4 --- phputf8/utils/bad.php | 2 +- phputf8/utils/unicode.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phputf8/utils/bad.php b/phputf8/utils/bad.php index 73cb137c..dcece329 100644 --- a/phputf8/utils/bad.php +++ b/phputf8/utils/bad.php @@ -254,7 +254,7 @@ function utf8_bad_identify($str, &$i) $len = strlen($str); for ($i = 0; $i < $len; $i++) { - $in = ord($str{$i}); + $in = ord($str[$i]); if ($mState == 0) { // When mState is zero we expect either a US-ASCII character or a diff --git a/phputf8/utils/unicode.php b/phputf8/utils/unicode.php index 123d003e..fc2611ea 100644 --- a/phputf8/utils/unicode.php +++ b/phputf8/utils/unicode.php @@ -39,7 +39,7 @@ function utf8_to_unicode($str) $len = strlen($str); for ($i = 0; $i < $len; $i++) { - $in = ord($str{$i}); + $in = ord($str[$i]); if ($mState == 0) { // When mState is zero we expect either a US-ASCII character or a From 1a3a0c928204c465347bb3dc128509a91062581d Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 18 Oct 2020 17:54:35 +0800 Subject: [PATCH 22/27] php8 --- phputf8/utf8.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phputf8/utf8.php b/phputf8/utf8.php index 314ff341..7303de82 100644 --- a/phputf8/utf8.php +++ b/phputf8/utf8.php @@ -23,7 +23,7 @@ * encoding */ if (extension_loaded('mbstring')) { - if (ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING) { + if (defined('MB_OVERLOAD_STRING') && ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING) { trigger_error('String functions are overloaded by mbstring', E_USER_ERROR); } mb_internal_encoding('UTF-8'); From 042d47599a4b3b043b8d77fe6e017d1d6e1fc451 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 18 Oct 2020 18:15:43 +0800 Subject: [PATCH 23/27] php8 --- StringInflector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StringInflector.php b/StringInflector.php index c40fabaf..7fe91462 100644 --- a/StringInflector.php +++ b/StringInflector.php @@ -193,7 +193,7 @@ private function matchRegexRule($word, $ruleType) // Cycle through the regex rules. foreach ($this->rules[$ruleType] as $regex => $replacement) { $matches = 0; - $matchedWord = preg_replace($regex, $replacement, $word, -1, $matches); + $matchedWord = preg_replace($regex, $replacement, (string) $word, -1, $matches); if ($matches > 0) { return $matchedWord; From 1e2dd9b1d53a5a765f0475fe4f52e6fcbfa4fcc3 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Tue, 12 Jan 2021 17:05:23 +0800 Subject: [PATCH 24/27] (string) --- SimpleTemplate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimpleTemplate.php b/SimpleTemplate.php index fe87949a..4d98a4ad 100644 --- a/SimpleTemplate.php +++ b/SimpleTemplate.php @@ -49,7 +49,7 @@ function ($match) use ($data) { return $return; } }, - $string + (string) $string ); } } From 744273a0a091cd9f6411c3b5aa99042e01c64a8d Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 29 Jan 2022 22:07:14 +0800 Subject: [PATCH 25/27] php8.1 --- StringObject.php | 6 ++++++ Test/StringObjectTest.php | 3 +++ 2 files changed, 9 insertions(+) diff --git a/StringObject.php b/StringObject.php index 8f9319aa..e6958414 100644 --- a/StringObject.php +++ b/StringObject.php @@ -194,6 +194,7 @@ protected function callProxy($class, $method, array $args) * Traversable * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayIterator($this->chop()); @@ -214,6 +215,7 @@ public function getIterator() * The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { $offset = $offset >= 0 ? $offset : (int) abs($offset) - 1; @@ -228,6 +230,7 @@ public function offsetExists($offset) * * @return string Can return all value types. */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->getChar($offset); @@ -248,6 +251,7 @@ public function offsetGet($offset) * @return void * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $string) { $this->string = Mbstring::substrReplace($this->string, $string, $offset, 1, $this->encoding); @@ -265,6 +269,7 @@ public function offsetSet($offset, $string) * @return void * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { if ($this->length() < abs($offset)) { @@ -284,6 +289,7 @@ public function offsetUnset($offset) * The return value is cast to an integer. * @since 5.1.0 */ + #[\ReturnTypeWillChange] public function count() { return $this->length(); diff --git a/Test/StringObjectTest.php b/Test/StringObjectTest.php index 3f504bf4..2a7648b1 100644 --- a/Test/StringObjectTest.php +++ b/Test/StringObjectTest.php @@ -158,6 +158,7 @@ public function testOffsetGet($offset, $expected) * * @return array */ + #[\ReturnTypeWillChange] public function offsetGetProvider() { return [ @@ -196,6 +197,7 @@ public function testOffsetSet($string, $replace, $offset, $expected) * * @return array */ + #[\ReturnTypeWillChange] public function offsetSetProvider() { return [ @@ -230,6 +232,7 @@ public function testOffsetUnset($string, $offset, $expected) * * @return array */ + #[\ReturnTypeWillChange] public function offsetUnsetProvider() { return [ From 98266af15de374ab1c307df59bba1e13c88cc64d Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 8 Oct 2022 00:27:09 +0800 Subject: [PATCH 26/27] Test with laravel 9.* --- Test/StringObjectTest.php | 2 +- functions.php | 49 ++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/Test/StringObjectTest.php b/Test/StringObjectTest.php index 2a7648b1..0448bad7 100644 --- a/Test/StringObjectTest.php +++ b/Test/StringObjectTest.php @@ -40,7 +40,7 @@ protected function tearDown(): void */ public function testFunctionCreate() { - $s = str('白日依山盡', StringObject::ENCODING_US_ASCII); + $s = \Windwalker\str('白日依山盡', StringObject::ENCODING_US_ASCII); self::assertInstanceOf(StringObject::class, $s); self::assertEquals('白日依山盡', $s->getString()); diff --git a/functions.php b/functions.php index f46ff655..2c4ea37a 100644 --- a/functions.php +++ b/functions.php @@ -6,19 +6,42 @@ * @license Please see LICENSE file. */ -use Windwalker\String\StringObject; +namespace { -if (!function_exists('str')) { - /** - * str - * - * @param string $string - * @param null|string $encoding - * - * @return StringObject - */ - function str($string = '', $encoding = StringObject::ENCODING_UTF8) - { - return new StringObject($string, $encoding); + use Windwalker\String\StringObject; + + if (!function_exists('str')) { + /** + * str + * + * @param string $string + * @param null|string $encoding + * + * @return StringObject + */ + function str($string = '', $encoding = StringObject::ENCODING_UTF8) + { + return new StringObject($string, $encoding); + } + } +} + +namespace Windwalker { + + use Windwalker\String\StringObject; + + if (!function_exists('\Windwalker\str')) { + /** + * str + * + * @param string $string + * @param null|string $encoding + * + * @return StringObject + */ + function str($string = '', $encoding = StringObject::ENCODING_UTF8) + { + return new StringObject($string, $encoding); + } } } From 45cb0ea7c2102742f1b59b55e8f2631b21d1bdab Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 6 Mar 2023 15:01:30 +1300 Subject: [PATCH 27/27] Correct namespace --- Test/NormaliseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/NormaliseTest.php b/Test/NormaliseTest.php index 6b733583..1740cd11 100644 --- a/Test/NormaliseTest.php +++ b/Test/NormaliseTest.php @@ -6,7 +6,7 @@ // phpcs:disable -namespace Windwalker\String\Tests; +namespace Windwalker\String\Test; use Windwalker\String\StringNormalise;