Skip to content

Commit

Permalink
added strict mode on rowcollection->filter()
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 2, 2015
1 parent 165a66b commit b39b015
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/RowCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,23 @@ public function add($rows)
/**
* Filter the rows by a value.
*
* @param string $name The value name
* @param mixed $value The value to filter
* @param bool $first Set true to return only the first row found
* @param string $name The value name
* @param mixed $value The value to filter
* @param bool $strict Strict mode
*
* @return null|RowInterface The rows found or null if no value is found and $first parameter is true
* @return RowInterface The rows found
*/
public function filter($name, $value, $first = false)
public function filter($name, $value, $strict = true)
{
$rows = [];

foreach ($this->rows as $row) {
if (($row->$name === $value) || (is_array($value) && in_array($row->$name, $value, true))) {
if ($first === true) {
return $row;
}

if (($row->$name === $value) || (!$strict && $row->$name == $value) || (is_array($value) && in_array($row->$name, $value, $strict))) {
$rows[] = $row;
}
}

return $first ? null : $this->entity->createCollection($rows);
return $this->entity->createCollection($rows);
}

/**
Expand Down

0 comments on commit b39b015

Please sign in to comment.