Skip to content

Commit

Permalink
Arrays 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed May 9, 2022
1 parent acfdeba commit d2225ff
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 77 deletions.
158 changes: 81 additions & 77 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<a name="4.1.0"></a>
# [4.1.0](https://github.com/glowyphp/arrays) (2022-05-09)
* Added createFromQueryString() method

<a name="4.0.0"></a>
# [4.0.0](https://github.com/glowyphp/arrays) (2021-12-23)
* Released under Glowy PHP Organization.
Expand All @@ -6,60 +10,60 @@

<a name="3.1.0"></a>
# [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

<a name="3.0.5"></a>
# [3.0.5](https://github.com/glowyphp/arrays) (2021-08-02)
* fix except() method.
* Fixed except() method.

<a name="3.0.4"></a>
# [3.0.4](https://github.com/glowyphp/arrays) (2021-07-09)
* fix PHPstan tests
* Fixed PHPstan tests

<a name="3.0.3"></a>
# [3.0.3](https://github.com/glowyphp/arrays) (2021-07-09)
* fix delete() method and improve tests
* Fixed delete() method and improve tests

<a name="3.0.2"></a>
# [3.0.2](https://github.com/glowyphp/arrays) (2021-02-19)
* fix dependencies.
* Fixed dependencies.

<a name="3.0.1"></a>
# [3.0.1](https://github.com/glowyphp/arrays) (2021-02-18)
* fix where() method.
* Fixed where() method.

<a name="3.0.0"></a>
# [3.0.0](https://github.com/glowyphp/arrays) (2021-02-18)
* move to PHP 7.4

<a name="2.2.0"></a>
# [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.

<a name="2.1.0"></a>
# [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;
Expand All @@ -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:
```
Expand All @@ -87,69 +91,69 @@
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

* USE sortBy() INSTEAD OF sortBySubkey() method.

<a name="1.3.0"></a>
# [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.

<a name="1.2.0"></a>
# [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.


<a name="1.1.0"></a>
# [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.

<a name="1.0.0"></a>
# [1.0.0](https://github.com/glowyphp/arrays) (2020-10-03)
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
13 changes: 13 additions & 0 deletions src/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
14 changes: 14 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arrays>
*/
function arraysFromQueryString(string $string): Arrays
{
return Arrays::createFromQueryString($string);
}
}

if (! function_exists('arraysWithRange')) {
/**
* Create a new arrayable object with a range of elements.
Expand Down
10 changes: 10 additions & 0 deletions tests/ArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit d2225ff

Please sign in to comment.