/home/techb158/immovalet.com/vendor/doctrine/dbal/src/Cache
Edit: /home/techb158/immovalet.com/vendor/doctrine/dbal/src/Cache/CachingResult.php (3844B)
>|null */
private $data;
/**
* @param string $cacheKey
* @param string $realKey
* @param int $lifetime
*/
public function __construct(Result $result, Cache $cache, $cacheKey, $realKey, $lifetime)
{
$this->result = $result;
$this->cache = $cache;
$this->cacheKey = $cacheKey;
$this->realKey = $realKey;
$this->lifetime = $lifetime;
}
/**
* {@inheritdoc}
*/
public function fetchNumeric()
{
$row = $this->fetch();
if ($row === false) {
return false;
}
return array_values($row);
}
/**
* {@inheritdoc}
*/
public function fetchAssociative()
{
return $this->fetch();
}
/**
* {@inheritdoc}
*/
public function fetchOne()
{
return FetchUtils::fetchOne($this);
}
/**
* {@inheritdoc}
*/
public function fetchAllNumeric(): array
{
return array_map('array_values', $this->fetchAllAssociative());
}
/**
* {@inheritdoc}
*/
public function fetchAllAssociative(): array
{
$data = $this->result->fetchAllAssociative();
$this->store($data);
return $data;
}
/**
* {@inheritdoc}
*/
public function fetchFirstColumn(): array
{
return FetchUtils::fetchFirstColumn($this);
}
public function rowCount(): int
{
return $this->result->rowCount();
}
public function columnCount(): int
{
return $this->result->columnCount();
}
public function free(): void
{
$this->data = null;
}
/**
* @return array
|false
*
* @throws Exception
*/
private function fetch()
{
if ($this->data === null) {
$this->data = [];
}
$row = $this->result->fetchAssociative();
if ($row !== false) {
$this->data[] = $row;
return $row;
}
$this->saveToCache();
return false;
}
/**
* @param array> $data
*/
private function store(array $data): void
{
$this->data = $data;
$this->saveToCache();
}
private function saveToCache(): void
{
if ($this->data === null) {
return;
}
$data = $this->cache->fetch($this->cacheKey);
if ($data === false) {
$data = [];
}
$data[$this->realKey] = $this->data;
$this->cache->save($this->cacheKey, $data, $this->lifetime);
}
}