/** * 全てのレコードを連想配列として返す * 有効期限切れのレコードを除外したい場合は事前にgc()しておくこと * * @param string $prefix * @param array $orderBy * @param int $limit * @param int $offset * @param bool $getRaw * @return array */ public function getAll($prefix = null, array $orderBy = null, $limit = null, $offset = null, $getRaw = false) { $query = self::Q_GETALL; if ($prefix !== null) { $query .= ' WHERE ' . self::C_KEY_BEGINS; } $query .= $this->buildOrderBy($orderBy); $query .= $this->buildLimit($limit, $offset); $stmt = $this->_prepare($query, true); if ($prefix !== null) { $this->bindValueForPrefixSearch($stmt, $prefix); } $stmt->execute(); $values = array(); if ($getRaw) { $stmt->setFetchMode(PDO::FETCH_CLASS, 'P2KeyValueStore_Result'); while ($row = $stmt->fetch()) { $values[$this->_codec->decodeKey($row->arkey)] = $row; } } else { $stmt->setFetchMode(PDO::FETCH_INTO, $this->_sharedResult); while ($row = $stmt->fetch()) { $value = $this->_codec->decodeValue($row->value); $values[$this->_codec->decodeKey($row->arkey)] = $value; } } return $values; }
/** * 結果セットを連想配列に変換する * * @param P2KeyValueStore_Codec_Interface $codec * @return array */ public function toArray(P2KeyValueStore_Codec_Interface $codec = null) { if ($codc === null) { $key = $this->arkey; $value = $this->value; } else { $key = $codec->decodeKey($this->arkey); $value = $codec->decodeValue($this->value); } return array('id' => (int) $this->id, 'key' => $key, 'value' => $value, 'mtime' => (int) $this->mtime, 'order' => (int) $this->sort_order); }