1
0
mirror of synced 2025-01-06 00:57:10 +03:00

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:
meus 2007-11-18 20:37:44 +00:00
parent 7af31c0c51
commit d5cc06e7b8
16 changed files with 384 additions and 172 deletions

View File

@ -103,6 +103,8 @@ abstract class Doctrine_Access extends Doctrine_Locator_Injectable implements Ar
} }
/** /**
* Check if an offsetExists. Alias for contains.
*
* @param mixed $offset * @param mixed $offset
* @return boolean whether or not this object contains $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() * offsetGet an alias of get()
*
* @see get, __get * @see get, __get
* @param mixed $offset * @param mixed $offset
* @return mixed * @return mixed

View File

@ -40,11 +40,24 @@ class Doctrine_AuditLog extends Doctrine_Plugin
'pluginTable' => false, 'pluginTable' => false,
); );
/**
* Create a new auditlog_
*
* @param array $options An array of options
* @return void
*/
public function __construct($options) public function __construct($options)
{ {
$this->_options = array_merge($this->_options, $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) public function getVersion(Doctrine_Record $record, $version)
{ {
$className = $this->_options['className']; $className = $this->_options['className'];
@ -65,6 +78,13 @@ class Doctrine_AuditLog extends Doctrine_Plugin
return $q->execute($values, Doctrine::HYDRATE_ARRAY); 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) public function buildDefinition(Doctrine_Table $table)
{ {
$this->_options['className'] = str_replace('%CLASS%', $this->_options['className'] = str_replace('%CLASS%',

View File

@ -36,12 +36,12 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
* @var array $_options an array of general caching options * @var array $_options an array of general caching options
*/ */
protected $_options = array('size' => 1000, protected $_options = array('size' => 1000,
'lifeTime' => 3600, 'lifeTime' => 3600,
'addStatsPropability' => 0.25, 'addStatsPropability' => 0.25,
'savePropability' => 0.10, 'savePropability' => 0.10,
'cleanPropability' => 0.01, 'cleanPropability' => 0.01,
'statsFile' => '../data/stats.cache', 'statsFile' => '../data/stats.cache',
); );
/** /**
* @var array $_queries query stack * @var array $_queries query stack
@ -72,19 +72,19 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
public function __construct($driver, $options = array()) public function __construct($driver, $options = array())
{ {
if (is_object($driver)) { if (is_object($driver)) {
if ( ! ($driver instanceof Doctrine_Cache_Interface)) { if ( ! ($driver instanceof Doctrine_Cache_Interface)) {
throw new Doctrine_Cache_Exception('Driver should implement Doctrine_Cache_Interface.'); throw new Doctrine_Cache_Exception('Driver should implement Doctrine_Cache_Interface.');
} }
$this->_driver = $driver; $this->_driver = $driver;
$this->_driver->setOptions($options); $this->_driver->setOptions($options);
} else { } else {
$class = 'Doctrine_Cache_' . ucwords(strtolower($driver)); $class = 'Doctrine_Cache_' . ucwords(strtolower($driver));
if ( ! class_exists($class)) { if ( ! class_exists($class)) {
throw new Doctrine_Cache_Exception('Cache driver ' . $driver . ' could not be found.'); throw new Doctrine_Cache_Exception('Cache driver ' . $driver . ' could not be found.');
} }
$this->_driver = new $class($options); $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[$namespace];
} }
return $this->_queries; return $this->_queries;
} }
@ -235,7 +235,7 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
$queries = $this->readStats(); $queries = $this->readStats();
$stats = array(); $stats = array();
foreach ($queries as $query) { foreach ($queries as $query) {
if (isset($stats[$query])) { if (isset($stats[$query])) {
$stats[$query]++; $stats[$query]++;
@ -244,9 +244,9 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
} }
} }
sort($stats); sort($stats);
$i = $this->_options['size']; $i = $this->_options['size'];
while ($i--) { while ($i--) {
$element = next($stats); $element = next($stats);
$query = key($stats); $query = key($stats);
@ -266,11 +266,11 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
public function readStats() public function readStats()
{ {
if ($this->_options['statsFile'] !== false) { if ($this->_options['statsFile'] !== false) {
$content = file_get_contents($this->_options['statsFile']); $content = file_get_contents($this->_options['statsFile']);
$e = explode("\n", $content); $e = explode("\n", $content);
return array_map('unserialize', $e); return array_map('unserialize', $e);
} }
return array(); return array();
} }
@ -288,7 +288,7 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
if ( ! file_exists($this->_options['statsFile'])) { if ( ! file_exists($this->_options['statsFile'])) {
throw new Doctrine_Cache_Exception("Couldn't save cache statistics. Cache statistics file doesn't exists!"); throw new Doctrine_Cache_Exception("Couldn't save cache statistics. Cache statistics file doesn't exists!");
} }
$rand = (mt_rand() / mt_getrandmax()); $rand = (mt_rand() / mt_getrandmax());
if ($rand <= $this->_options['addStatsPropability']) { if ($rand <= $this->_options['addStatsPropability']) {
@ -312,33 +312,34 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
$data = false; $data = false;
// only process SELECT statements // 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) { if ( ! $data) {
$rand = (mt_rand() / mt_getrandmax()); $rand = (mt_rand() / mt_getrandmax());
if ($rand < $this->_options['savePropability']) { if ($rand < $this->_options['savePropability']) {
$stmt = $event->getInvoker()->getAdapter()->query($query); $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); $this->_driver->save(md5(serialize($query)), $data);
}
}
if ($this->success)
{
$this->_data = $data;
return true;
} }
} }
if ($this->success)
{
$this->_data = $data;
return true;
}
return false; return false;
} }
@ -387,36 +388,37 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
$data = false; $data = false;
// only process SELECT statements // 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) { if ( ! $data) {
$rand = (mt_rand() / mt_getrandmax()); $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); $this->_driver->save(md5(serialize(array($query, $event->getParams()))), $data);
}
}
if ($this->success)
{
$this->_data = $data;
return true;
} }
} }
if ($this->success)
{
$this->_data = $data;
return true;
}
return false; return false;
} }
} }

View File

@ -26,8 +26,8 @@
* @package Doctrine * @package Doctrine
* @subpackage Compiler * @subpackage Compiler
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpllicense.php LGPL
* @link www.phpdoctrine.com * @link www.phpdoctrine.
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
@ -69,6 +69,8 @@ class Doctrine_Compiler
foreach ($it as $file) { foreach ($it as $file) {
$e = explode('.', $file->getFileName()); $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 // we don't want to require versioning files
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
require_once $file->getPathName(); require_once $file->getPathName();
@ -132,4 +134,4 @@ class Doctrine_Compiler
fwrite($fp, $stripped); fwrite($fp, $stripped);
fclose($fp); fclose($fp);
} }
} }

View File

@ -379,13 +379,14 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
throw new Doctrine_Exception('Unknown attribute.'); throw new Doctrine_Exception('Unknown attribute.');
} }
if ( ! isset($this->attributes[$attribute])) { if (isset($this->attributes[$attribute])) {
if (isset($this->parent)) { return $this->attributes[$attribute];
return $this->parent->getAttribute($attribute);
}
return null;
} }
return $this->attributes[$attribute];
if (isset($this->parent)) {
return $this->parent->getAttribute($attribute);
}
return null;
} }
/** /**

View File

@ -262,6 +262,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* setAttribute * setAttribute
* sets an attribute * sets an attribute
* *
* @todo why check for >= 100? has this any special meaning when creating
* attributes?
*
* @param integer $attribute * @param integer $attribute
* @param mixed $value * @param mixed $value
* @return boolean * @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 some of the key values was null
* @throws Doctrine_Connection_Exception if there were no key fields * @throws Doctrine_Connection_Exception if there were no key fields
* @throws PDOException if something fails at PDO level * @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) 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)) { if (empty($keys)) {
throw new Doctrine_Connection_Exception('Not specified which fields are keys'); throw new Doctrine_Connection_Exception('Not specified which fields are keys');
} }

View File

@ -36,6 +36,13 @@ class Doctrine_Expression
protected $_conn; 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) public function __construct($expr, $conn = null)
{ {
$this->setExpression($expr); $this->setExpression($expr);
@ -45,6 +52,11 @@ class Doctrine_Expression
} }
} }
/**
* getConnection
*
* @return Doctrine_Connection The connection
*/
public function getConnection() public function getConnection()
{ {
if ( ! isset($this->_conn)) { if ( ! isset($this->_conn)) {
@ -54,11 +66,25 @@ class Doctrine_Expression
return $this->_conn; return $this->_conn;
} }
/**
* setExpression
*
* @param string $clause The expression to set
* @return void
*/
public function setExpression($clause) public function setExpression($clause)
{ {
$this->_expression = $this->parseClause($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) public function parseExpression($expr)
{ {
$pos = strpos($expr, '('); $pos = strpos($expr, '(');
@ -78,6 +104,12 @@ class Doctrine_Expression
return call_user_func_array(array($this->getConnection()->expression, $name), $args); 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) public function parseClause($clause)
{ {
$e = Doctrine_Tokenizer::bracketExplode($clause, ' '); $e = Doctrine_Tokenizer::bracketExplode($clause, ' ');
@ -89,14 +121,24 @@ class Doctrine_Expression
return implode(' ', $e); return implode(' ', $e);
} }
/**
* getSql
*
* @return string The expression
*/
public function getSql() public function getSql()
{ {
return $this->_expression; return $this->_expression;
} }
/**
* __toString
*
* @return void
*/
public function __toString() public function __toString()
{ {
return $this->getSql(); return $this->getSql();
} }
} }

View File

@ -46,16 +46,17 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
*/ */
public function escapePattern($text) public function escapePattern($text)
{ {
if ($this->string_quoting['escape_pattern']) { if ( ! $this->string_quoting['escape_pattern']) {
$tmp = $this->conn->string_quoting; return $text;
}
$tmp = $this->conn->string_quoting;
$text = str_replace($tmp['escape_pattern'], $text = str_replace($tmp['escape_pattern'],
$tmp['escape_pattern'] . $tmp['escape_pattern'] .
$tmp['escape_pattern'], $text); $tmp['escape_pattern'], $text);
foreach ($this->wildcards as $wildcard) { foreach ($this->wildcards as $wildcard) {
$text = str_replace($wildcard, $tmp['escape_pattern'] . $wildcard, $text); $text = str_replace($wildcard, $tmp['escape_pattern'] . $wildcard, $text);
}
} }
return $text; return $text;
} }
@ -125,8 +126,8 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
} }
$tmp = $this->conn->identifier_quoting; $tmp = $this->conn->identifier_quoting;
$str = str_replace($tmp['end'], $str = str_replace($tmp['end'],
$tmp['escape'] . $tmp['escape'] .
$tmp['end'], $str); $tmp['end'], $str);
return $tmp['start'] . $str . $tmp['end']; return $tmp['start'] . $str . $tmp['end'];
} }
@ -145,28 +146,28 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
$type = gettype($input); $type = gettype($input);
} }
switch ($type) { switch ($type) {
case 'integer': case 'integer':
case 'enum': case 'enum':
case 'boolean': case 'boolean':
case 'double': case 'double':
case 'float': case 'float':
case 'bool': case 'bool':
case 'decimal': case 'decimal':
case 'int': case 'int':
return $input; return $input;
case 'array': case 'array':
case 'object': case 'object':
$input = serialize($input); $input = serialize($input);
case 'string': case 'string':
case 'char': case 'char':
case 'varchar': case 'varchar':
case 'text': case 'text':
case 'gzip': case 'gzip':
case 'blob': case 'blob':
case 'clob': case 'clob':
$this->conn->connect(); $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) public function getIndexName($idx)
{ {
return sprintf($this->conn->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT), 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 * adds table name formatting to a table name
* *
@ -236,6 +237,6 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
public function getTableName($table) public function getTableName($table)
{ {
return sprintf($this->conn->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT), return sprintf($this->conn->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT),
preg_replace('/[^a-z0-9_\$]/i', '_', $table)); preg_replace('/[^a-z0-9_\$]/i', '_', $table));
} }
} }

View File

@ -208,7 +208,10 @@ class Doctrine_Hook
} }
/** /**
* @param integer $limit * set the hook limit
*
* @param integer $limit
* @return void
*/ */
public function hookLimit($limit) public function hookLimit($limit)
{ {
@ -216,10 +219,12 @@ class Doctrine_Hook
} }
/** /**
* set the hook offset
*
* @param integer $offset * @param integer $offset
*/ */
public function hookOffset($offset) public function hookOffset($offset)
{ {
$this->query->offset((int) $offset); $this->query->offset((int) $offset);
} }
} }

