Skip to content

Commit ce1f642

Browse files
committed
Merge branch 'master' into 3.2-merge
2 parents 60cc07f + deb522f commit ce1f642

File tree

2 files changed

+469
-2
lines changed

2 files changed

+469
-2
lines changed

src/Fluent.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
namespace Hyperf\Support;
1414

1515
use ArrayAccess;
16+
use ArrayIterator;
1617
use Closure;
1718
use Hyperf\Collection\Arr;
1819
use Hyperf\Contract\Arrayable;
1920
use Hyperf\Contract\Jsonable;
2021
use Hyperf\Macroable\Macroable;
22+
use IteratorAggregate;
2123
use JsonSerializable;
24+
use Traversable;
2225

2326
use function Hyperf\Collection\data_get;
2427
use function Hyperf\Collection\data_set;
@@ -33,10 +36,10 @@
3336
* @implements \Hyperf\Contract\Arrayable<TKey, TValue>
3437
* @implements ArrayAccess<TKey, TValue>
3538
*/
36-
class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
39+
class Fluent implements ArrayAccess, Arrayable, IteratorAggregate, Jsonable, JsonSerializable
3740
{
3841
use Traits\InteractsWithData;
39-
use Macroable{
42+
use Macroable {
4043
__call as macroCall;
4144
}
4245

@@ -227,6 +230,26 @@ public function getAttributes()
227230
return $this->attributes;
228231
}
229232

233+
/**
234+
* Determine if the fluent instance is empty.
235+
*
236+
* @return bool
237+
*/
238+
public function isEmpty()
239+
{
240+
return empty($this->attributes);
241+
}
242+
243+
/**
244+
* Determine if the fluent instance is not empty.
245+
*
246+
* @return bool
247+
*/
248+
public function isNotEmpty()
249+
{
250+
return ! $this->isEmpty();
251+
}
252+
230253
/**
231254
* Convert the fluent instance to an array.
232255
*
@@ -297,6 +320,16 @@ public function offsetUnset(mixed $offset): void
297320
unset($this->attributes[$offset]);
298321
}
299322

323+
/**
324+
* Get an iterator for the attributes.
325+
*
326+
* @return ArrayIterator<TKey, TValue>
327+
*/
328+
public function getIterator(): Traversable
329+
{
330+
return new ArrayIterator($this->attributes);
331+
}
332+
300333
/**
301334
* Get data from the fluent instance.
302335
*

0 commit comments

Comments
 (0)