Add lazy collection for members
This commit is contained in:
parent
7b9cad7580
commit
6e04bc2de6
|
@ -26,6 +26,13 @@ class Group implements Arrayable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function members(): MemberCollection {
|
public function members(): MemberCollection {
|
||||||
|
$members = Nami::membersOf($this->id);
|
||||||
|
|
||||||
|
return MemberCollection::make(function() use ($members) {
|
||||||
|
foreach ($members as $member) {
|
||||||
|
yield $this->member($member['id']);
|
||||||
|
}
|
||||||
|
});
|
||||||
return new MemberCollection(Nami::membersOf($this->id)->map(function($member) {
|
return new MemberCollection(Nami::membersOf($this->id)->map(function($member) {
|
||||||
return $this->member($member['id']);
|
return $this->member($member['id']);
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami;
|
namespace Zoomyboy\LaravelNami;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\LazyCollection;
|
||||||
|
|
||||||
class MemberCollection extends Collection {
|
class MemberCollection extends LazyCollection {
|
||||||
|
|
||||||
public static function fromOverview($items) {
|
public static function fromOverview($items) {
|
||||||
$self = new self($items);
|
$self = new self($items);
|
||||||
|
|
|
@ -100,9 +100,10 @@ class PullMemberTest extends TestCase
|
||||||
|
|
||||||
Nami::login();
|
Nami::login();
|
||||||
|
|
||||||
$member = Nami::group(103)->members();
|
$members = Nami::group(103)->members();
|
||||||
$this->assertSame($values[0], $member->get(0)->toArray()[$key]);
|
foreach ($members as $i => $m) {
|
||||||
$this->assertSame($values[1], $member->get(1)->toArray()[$key]);
|
$this->assertSame($values[$i], $m->toArray()[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
Http::assertSentCount(6);
|
Http::assertSentCount(6);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue