From d2225ff1da06dd12cc3b1bb8545e9eb8d0ae3670 Mon Sep 17 00:00:00 2001 From: Sergey Romanenko Date: Mon, 9 May 2022 16:21:13 +0300 Subject: [PATCH] Arrays 4.1.0 --- CHANGELOG.md | 158 ++++++++++++++++++++++--------------------- composer.json | 6 ++ src/Arrays.php | 13 ++++ src/helpers.php | 14 ++++ tests/ArraysTest.php | 10 +++ 5 files changed, 124 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38732a2..f332888 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ + +# [4.1.0](https://github.com/glowyphp/arrays) (2022-05-09) +* Added createFromQueryString() method + # [4.0.0](https://github.com/glowyphp/arrays) (2021-12-23) * Released under Glowy PHP Organization. @@ -6,27 +10,27 @@ # [3.1.0](https://github.com/glowyphp/arrays) (2021-10-26) -* use `getArray` for every methods and set default items value = null +* Use `getArray` for every methods and set default items value = null # [3.0.5](https://github.com/glowyphp/arrays) (2021-08-02) -* fix except() method. +* Fixed except() method. # [3.0.4](https://github.com/glowyphp/arrays) (2021-07-09) -* fix PHPstan tests +* Fixed PHPstan tests # [3.0.3](https://github.com/glowyphp/arrays) (2021-07-09) -* fix delete() method and improve tests +* Fixed delete() method and improve tests # [3.0.2](https://github.com/glowyphp/arrays) (2021-02-19) -* fix dependencies. +* Fixed dependencies. # [3.0.1](https://github.com/glowyphp/arrays) (2021-02-18) -* fix where() method. +* Fixed where() method. # [3.0.0](https://github.com/glowyphp/arrays) (2021-02-18) @@ -34,32 +38,32 @@ # [2.2.0](https://github.com/glowyphp/arrays) (2020-12-10) -* add whereIn() method. -* add whereNotIn() method. -* add whereBetween() method. -* add whereNotBetween() method. -* add whereLess() method. -* add whereLessOrEqual() method. -* add whereGreater() method. -* add whereGreaterOrEqual() method. -* add whereContains() method. -* add whereNotContains() method. -* add whereEqual() method. -* add whereNotEqual() method. -* add whereStartsWith() method. -* add whereEndsWith() method. -* add whereNewer() method. -* add whereOlder() method. -* add whereRegexp() method. -* add whereNotRegexp() method. -* add sortByDesc() method. -* and sortByAsc() method. -* and skip() method. -* improve sortBy() method. +* Added whereIn() method. +* Added whereNotIn() method. +* Added whereBetween() method. +* Added whereNotBetween() method. +* Added whereLess() method. +* Added whereLessOrEqual() method. +* Added whereGreater() method. +* Added whereGreaterOrEqual() method. +* Added whereContains() method. +* Added whereNotContains() method. +* Added whereEqual() method. +* Added whereNotEqual() method. +* Added whereStartsWith() method. +* Added whereEndsWith() method. +* Added whereNewer() method. +* Added whereOlder() method. +* Added whereRegexp() method. +* Added whereNotRegexp() method. +* Added sortByDesc() method. +* Added sortByAsc() method. +* Added skip() method. +* Improved sortBy() method. # [2.1.0](https://github.com/glowyphp/arrays) (2020-12-05) -* add ability to extend Arrays class with Macros. +* Added ability to extend Arrays class with Macros. ```php use Glowy\Arrays\Arrays; @@ -76,7 +80,7 @@ ``` # [2.0.0](https://github.com/glowyphp/arrays) (2020-12-02) -* add new operators added for where() method. +* Added new operators added for where() method. Supported operators: ``` @@ -87,18 +91,18 @@ ends_with, between, nbetween, older, newer ``` -* fix issue in set() method with null key. -* fix combine() method when two arrays are different. +* Fixed issue in set() method with null key. +* Fixed combine() method when two arrays are different. * rename sortBySubkey() method to sortBy() method. -* improve combine() method. -* improve tests for get() method. -* improve tests for get() method. -* improve tests for sort() method. -* improve tests for first() method. -* improve tests for last() method. -* improve tests for random() method. -* improve tests for sortBy() method. -* improve tests workflow. +* Improved combine() method. +* Improved tests for get() method. +* Improved tests for get() method. +* Improved tests for sort() method. +* Improved tests for first() method. +* Improved tests for last() method. +* Improved tests for random() method. +* Improved tests for sortBy() method. +* Improved tests workflow. ### BREAKING CHANGES @@ -106,50 +110,50 @@ # [1.3.0](https://github.com/glowyphp/arrays) (2020-11-15) -* add where() method. -* add dump() method. -* add dd() method. -* add extract() method. -* add column() method. -* add pipe() method. -* add sum() method. -* add every() method. -* add product() method. +* Added where() method. +* Added dump() method. +* Added dd() method. +* Added extract() method. +* Added column() method. +* Added pipe() method. +* Added sum() method. +* Added every() method. +* Added product() method. * general tests improvements. -* add new requirements for php modules: ext-json and ext-mbstring. +* Added new requirements for php modules: ext-json and ext-mbstring. # [1.2.0](https://github.com/glowyphp/arrays) (2020-11-11) -* add offset() method. -* add limit() method. -* add copy() method. -* add except() method. -* add nth() method. -* add offsetGet() method. -* add offsetSet() method. -* add offsetExists() method. -* add offsetUnset() method. -* add getIterator() method. -* add protected getArray() method. -* add phpstan.neon config file. -* implement ArrayAccess, ArrayIntegrator, Countable, IneratrorAggregate, Traversable. -* improve create() method, add ability to path not only arrays inside. -* improve flush() method - return self instead of void -* improve filter() method - add ability to set $flag, default is ARRAY_FILTER_USE_BOTH -* improve set() method. add ability to set $key as null. -* fix issue for get() method in cace if $key type is int provided. -* fix php doc sesction for all methods. -* fix return result for delete() method if count($keys) === 0 -* fix combine() method error with not accept array|false. -* fix toString() method when result $string is null we should return empty string instead of null. +* Added offset() method. +* Added limit() method. +* Added copy() method. +* Added except() method. +* Added nth() method. +* Added offsetGet() method. +* Added offsetSet() method. +* Added offsetExists() method. +* Added offsetUnset() method. +* Added getIterator() method. +* Added protected getArray() method. +* Added phpstan.neon config file. +* Implemented ArrayAccess, ArrayIntegrator, Countable, IneratrorAggregate, Traversable. +* Improved create() method, add ability to path not only arrays inside. +* Improved flush() method - return self instead of void +* Improved filter() method - add ability to set $flag, default is ARRAY_FILTER_USE_BOTH +* Improved set() method. add ability to set $key as null. +* Fixed issue for get() method in cace if $key type is int provided. +* Fixed php doc sesction for all methods. +* Fixed return result for delete() method if count($keys) === 0 +* Fixed combine() method error with not accept array|false. +* Fixed toString() method when result $string is null we should return empty string instead of null. # [1.1.0](https://github.com/glowyphp/arrays) (2020-10-30) -* add next() method. -* add prev() method. -* add current() method. -* add groupBy() method. +* Added next() method. +* Added prev() method. +* Added current() method. +* Added groupBy() method. # [1.0.0](https://github.com/glowyphp/arrays) (2020-10-03) diff --git a/composer.json b/composer.json index d4c6031..8a04d3f 100644 --- a/composer.json +++ b/composer.json @@ -35,5 +35,11 @@ "pestphp/pest": "^1.21.1", "phpstan/phpstan": "^1.2.0", "symfony/var-dumper": "^5.4.0" + }, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/src/Arrays.php b/src/Arrays.php index 6c43091..60c82dc 100644 --- a/src/Arrays.php +++ b/src/Arrays.php @@ -157,6 +157,19 @@ public static function createFromString(string $string, string $separator): self return new static(explode($separator, $string)); } + /** + * Create a new arrayable object from the given query string. + * + * @param string $string Input queary string. + * + * @return self Returns instance of The Arrays class. + */ + public static function createFromQueryString(string $string): self + { + parse_str($string, $items); + return new static($items); + } + /** * Create a new arrayable object with a range of elements. * diff --git a/src/helpers.php b/src/helpers.php index 5e4931d..4995814 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -52,6 +52,20 @@ function arraysFromString(string $string, string $separator): Arrays } } +if (! function_exists('arraysFromQueryString')) { + /** + * Create a new arrayable object from the given query string. + * + * @param string $string Input query string. + * + * @return Glowy\Arrays\Arrays + */ + function arraysFromQueryString(string $string): Arrays + { + return Arrays::createFromQueryString($string); + } +} + if (! function_exists('arraysWithRange')) { /** * Create a new arrayable object with a range of elements. diff --git a/tests/ArraysTest.php b/tests/ArraysTest.php index 48c60cc..b9b4f7b 100644 --- a/tests/ArraysTest.php +++ b/tests/ArraysTest.php @@ -1492,6 +1492,16 @@ ); }); +test('test createFromQueryString() method', function (): void { + $collection = arraysFromQueryString('foo=bar&baz=qux'); + $collection2 = Arrays::createFromQueryString('foo=bar&baz=qux'); + + $this->assertCount(2, $collection); + $this->assertEquals('bar', $collection->get('foo')); + $this->assertEquals('qux', $collection->get('baz')); + $this->assertEquals($collection, $collection2); +}); + test('test isEmpty() method', function (): void { $this->assertFalse(Arrays::create([1, 2, 3, 4, 5])->isEmpty()); $this->assertTrue(Arrays::create()->isEmpty());