db = $database; $this->logger = $logger; $this->factory = $factory; } /** * @param array $condition * @param array $params * @return BaseCollection * @throws Exception */ protected function _select(array $condition, array $params = []): BaseCollection { $rows = $this->db->selectToArray(static::$table_name, [], $condition, $params); $Entities = new BaseCollection(); foreach ($rows as $fields) { $Entities[] = $this->factory->createFromTableRow($fields); } return $Entities; } /** * @param array $condition * @param array $params * @return BaseEntity * @throws NotFoundException */ protected function _selectOne(array $condition, array $params = []): BaseEntity { $fields = $this->db->selectFirst(static::$table_name, [], $condition, $params); if (!$this->db->isResult($fields)) { throw new NotFoundException(); } return $this->factory->createFromTableRow($fields); } /** * @param array $condition * @param array $params * @return int * @throws Exception */ public function count(array $condition, array $params = []): int { return $this->db->count(static::$table_name, $condition, $params); } /** * @param array $condition * @return bool * @throws Exception */ public function exists(array $condition): bool { return $this->db->exists(static::$table_name, $condition); } }