View File

@ -254,14 +254,9 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
*/ */
public function useCache($driver = true, $timeToLive = null) public function useCache($driver = true, $timeToLive = null)
{ {
if ($driver !== null) { if($driver !== null && $driver !== true && !($driver instanceOf Doctrine_Cache_Interface)){
if ($driver !== true) { $msg = 'First argument should be instance of Doctrine_Cache_Interface or null.';
if ( ! ($driver instanceof Doctrine_Cache_Interface)) { throw new Doctrine_Hydrate_Exception($msg);
$msg = 'First argument should be instance of Doctrine_Cache_Interface or null.';
throw new Doctrine_Hydrate_Exception($msg);
}
}
} }
$this->_cache = $driver; $this->_cache = $driver;
@ -549,15 +544,15 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
*/ */
public function removeQueryPart($name) public function removeQueryPart($name)
{ {
if (isset($this->parts[$name])) { if ( ! isset($this->parts[$name])) {
if ($name == 'limit' || $name == 'offset') {
$this->parts[$name] = false;
} else {
$this->parts[$name] = array();
}
} else {
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $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; return $this;
} }
@ -798,6 +793,13 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
return serialize(array($resultSet, $map, $this->getTableAliases())); return serialize(array($resultSet, $map, $this->getTableAliases()));
} }
/**
* _execute
*
* @param array $params
* @return void
*/
public function _execute($params) public function _execute($params)
{ {
$params = $this->_conn->convertBooleans($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 * The key idea is the loop over the rowset only once doing all the needed operations
* within this massive loop. * within this massive loop.
* *
* @todo: Can we refactor this function so that it is not so long and
* nested?
*
* @param mixed $stmt * @param mixed $stmt
* @return array * @return array
*/ */
@ -1240,24 +1245,24 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
} }
if ($index !== false) { if ($index !== false) {
$prev[$alias] =& $coll[$index]; $prev[$alias] =& $coll[$index];
} else { return;
// first check the count (we do not want to get the last element }
// of an empty collection/array) // first check the count (we do not want to get the last element
if (count($coll) > 0) { // of an empty collection/array)
if (is_array($coll)) { if (count($coll) > 0) {
if ($oneToOne) { if (is_array($coll)) {
$prev[$alias] =& $coll; if ($oneToOne) {
} else { $prev[$alias] =& $coll;
end($coll);
$prev[$alias] =& $coll[key($coll)];
}
} else { } else {
$prev[$alias] = $coll->getLast(); end($coll);
$prev[$alias] =& $coll[key($coll)];
} }
} else { } else {
if (isset($prev[$alias])) { $prev[$alias] = $coll->getLast();
unset($prev[$alias]); }
} } else {
if (isset($prev[$alias])) {
unset($prev[$alias]);
} }
} }
} }

View File

@ -32,12 +32,26 @@
*/ */
class Doctrine_IntegrityMapper class Doctrine_IntegrityMapper
{ {
/**
* processDeleteIntegrity
*
* @param Doctrine_Record $record
* @return void
*/
public function processDeleteIntegrity(Doctrine_Record $record) public function processDeleteIntegrity(Doctrine_Record $record)
{ {
$coll = $this->buildIntegrityRelationQuery($record); $coll = $this->buildIntegrityRelationQuery($record);
$this->invokeIntegrityActions($record); $this->invokeIntegrityActions($record);
} }
/**
* invokeIntegrityActions
*
* @param Doctrine_Record $record
* @return void
*/
public function invokeIntegrityActions(Doctrine_Record $record) public function invokeIntegrityActions(Doctrine_Record $record)
{ {
$deleteActions = Doctrine_Manager::getInstance() $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) public function buildIntegrityRelationQuery(Doctrine_Record $record)
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
@ -95,6 +116,17 @@ class Doctrine_IntegrityMapper
return $q->execute(array($params)); 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) public function buildIntegrityRelations(Doctrine_Table $table, &$aliases, &$fields, &$indexes, &$components)
{ {
$deleteActions = Doctrine_Manager::getInstance() $deleteActions = Doctrine_Manager::getInstance()
@ -139,4 +171,4 @@ class Doctrine_IntegrityMapper
} }
} }
} }
} }

