Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation fixes #243

Merged
merged 1 commit into from
Jun 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/Doctrine/DBAL/Cache/ArrayStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,29 @@

class ArrayStatement implements \IteratorAggregate, ResultStatement
{
/**
* @var array
*/
private $data;

/**
* @var integer
*/
private $columnCount = 0;

/**
* @var integer
*/
private $num = 0;

/**
* @var integer
*/
private $defaultFetchMode = PDO::FETCH_BOTH;

/**
* @param array $data
*/
public function __construct(array $data)
{
$this->data = $data;
Expand All @@ -37,31 +55,49 @@ public function __construct(array $data)
}
}

/**
* {@inheritdoc}
*/
public function closeCursor()
{
unset ($this->data);
}

/**
* {@inheritdoc}
*/
public function columnCount()
{
return $this->columnCount;
}

/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{
if ($arg2 !== null || $arg3 !== null) {
throw new \InvalidArgumentException("Caching layer does not support 2nd/3rd argument to setFetchMode()");
}

$this->defaultFetchMode = $fetchMode;

return true;
}

/**
* {@inheritdoc}
*/
public function getIterator()
{
$data = $this->fetchAll();

return new \ArrayIterator($data);
}

/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null)
{
if (isset($this->data[$this->num])) {
Expand All @@ -79,25 +115,34 @@ public function fetch($fetchMode = null)
throw new \InvalidArgumentException("Invalid fetch-style given for fetching result.");
}
}

return false;
}

/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null)
{
$rows = array();
while ($row = $this->fetch($fetchMode)) {
$rows[] = $row;
}

return $rows;
}

/**
* {@inheritdoc}
*/
public function fetchColumn($columnIndex = 0)
{
$row = $this->fetch(PDO::FETCH_NUM);
if (!isset($row[$columnIndex])) {
// TODO: verify this is correct behavior
return false;
}

return $row[$columnIndex];
}
}
6 changes: 6 additions & 0 deletions lib/Doctrine/DBAL/Cache/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@
*/
class CacheException extends \Doctrine\DBAL\DBALException
{
/**
* @return \Doctrine\DBAL\Cache\CacheException
*/
static public function noCacheKey()
{
return new self("No cache key was set.");
}

/**
* @return \Doctrine\DBAL\Cache\CacheException
*/
static public function noResultDriverConfigured()
{
return new self("Trying to cache a query but no result driver is configured.");
Expand Down
42 changes: 26 additions & 16 deletions lib/Doctrine/DBAL/Cache/QueryCacheProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@
class QueryCacheProfile
{
/**
* @var Cache
* @var \Doctrine\Common\Cache\Cache|null
*/
private $resultCacheDriver;

/**
* @var int
* @var integer
*/
private $lifetime = 0;

/**
* @var string
* @var string|null
*/
private $cacheKey;

/**
* @param int $lifetime
* @param string $cacheKey
* @param Cache $resultCache
* @param integer $lifetime
* @param string|null $cacheKey
* @param \Doctrine\Common\Cache\Cache|null $resultCache
*/
public function __construct($lifetime = 0, $cacheKey = null, Cache $resultCache = null)
{
Expand All @@ -56,15 +58,15 @@ public function __construct($lifetime = 0, $cacheKey = null, Cache $resultCache
}

/**
* @return Cache
* @return \Doctrine\Common\Cache\Cache|null
*/
public function getResultCacheDriver()
{
return $this->resultCacheDriver;
}

/**
* @return int
* @return integer
*/
public function getLifetime()
{
Expand All @@ -73,21 +75,25 @@ public function getLifetime()

/**
* @return string
*
* @throws \Doctrine\DBAL\Cache\CacheException
*/
public function getCacheKey()
{
if ($this->cacheKey === null) {
throw CacheException::noCacheKey();
}

return $this->cacheKey;
}

/**
* Generate the real cache key from query, params and types.
* Generates the real cache key from query, params and types.
*
* @param string $query
* @param array $params
* @param array $types
* @param array $params
* @param array $types
*
* @return array
*/
public function generateCacheKeys($query, $params, $types)
Expand All @@ -99,12 +105,14 @@ public function generateCacheKeys($query, $params, $types)
} else {
$cacheKey = $this->cacheKey;
}

return array($cacheKey, $realCacheKey);
}

/**
* @param Cache $cache
* @return QueryCacheProfile
* @param \Doctrine\Common\Cache\Cache $cache
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/
public function setResultCacheDriver(Cache $cache)
{
Expand All @@ -113,16 +121,18 @@ public function setResultCacheDriver(Cache $cache)

/**
* @param string|null $cacheKey
* @return QueryCacheProfile
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/
public function setCacheKey($cacheKey)
{
return new QueryCacheProfile($this->lifetime, $cacheKey, $this->resultCacheDriver);
}

/**
* @param int $lifetime
* @return QueryCacheProfile
* @param integer $lifetime
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/
public function setLifetime($lifetime)
{
Expand Down
Loading