[HaveIBeenPwnedBridge] Add item limit parameter, set default limit to 20 (#1219)

* Add `item_limit` parameter to allow user to control number of item returned by bridge. Suggested by @triatic and @somini (code).
This commit is contained in:
Joseph 2019-07-26 08:47:20 +00:00 committed by Teromene
parent be27bc9250
commit e032705c9a

View file

@ -13,6 +13,11 @@ class HaveIBeenPwnedBridge extends BridgeAbstract {
'Date added to HIBP' => 'dateAdded', 'Date added to HIBP' => 'dateAdded',
), ),
'defaultValue' => 'dateAdded', 'defaultValue' => 'dateAdded',
),
'item_limit' => array(
'name' => 'Limit number of returned items',
'type' => 'number',
'defaultValue' => 20,
) )
)); ));
@ -109,6 +114,12 @@ class HaveIBeenPwnedBridge extends BridgeAbstract {
*/ */
private function createItems() { private function createItems() {
$limit = $this->getInput('item_limit');
if ($limit < 1) {
$limit = 20;
}
foreach ($this->breaches as $breach) { foreach ($this->breaches as $breach) {
$item = array(); $item = array();
@ -118,6 +129,10 @@ class HaveIBeenPwnedBridge extends BridgeAbstract {
$item['content'] = $breach['content']; $item['content'] = $breach['content'];
$this->items[] = $item; $this->items[] = $item;
if (count($this->items) >= $limit) {
break;
}
} }
} }
} }