View File

@ -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) public static function formatSql($sql)
{ {

View File

@ -82,6 +82,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* setDefaultAttributes * setDefaultAttributes
* sets default attributes * sets default attributes
* *
* @todo I do not understand the flow here. Explain or refactor?
* @return boolean * @return boolean
*/ */
public function setDefaultAttributes() public function setDefaultAttributes()
@ -106,7 +107,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL, Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL,
Doctrine::ATTR_DECIMAL_PLACES => 2, Doctrine::ATTR_DECIMAL_PLACES => 2,
Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine', Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine',
); );
foreach ($attributes as $attribute => $value) { foreach ($attributes as $attribute => $value) {
$old = $this->getAttribute($attribute); $old = $this->getAttribute($attribute);
if ($old === null) { if ($old === null) {
@ -317,6 +318,12 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return $this->_connections[$name]; return $this->_connections[$name];
} }
/**
* parsePdoDsn
*
* @param array $dsn An array of dsn information
* @return array The array parsed
*/
public function parsePdoDsn($dsn) public function parsePdoDsn($dsn)
{ {
$parts = array(); $parts = array();

View File

@ -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 * loadMigrationClasses
* *
@ -130,27 +161,9 @@ class Doctrine_Migration
$classes = get_declared_classes(); $classes = get_declared_classes();
if ($this->_migrationClassesDirectory !== null) { if ($this->_migrationClassesDirectory !== null) {
foreach ((array) $this->_migrationClassesDirectory as $dir) { $this->loadMigrationClassesFromDirectory($classes);
$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();
}
}
}
}
}
} }
$parent = new ReflectionClass('Doctrine_Migration'); $parent = new ReflectionClass('Doctrine_Migration');
@ -317,16 +330,17 @@ class Doctrine_Migration
*/ */
protected function doMigrate($direction) protected function doMigrate($direction)
{ {
if (method_exists($this, $direction)) { if (! method_exists($this, $direction)) {
$this->$direction(); return;
}
$this->$direction();
foreach ($this->_changes as $type => $changes) { foreach ($this->_changes as $type => $changes) {
$process = new Doctrine_Migration_Process(); $process = new Doctrine_Migration_Process();
$funcName = 'process' . Doctrine::classify($type); $funcName = 'process' . Doctrine::classify($type);
if ( ! empty($changes)) { if ( ! empty($changes)) {
$process->$funcName($changes); $process->$funcName($changes);
}
} }
} }
} }
@ -570,4 +584,4 @@ class Doctrine_Migration
$this->addChange('removed_indexes', $options); $this->addChange('removed_indexes', $options);
} }
} }

