mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Fixed flatten()
failed, bacause INF
is float
. (#1454)
* 强制int参数,默认INF并不会有用,且会报错 * Added test cases. * Update CHANGELOG.md Co-authored-by: Donjan <Donjan@cqbaobao.cn> Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
893415c9c9
commit
de69980836
@ -3,6 +3,7 @@
|
||||
## Fixed
|
||||
|
||||
- [#1449](https://github.com/hyperf/hyperf/pull/1449) Fixed memory overflow for high cardinality request path.
|
||||
- [#1454](https://github.com/hyperf/hyperf/pull/1454) Fixed `flatten()` failed, bacause `INF` is `float`.
|
||||
|
||||
# v1.1.21 - 2020-03-19
|
||||
|
||||
|
@ -437,8 +437,9 @@ class Collection extends BaseCollection implements CompressInterface
|
||||
|
||||
/**
|
||||
* Get a flattened array of the items in the collection.
|
||||
* @param float|int $depth
|
||||
*/
|
||||
public function flatten(int $depth = INF): BaseCollection
|
||||
public function flatten($depth = INF): BaseCollection
|
||||
{
|
||||
return $this->toBase()->flatten($depth);
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ class Arr
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional array into a single level.
|
||||
* @param mixed $depth
|
||||
* @param float|int $depth
|
||||
*/
|
||||
public static function flatten(array $array, $depth = INF): array
|
||||
{
|
||||
|
@ -557,8 +557,9 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
|
||||
|
||||
/**
|
||||
* Get a flattened array of the items in the collection.
|
||||
* @param float|int $depth
|
||||
*/
|
||||
public function flatten(int $depth = INF): self
|
||||
public function flatten($depth = INF): self
|
||||
{
|
||||
return new static(Arr::flatten($this->items, $depth));
|
||||
}
|
||||
|
@ -44,4 +44,18 @@ class CollectionTest extends TestCase
|
||||
$res = $col->random(1);
|
||||
$this->assertTrue($res instanceof Collection);
|
||||
}
|
||||
|
||||
public function testFlatten()
|
||||
{
|
||||
$collection = new Collection([
|
||||
'item' => [
|
||||
'name' => 'Hyperf',
|
||||
],
|
||||
'it' => [
|
||||
'id' => $uuid = uniqid(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(['Hyperf', $uuid], $collection->flatten()->toArray());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user