/** * Returns all records that match the criteria. * * @param string $table The table that will be accessed and written. * @param Condition|null $criteria The criteria that will filter the records. * @param array $options The list of options that will help with finding the records. * @return array[] Multiple records from the table that match the criteria. */ public function findAll($table, Condition $criteria = null, array $options = []) { $limit = null; if (isset($options['limit'])) { $limit = $options['limit']; } if ($limit !== null && $limit < 1 || !isset($this->tables[$table])) { return []; } // The code below is included for increased efficiency. // It will check to see if a primary key is being compared. if ($criteria !== null && $criteria->getOperator() === '=' && $criteria->getLeft() === $this->primaryKey) { $primaryKeyValue = $criteria->getRight(); if (isset($this->tables[$table][$primaryKeyValue])) { return [$primaryKeyValue => $this->tables[$table][$primaryKeyValue]]; } return []; } $count = 0; $records = []; foreach ($this->tables[$table] as $primaryKeyValue => $record) { if ($limit !== null && $count >= $limit) { // We have reached our limit! break; } if ($this->isRecordMatchingCondition($primaryKeyValue, $record, $criteria)) { $records[$primaryKeyValue] = $record; $count++; } } return $records; }