View File

@ -49,6 +49,12 @@ class Doctrine_Search extends Doctrine_Plugin
protected $_built = false; protected $_built = false;
/**
* __construct
*
* @param array $options
* @return void
*/
public function __construct(array $options) public function __construct(array $options)
{ {
$this->_options = array_merge($this->_options, $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) public function search($query)
{ {
$q = new Doctrine_Search_Query($this->_options['pluginTable']); $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());; return $this->_options['connection']->fetchAll($q->getSql(), $q->getParams());;
} }
/**
* analyze
*
* @param string $text
* @return void
*/
public function analyze($text) public function analyze($text)
{ {
return $this->_options['analyzer']->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) public function readTableData($limit = null, $offset = null)
{ {
$this->buildDefinition(); $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) public function batchUpdateIndex($limit = null, $offset = null)
{ {
$this->buildDefinition(); $this->buildDefinition();
@ -202,6 +234,11 @@ class Doctrine_Search extends Doctrine_Plugin
} }
} }
/**
* buildDefinition
*
* @return void
*/
public function buildDefinition() public function buildDefinition()
{ {
if ($this->_built) { if ($this->_built) {

View File

@ -85,6 +85,14 @@ class Doctrine_Template extends Doctrine_Record_Abstract
return $this->_invoker; 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) public function addChild(Doctrine_Template $template)
{ {
$this->_plugin->addChild($template); $this->_plugin->addChild($template);
@ -93,24 +101,53 @@ class Doctrine_Template extends Doctrine_Record_Abstract
} }
/**
* getPlugin
*
* @return void
*/
public function getPlugin() public function getPlugin()
{ {
return $this->_plugin; return $this->_plugin;
} }
/**
* get
*
* @param mixed $name
* @return void
*/
public function get($name) public function get($name)
{ {
throw new Doctrine_Exception("Templates doesn't support accessors."); throw new Doctrine_Exception("Templates doesn't support accessors.");
} }
/**
* set
*
* @param mixed $name
* @param mixed $value
* @return void
*/
public function set($name, $value) public function set($name, $value)
{ {
throw new Doctrine_Exception("Templates doesn't support accessors."); throw new Doctrine_Exception("Templates doesn't support accessors.");
} }
/**
* setUp
*
* @return void
*/
public function setUp() public function setUp()
{ {
} }
/**
* setTableDefinition
*
* @return void
*/
public function setTableDefinition() public function setTableDefinition()
{ {