This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnldap/classes/Kohana/Database/LDAP/Result/Cached.php
2014-07-18 12:35:27 +10:00

79 lines
1.7 KiB
PHP

<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Object used for caching the results of select queries. See [Results](/database/results#select-cached) for usage and examples.
*
* @package Kohana/Database
* @category Query/Result
* @author Deon George
* @copyright (c) 2013 phpLDAPadmin Development Team
* @license http://dev.phpldapadmin.org/license.html
*/
abstract class Kohana_Database_LDAP_Result_Cached extends Database_Result_Cached {
protected $cache_key = NULL;
public function __construct(array $result, $sql, $as_object = NULL)
{
parent::__construct($result, $sql, $as_object);
// Find the number of rows in the result
$this->_total_rows = count($result);
$this->_current_row = key($result);
}
public function __destruct() {
// Cached results do not use resources
}
public function cache_key($key=NULL) {
if (is_null($key))
return $this->cache_key;
$this->cache_key = $key;
}
public function cached() {
return $this;
}
public function current() {
// Return an array of the row
return $this->valid() ? $this->_result[$this->_current_row] : NULL;
}
public function key() {
return current($this->_result)->pk();
}
public function next() {
next($this->_result);
$this->_current_row = key($this->_result);
return $this;
}
public function offsetExists($offset) {
return isset($this->_result[$offset]);
}
public function rewind() {
// We dont index by numbers, so we can just return
reset($this->_result);
$this->_current_row = key($this->_result);
return $this;
}
public function seek($offset) {
if (isset($this->_result[$offset])) {
$this->_current_row = $offset;
return TRUE;
} else {
return FALSE;
}
}
} // End Database_LDAP_Result_Cached
?>