-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagination Iterator with params #516
Conversation
$strategy = new $strategyClass($this, $this->resourcesKey(), AbstractStrategy::DEFAULT_PAGE_SIZE); | ||
return new PaginationIterator($strategy); | ||
$strategy = new $strategyClass($this->resourcesKey(), AbstractStrategy::DEFAULT_PAGE_SIZE); | ||
return new PaginationIterator($this, $strategy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of passing $this
for the strategy to run findAll()
duplicated in every strategy inside getPage()
, extract it in the Iterator as a function for the strategy to run (see below).
$this->page = array_merge($this->page, $this->strategy->getPage()); | ||
$pageFn = function ($params = []) { | ||
return $this->clientList->findAll($params); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more DRY, so adding params and later maybe making the method dynamic (findAll, find, active, etc
) in one place only instead of each Strategy.
d55dcf3
to
13bcecd
Compare
* @var string The response key where the data is returned | ||
*/ | ||
protected $resourcesKey; | ||
protected $pageSize; | ||
|
||
public function __construct($clientList, $resourcesKey, $pageSize = self::DEFAULT_PAGE_SIZE) | ||
public function __construct($resourcesKey, $pageSize = self::DEFAULT_PAGE_SIZE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the Strategies are more cohesive.
13bcecd
to
32ae8bf
Compare
It's now possible to call the iterator with params as such:
I will update the README in the next card, as I'll probably start the upgrade guide then too.