some small refactorings. adding docblocks. creating guard clauses. refactor our some code into methods. no aditional test failures so it looks ok. also added some @todo comments
This commit is contained in:
parent
7af31c0c51
commit
d5cc06e7b8
@ -103,6 +103,8 @@ abstract class Doctrine_Access extends Doctrine_Locator_Injectable implements Ar
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an offsetExists. Alias for contains.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return boolean whether or not this object contains $offset
|
||||
*/
|
||||
@ -113,6 +115,7 @@ abstract class Doctrine_Access extends Doctrine_Locator_Injectable implements Ar
|
||||
|
||||
/**
|
||||
* offsetGet an alias of get()
|
||||
*
|
||||
* @see get, __get
|
||||
* @param mixed $offset
|
||||
* @return mixed
|
||||
|
@ -40,11 +40,24 @@ class Doctrine_AuditLog extends Doctrine_Plugin
|
||||
'pluginTable' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new auditlog_
|
||||
*
|
||||
* @param array $options An array of options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
$this->_options = array_merge($this->_options, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version
|
||||
*
|
||||
* @param Doctrine_Record $record
|
||||
* @param mixed $version
|
||||
* @return array An array with version information
|
||||
*/
|
||||
public function getVersion(Doctrine_Record $record, $version)
|
||||
{
|
||||
$className = $this->_options['className'];
|
||||
@ -65,6 +78,13 @@ class Doctrine_AuditLog extends Doctrine_Plugin
|
||||
|
||||
return $q->execute($values, Doctrine::HYDRATE_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* buildDefinition for a table
|
||||
*
|
||||
* @param Doctrine_Table $table
|
||||
* @return boolean true on success otherwise false.
|
||||
*/
|
||||
public function buildDefinition(Doctrine_Table $table)
|
||||
{
|
||||
$this->_options['className'] = str_replace('%CLASS%',
|
||||
|
@ -36,12 +36,12 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
* @var array $_options an array of general caching options
|
||||
*/
|
||||
protected $_options = array('size' => 1000,
|
||||
'lifeTime' => 3600,
|
||||
'addStatsPropability' => 0.25,
|
||||
'savePropability' => 0.10,
|
||||
'cleanPropability' => 0.01,
|
||||
'statsFile' => '../data/stats.cache',
|
||||
);
|
||||
'lifeTime' => 3600,
|
||||
'addStatsPropability' => 0.25,
|
||||
'savePropability' => 0.10,
|
||||
'cleanPropability' => 0.01,
|
||||
'statsFile' => '../data/stats.cache',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array $_queries query stack
|
||||
@ -72,19 +72,19 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
public function __construct($driver, $options = array())
|
||||
{
|
||||
if (is_object($driver)) {
|
||||
if ( ! ($driver instanceof Doctrine_Cache_Interface)) {
|
||||
throw new Doctrine_Cache_Exception('Driver should implement Doctrine_Cache_Interface.');
|
||||
}
|
||||
|
||||
$this->_driver = $driver;
|
||||
$this->_driver->setOptions($options);
|
||||
if ( ! ($driver instanceof Doctrine_Cache_Interface)) {
|
||||
throw new Doctrine_Cache_Exception('Driver should implement Doctrine_Cache_Interface.');
|
||||
}
|
||||
|
||||
$this->_driver = $driver;
|
||||
$this->_driver->setOptions($options);
|
||||
} else {
|
||||
$class = 'Doctrine_Cache_' . ucwords(strtolower($driver));
|
||||
|
||||
|
||||
if ( ! class_exists($class)) {
|
||||
throw new Doctrine_Cache_Exception('Cache driver ' . $driver . ' could not be found.');
|
||||
}
|
||||
|
||||
|
||||
$this->_driver = new $class($options);
|
||||
}
|
||||
}
|
||||
@ -168,7 +168,7 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
|
||||
return $this->_queries[$namespace];
|
||||
}
|
||||
|
||||
|
||||
return $this->_queries;
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
$queries = $this->readStats();
|
||||
|
||||
$stats = array();
|
||||
|
||||
|
||||
foreach ($queries as $query) {
|
||||
if (isset($stats[$query])) {
|
||||
$stats[$query]++;
|
||||
@ -244,9 +244,9 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
}
|
||||
}
|
||||
sort($stats);
|
||||
|
||||
|
||||
$i = $this->_options['size'];
|
||||
|
||||
|
||||
while ($i--) {
|
||||
$element = next($stats);
|
||||
$query = key($stats);
|
||||
@ -266,11 +266,11 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
public function readStats()
|
||||
{
|
||||
if ($this->_options['statsFile'] !== false) {
|
||||
$content = file_get_contents($this->_options['statsFile']);
|
||||
|
||||
$e = explode("\n", $content);
|
||||
|
||||
return array_map('unserialize', $e);
|
||||
$content = file_get_contents($this->_options['statsFile']);
|
||||
|
||||
$e = explode("\n", $content);
|
||||
|
||||
return array_map('unserialize', $e);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
@ -288,7 +288,7 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
if ( ! file_exists($this->_options['statsFile'])) {
|
||||
throw new Doctrine_Cache_Exception("Couldn't save cache statistics. Cache statistics file doesn't exists!");
|
||||
}
|
||||
|
||||
|
||||
$rand = (mt_rand() / mt_getrandmax());
|
||||
|
||||
if ($rand <= $this->_options['addStatsPropability']) {
|
||||
@ -312,33 +312,34 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
|
||||
$data = false;
|
||||
// only process SELECT statements
|
||||
if (strtoupper(substr(ltrim($query), 0, 6)) == 'SELECT') {
|
||||
if (strtoupper(substr(ltrim($query), 0, 6)) != 'SELECT') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->add($query, $event->getInvoker()->getName());
|
||||
$this->add($query, $event->getInvoker()->getName());
|
||||
|
||||
$data = $this->_driver->fetch(md5(serialize($query)));
|
||||
$data = $this->_driver->fetch(md5(serialize($query)));
|
||||
|
||||
$this->success = ($data) ? true : false;
|
||||
$this->success = ($data) ? true : false;
|
||||
|
||||
if ( ! $data) {
|
||||
$rand = (mt_rand() / mt_getrandmax());
|
||||
if ( ! $data) {
|
||||
$rand = (mt_rand() / mt_getrandmax());
|
||||
|
||||
if ($rand < $this->_options['savePropability']) {
|
||||
$stmt = $event->getInvoker()->getAdapter()->query($query);
|
||||
if ($rand < $this->_options['savePropability']) {
|
||||
$stmt = $event->getInvoker()->getAdapter()->query($query);
|
||||
|
||||
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
|
||||
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
|
||||
|
||||
$this->success = true;
|
||||
$this->success = true;
|
||||
|
||||
$this->_driver->save(md5(serialize($query)), $data);
|
||||
}
|
||||
}
|
||||
if ($this->success)
|
||||
{
|
||||
$this->_data = $data;
|
||||
return true;
|
||||
$this->_driver->save(md5(serialize($query)), $data);
|
||||
}
|
||||
}
|
||||
if ($this->success)
|
||||
{
|
||||
$this->_data = $data;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -387,36 +388,37 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
|
||||
$data = false;
|
||||
|
||||
// only process SELECT statements
|
||||
if (strtoupper(substr(ltrim($query), 0, 6)) == 'SELECT') {
|
||||
if (strtoupper(substr(ltrim($query), 0, 6)) != 'SELECT') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->add($query, $event->getInvoker()->getDbh()->getName());
|
||||
$this->add($query, $event->getInvoker()->getDbh()->getName());
|
||||
|
||||
$data = $this->_driver->fetch(md5(serialize(array($query, $event->getParams()))));
|
||||
$data = $this->_driver->fetch(md5(serialize(array($query, $event->getParams()))));
|
||||
|
||||
$this->success = ($data) ? true : false;
|
||||
$this->success = ($data) ? true : false;
|
||||
|
||||
if ( ! $data) {
|
||||
$rand = (mt_rand() / mt_getrandmax());
|
||||
if ( ! $data) {
|
||||
$rand = (mt_rand() / mt_getrandmax());
|
||||
|
||||
if ($rand <= $this->_options['savePropability']) {
|
||||
if ($rand <= $this->_options['savePropability']) {
|
||||
|
||||
$stmt = $event->getInvoker()->getStatement();
|
||||
$stmt = $event->getInvoker()->getStatement();
|
||||
|
||||
$stmt->execute($event->getParams());
|
||||
$stmt->execute($event->getParams());
|
||||
|
||||
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
|
||||
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
|
||||
|
||||
$this->success = true;
|
||||
$this->success = true;
|
||||
|
||||
$this->_driver->save(md5(serialize(array($query, $event->getParams()))), $data);
|
||||
}
|
||||
}
|
||||
if ($this->success)
|
||||
{
|
||||
$this->_data = $data;
|
||||
return true;
|
||||
$this->_driver->save(md5(serialize(array($query, $event->getParams()))), $data);
|
||||
}
|
||||
}
|
||||
if ($this->success)
|
||||
{
|
||||
$this->_data = $data;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,8 @@
|
||||
* @package Doctrine
|
||||
* @subpackage Compiler
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpllicense.php LGPL
|
||||
* @link www.phpdoctrine.
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
@ -69,6 +69,8 @@ class Doctrine_Compiler
|
||||
foreach ($it as $file) {
|
||||
$e = explode('.', $file->getFileName());
|
||||
|
||||
//@todo what is a versioning file? do we have these anymore? None
|
||||
//exists in my version of doctrine from svn.
|
||||
// we don't want to require versioning files
|
||||
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
||||
require_once $file->getPathName();
|
||||
@ -132,4 +134,4 @@ class Doctrine_Compiler
|
||||
fwrite($fp, $stripped);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -379,13 +379,14 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
|
||||
throw new Doctrine_Exception('Unknown attribute.');
|
||||
}
|
||||
|
||||
if ( ! isset($this->attributes[$attribute])) {
|
||||
if (isset($this->parent)) {
|
||||
return $this->parent->getAttribute($attribute);
|
||||
}
|
||||
return null;
|
||||
if (isset($this->attributes[$attribute])) {
|
||||
return $this->attributes[$attribute];
|
||||
}
|
||||
return $this->attributes[$attribute];
|
||||
|
||||
if (isset($this->parent)) {
|
||||
return $this->parent->getAttribute($attribute);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,6 +262,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
* setAttribute
|
||||
* sets an attribute
|
||||
*
|
||||
* @todo why check for >= 100? has this any special meaning when creating
|
||||
* attributes?
|
||||
*
|
||||
* @param integer $attribute
|
||||
* @param mixed $value
|
||||
* @return boolean
|
||||
@ -466,13 +469,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
* @throws Doctrine_Connection_Exception if some of the key values was null
|
||||
* @throws Doctrine_Connection_Exception if there were no key fields
|
||||
* @throws PDOException if something fails at PDO level
|
||||
* @return integer number of rows affected
|
||||
* @ return integer number of rows affected
|
||||
*/
|
||||
public function replace(Doctrine_Table $table, array $fields, array $keys)
|
||||
{
|
||||
//if ( ! $this->supports('replace'))
|
||||
// throw new Doctrine_Connection_Exception('replace query is not supported');
|
||||
|
||||
if (empty($keys)) {
|
||||
throw new Doctrine_Connection_Exception('Not specified which fields are keys');
|
||||
}
|
||||
|
@ -36,6 +36,13 @@ class Doctrine_Expression
|
||||
|
||||
protected $_conn;
|
||||
|
||||
/**
|
||||
* Create an expression
|
||||
*
|
||||
* @param string $expr The expression
|
||||
* @param Doctrine_Connection $conn The connection (optional)
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($expr, $conn = null)
|
||||
{
|
||||
$this->setExpression($expr);
|
||||
@ -45,6 +52,11 @@ class Doctrine_Expression
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getConnection
|
||||
*
|
||||
* @return Doctrine_Connection The connection
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
if ( ! isset($this->_conn)) {
|
||||
@ -54,11 +66,25 @@ class Doctrine_Expression
|
||||
return $this->_conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* setExpression
|
||||
*
|
||||
* @param string $clause The expression to set
|
||||
* @return void
|
||||
*/
|
||||
public function setExpression($clause)
|
||||
{
|
||||
$this->_expression = $this->parseClause($clause);
|
||||
}
|
||||
|
||||
/**
|
||||
* parseExpression
|
||||
*
|
||||
* @todo: What does this function do?
|
||||
*
|
||||
* @param string $expr The expression to parse
|
||||
* @return void
|
||||
*/
|
||||
public function parseExpression($expr)
|
||||
{
|
||||
$pos = strpos($expr, '(');
|
||||
@ -78,6 +104,12 @@ class Doctrine_Expression
|
||||
return call_user_func_array(array($this->getConnection()->expression, $name), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* parseClause
|
||||
*
|
||||
* @param string $clause The clause
|
||||
* @return string The parse clause
|
||||
*/
|
||||
public function parseClause($clause)
|
||||
{
|
||||
$e = Doctrine_Tokenizer::bracketExplode($clause, ' ');
|
||||
@ -89,14 +121,24 @@ class Doctrine_Expression
|
||||
return implode(' ', $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* getSql
|
||||
*
|
||||
* @return string The expression
|
||||
*/
|
||||
public function getSql()
|
||||
{
|
||||
|
||||
return $this->_expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* __toString
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getSql();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,16 +46,17 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
|
||||
*/
|
||||
public function escapePattern($text)
|
||||
{
|
||||
if ($this->string_quoting['escape_pattern']) {
|
||||
$tmp = $this->conn->string_quoting;
|
||||
if ( ! $this->string_quoting['escape_pattern']) {
|
||||
return $text;
|
||||
}
|
||||
$tmp = $this->conn->string_quoting;
|
||||
|
||||
$text = str_replace($tmp['escape_pattern'],
|
||||
$tmp['escape_pattern'] .
|
||||
$tmp['escape_pattern'], $text);
|
||||
$text = str_replace($tmp['escape_pattern'],
|
||||
$tmp['escape_pattern'] .
|
||||
$tmp['escape_pattern'], $text);
|
||||
|
||||
foreach ($this->wildcards as $wildcard) {
|
||||
$text = str_replace($wildcard, $tmp['escape_pattern'] . $wildcard, $text);
|
||||
}
|
||||
foreach ($this->wildcards as $wildcard) {
|
||||
$text = str_replace($wildcard, $tmp['escape_pattern'] . $wildcard, $text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
@ -125,8 +126,8 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
|
||||
}
|
||||
$tmp = $this->conn->identifier_quoting;
|
||||
$str = str_replace($tmp['end'],
|
||||
$tmp['escape'] .
|
||||
$tmp['end'], $str);
|
||||
$tmp['escape'] .
|
||||
$tmp['end'], $str);
|
||||
|
||||
return $tmp['start'] . $str . $tmp['end'];
|
||||
}
|
||||
@ -145,28 +146,28 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
|
||||
$type = gettype($input);
|
||||
}
|
||||
switch ($type) {
|
||||
case 'integer':
|
||||
case 'enum':
|
||||
case 'boolean':
|
||||
case 'double':
|
||||
case 'float':
|
||||
case 'bool':
|
||||
case 'decimal':
|
||||
case 'int':
|
||||
return $input;
|
||||
case 'array':
|
||||
case 'object':
|
||||
$input = serialize($input);
|
||||
case 'string':
|
||||
case 'char':
|
||||
case 'varchar':
|
||||
case 'text':
|
||||
case 'gzip':
|
||||
case 'blob':
|
||||
case 'clob':
|
||||
$this->conn->connect();
|
||||
case 'integer':
|
||||
case 'enum':
|
||||
case 'boolean':
|
||||
case 'double':
|
||||
case 'float':
|
||||
case 'bool':
|
||||
case 'decimal':
|
||||
case 'int':
|
||||
return $input;
|
||||
case 'array':
|
||||
case 'object':
|
||||
$input = serialize($input);
|
||||
case 'string':
|
||||
case 'char':
|
||||
case 'varchar':
|
||||
case 'text':
|
||||
case 'gzip':
|
||||
case 'blob':
|
||||
case 'clob':
|
||||
$this->conn->connect();
|
||||
|
||||
return $this->conn->getDbh()->quote($input);
|
||||
return $this->conn->getDbh()->quote($input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,9 +225,9 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
|
||||
public function getIndexName($idx)
|
||||
{
|
||||
return sprintf($this->conn->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT),
|
||||
preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
|
||||
preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* adds table name formatting to a table name
|
||||
*
|
||||
@ -236,6 +237,6 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
|
||||
public function getTableName($table)
|
||||
{
|
||||
return sprintf($this->conn->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT),
|
||||
preg_replace('/[^a-z0-9_\$]/i', '_', $table));
|
||||
preg_replace('/[^a-z0-9_\$]/i', '_', $table));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,10 @@ class Doctrine_Hook
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $limit
|
||||
* set the hook limit
|
||||
*
|
||||
* @param integer $limit
|
||||
* @return void
|
||||
*/
|
||||
public function hookLimit($limit)
|
||||
{
|
||||
@ -216,10 +219,12 @@ class Doctrine_Hook
|
||||
}
|
||||
|
||||
/**
|
||||
* set the hook offset
|
||||
*
|
||||
* @param integer $offset
|
||||
*/
|
||||
public function hookOffset($offset)
|
||||
{
|
||||
$this->query->offset((int) $offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,14 +254,9 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
|
||||
*/
|
||||
public function useCache($driver = true, $timeToLive = null)
|
||||
{
|
||||
if ($driver !== null) {
|
||||
if ($driver !== true) {
|
||||
if ( ! ($driver instanceof Doctrine_Cache_Interface)) {
|
||||
$msg = 'First argument should be instance of Doctrine_Cache_Interface or null.';
|
||||
|
||||
throw new Doctrine_Hydrate_Exception($msg);
|
||||
}
|
||||
}
|
||||
if($driver !== null && $driver !== true && !($driver instanceOf Doctrine_Cache_Interface)){
|
||||
$msg = 'First argument should be instance of Doctrine_Cache_Interface or null.';
|
||||
throw new Doctrine_Hydrate_Exception($msg);
|
||||
}
|
||||
$this->_cache = $driver;
|
||||
|
||||
@ -549,15 +544,15 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
|
||||
*/
|
||||
public function removeQueryPart($name)
|
||||
{
|
||||
if (isset($this->parts[$name])) {
|
||||
if ($name == 'limit' || $name == 'offset') {
|
||||
$this->parts[$name] = false;
|
||||
} else {
|
||||
$this->parts[$name] = array();
|
||||
}
|
||||
} else {
|
||||
if ( ! isset($this->parts[$name])) {
|
||||
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
|
||||
}
|
||||
|
||||
if ($name == 'limit' || $name == 'offset') {
|
||||
$this->parts[$name] = false;
|
||||
} else {
|
||||
$this->parts[$name] = array();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -798,6 +793,13 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
|
||||
|
||||
return serialize(array($resultSet, $map, $this->getTableAliases()));
|
||||
}
|
||||
|
||||
/**
|
||||
* _execute
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function _execute($params)
|
||||
{
|
||||
$params = $this->_conn->convertBooleans($params);
|
||||
@ -1019,6 +1021,9 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
|
||||
* The key idea is the loop over the rowset only once doing all the needed operations
|
||||
* within this massive loop.
|
||||
*
|
||||
* @todo: Can we refactor this function so that it is not so long and
|
||||
* nested?
|
||||
*
|
||||
* @param mixed $stmt
|
||||
* @return array
|
||||
*/
|
||||
@ -1240,24 +1245,24 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
|
||||
}
|
||||
if ($index !== false) {
|
||||
$prev[$alias] =& $coll[$index];
|
||||
} else {
|
||||
// first check the count (we do not want to get the last element
|
||||
// of an empty collection/array)
|
||||
if (count($coll) > 0) {
|
||||
if (is_array($coll)) {
|
||||
if ($oneToOne) {
|
||||
$prev[$alias] =& $coll;
|
||||
} else {
|
||||
end($coll);
|
||||
$prev[$alias] =& $coll[key($coll)];
|
||||
}
|
||||
return;
|
||||
}
|
||||
// first check the count (we do not want to get the last element
|
||||
// of an empty collection/array)
|
||||
if (count($coll) > 0) {
|
||||
if (is_array($coll)) {
|
||||
if ($oneToOne) {
|
||||
$prev[$alias] =& $coll;
|
||||
} else {
|
||||
$prev[$alias] = $coll->getLast();
|
||||
end($coll);
|
||||
$prev[$alias] =& $coll[key($coll)];
|
||||
}
|
||||
} else {
|
||||
if (isset($prev[$alias])) {
|
||||
unset($prev[$alias]);
|
||||
}
|
||||
$prev[$alias] = $coll->getLast();
|
||||
}
|
||||
} else {
|
||||
if (isset($prev[$alias])) {
|
||||
unset($prev[$alias]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,26 @@
|
||||
*/
|
||||
class Doctrine_IntegrityMapper
|
||||
{
|
||||
/**
|
||||
* processDeleteIntegrity
|
||||
*
|
||||
* @param Doctrine_Record $record
|
||||
* @return void
|
||||
*/
|
||||
public function processDeleteIntegrity(Doctrine_Record $record)
|
||||
{
|
||||
$coll = $this->buildIntegrityRelationQuery($record);
|
||||
|
||||
$this->invokeIntegrityActions($record);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* invokeIntegrityActions
|
||||
*
|
||||
* @param Doctrine_Record $record
|
||||
* @return void
|
||||
*/
|
||||
public function invokeIntegrityActions(Doctrine_Record $record)
|
||||
{
|
||||
$deleteActions = Doctrine_Manager::getInstance()
|
||||
@ -65,6 +79,13 @@ class Doctrine_IntegrityMapper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* buildIntegrityRelationQuery
|
||||
*
|
||||
* @param Doctrine_Record $record
|
||||
* @return array The result
|
||||
*/
|
||||
public function buildIntegrityRelationQuery(Doctrine_Record $record)
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
@ -95,6 +116,17 @@ class Doctrine_IntegrityMapper
|
||||
|
||||
return $q->execute(array($params));
|
||||
}
|
||||
|
||||
/**
|
||||
* buildIntegrityRelations
|
||||
*
|
||||
* @param Doctrine_Table $table
|
||||
* @param mixed $aliases
|
||||
* @param mixed $fields
|
||||
* @param mixed $indexes
|
||||
* @param mixed $components
|
||||
* @return void
|
||||
*/
|
||||
public function buildIntegrityRelations(Doctrine_Table $table, &$aliases, &$fields, &$indexes, &$components)
|
||||
{
|
||||
$deleteActions = Doctrine_Manager::getInstance()
|
||||
@ -139,4 +171,4 @@ class Doctrine_IntegrityMapper
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +221,11 @@ class Doctrine_Lib
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* formatSql
|
||||
*
|
||||
* @todo: What about creating a config varialbe for the color?
|
||||
* @param mixed $sql
|
||||
* @return string the formated sql
|
||||
*/
|
||||
public static function formatSql($sql)
|
||||
{
|
||||
|
@ -82,6 +82,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
* setDefaultAttributes
|
||||
* sets default attributes
|
||||
*
|
||||
* @todo I do not understand the flow here. Explain or refactor?
|
||||
* @return boolean
|
||||
*/
|
||||
public function setDefaultAttributes()
|
||||
@ -106,7 +107,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL,
|
||||
Doctrine::ATTR_DECIMAL_PLACES => 2,
|
||||
Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine',
|
||||
);
|
||||
);
|
||||
foreach ($attributes as $attribute => $value) {
|
||||
$old = $this->getAttribute($attribute);
|
||||
if ($old === null) {
|
||||
@ -317,6 +318,12 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
return $this->_connections[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* parsePdoDsn
|
||||
*
|
||||
* @param array $dsn An array of dsn information
|
||||
* @return array The array parsed
|
||||
*/
|
||||
public function parsePdoDsn($dsn)
|
||||
{
|
||||
$parts = array();
|
||||
|
@ -114,6 +114,37 @@ class Doctrine_Migration
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* loadMigrationClassesFromDirectory
|
||||
*
|
||||
* refactored out from loadMigrationClasses
|
||||
* $param array An array of classes
|
||||
* @return void
|
||||
*/
|
||||
public function loadMigrationClassesFromDirectory($classes){
|
||||
foreach ((array) $this->_migrationClassesDirectory as $dir) {
|
||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
|
||||
foreach ($it as $file) {
|
||||
$e = explode('.', $file->getFileName());
|
||||
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
||||
if ( ! in_array($file->getFileName(), $this->_loadedMigrations)) {
|
||||
require_once($file->getPathName());
|
||||
|
||||
$requiredClass = array_diff(get_declared_classes(), $classes);
|
||||
$requiredClass = end($requiredClass);
|
||||
|
||||
if ($requiredClass) {
|
||||
$this->_loadedMigrations[$requiredClass] = $file->getFileName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* loadMigrationClasses
|
||||
*
|
||||
@ -130,27 +161,9 @@ class Doctrine_Migration
|
||||
$classes = get_declared_classes();
|
||||
|
||||
if ($this->_migrationClassesDirectory !== null) {
|
||||
foreach ((array) $this->_migrationClassesDirectory as $dir) {
|
||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
|
||||
foreach ($it as $file) {
|
||||
$e = explode('.', $file->getFileName());
|
||||
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
||||
if ( ! in_array($file->getFileName(), $this->_loadedMigrations)) {
|
||||
require_once($file->getPathName());
|
||||
|
||||
$requiredClass = array_diff(get_declared_classes(), $classes);
|
||||
$requiredClass = end($requiredClass);
|
||||
|
||||
if ($requiredClass) {
|
||||
$this->_loadedMigrations[$requiredClass] = $file->getFileName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->loadMigrationClassesFromDirectory($classes);
|
||||
}
|
||||
|
||||
|
||||
$parent = new ReflectionClass('Doctrine_Migration');
|
||||
|
||||
@ -317,16 +330,17 @@ class Doctrine_Migration
|
||||
*/
|
||||
protected function doMigrate($direction)
|
||||
{
|
||||
if (method_exists($this, $direction)) {
|
||||
$this->$direction();
|
||||
if (! method_exists($this, $direction)) {
|
||||
return;
|
||||
}
|
||||
$this->$direction();
|
||||
|
||||
foreach ($this->_changes as $type => $changes) {
|
||||
$process = new Doctrine_Migration_Process();
|
||||
$funcName = 'process' . Doctrine::classify($type);
|
||||
foreach ($this->_changes as $type => $changes) {
|
||||
$process = new Doctrine_Migration_Process();
|
||||
$funcName = 'process' . Doctrine::classify($type);
|
||||
|
||||
if ( ! empty($changes)) {
|
||||
$process->$funcName($changes);
|
||||
}
|
||||
if ( ! empty($changes)) {
|
||||
$process->$funcName($changes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -570,4 +584,4 @@ class Doctrine_Migration
|
||||
|
||||
$this->addChange('removed_indexes', $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,12 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
protected $_built = false;
|
||||
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->_options = array_merge($this->_options, $options);
|
||||
@ -62,6 +68,12 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* search
|
||||
*
|
||||
* @param string $query
|
||||
* @return Doctrine_Collection The collection of search results
|
||||
*/
|
||||
public function search($query)
|
||||
{
|
||||
$q = new Doctrine_Search_Query($this->_options['pluginTable']);
|
||||
@ -71,6 +83,12 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
return $this->_options['connection']->fetchAll($q->getSql(), $q->getParams());;
|
||||
}
|
||||
|
||||
/**
|
||||
* analyze
|
||||
*
|
||||
* @param string $text
|
||||
* @return void
|
||||
*/
|
||||
public function analyze($text)
|
||||
{
|
||||
return $this->_options['analyzer']->analyze($text);
|
||||
@ -131,6 +149,13 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* readTableData
|
||||
*
|
||||
* @param mixed $limit
|
||||
* @param mixed $offset
|
||||
* @return Doctrine_Collection The collection of results
|
||||
*/
|
||||
public function readTableData($limit = null, $offset = null)
|
||||
{
|
||||
$this->buildDefinition();
|
||||
@ -152,6 +177,13 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* batchUpdateIndex
|
||||
*
|
||||
* @param mixed $limit
|
||||
* @param mixed $offset
|
||||
* @return void
|
||||
*/
|
||||
public function batchUpdateIndex($limit = null, $offset = null)
|
||||
{
|
||||
$this->buildDefinition();
|
||||
@ -202,6 +234,11 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* buildDefinition
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildDefinition()
|
||||
{
|
||||
if ($this->_built) {
|
||||
|
@ -85,6 +85,14 @@ class Doctrine_Template extends Doctrine_Record_Abstract
|
||||
return $this->_invoker;
|
||||
}
|
||||
|
||||
/**
|
||||
* addChild
|
||||
*
|
||||
* Adds a plugin as a child to this plugin
|
||||
*
|
||||
* @param Doctrine_Template $template
|
||||
* @return Doctrine_Template. Chainable.
|
||||
*/
|
||||
public function addChild(Doctrine_Template $template)
|
||||
{
|
||||
$this->_plugin->addChild($template);
|
||||
@ -93,24 +101,53 @@ class Doctrine_Template extends Doctrine_Record_Abstract
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getPlugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getPlugin()
|
||||
{
|
||||
return $this->_plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* get
|
||||
*
|
||||
* @param mixed $name
|
||||
* @return void
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
throw new Doctrine_Exception("Templates doesn't support accessors.");
|
||||
}
|
||||
|
||||
/**
|
||||
* set
|
||||
*
|
||||
* @param mixed $name
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
throw new Doctrine_Exception("Templates doesn't support accessors.");
|
||||
}
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* setTableDefinition
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setTableDefinition()
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user