1
0
mirror of synced 2025-01-07 09:37:11 +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

@ -312,7 +312,9 @@ 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());
@ -338,7 +340,6 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
$this->_data = $data; $this->_data = $data;
return true; return true;
} }
}
return false; return false;
} }
@ -387,7 +388,9 @@ 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());
@ -416,7 +419,6 @@ class Doctrine_Cache extends Doctrine_EventListener implements Countable, Iterat
$this->_data = $data; $this->_data = $data;
return true; 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();

View File

@ -379,14 +379,15 @@ 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])) {
return $this->attributes[$attribute];
}
if (isset($this->parent)) { if (isset($this->parent)) {
return $this->parent->getAttribute($attribute); return $this->parent->getAttribute($attribute);
} }
return null; return null;
} }
return $this->attributes[$attribute];
}
/** /**
* getAttributes * getAttributes

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
@ -470,9 +473,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/ */
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,12 +121,22 @@ 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,7 +46,9 @@ 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']) {
return $text;
}
$tmp = $this->conn->string_quoting; $tmp = $this->conn->string_quoting;
$text = str_replace($tmp['escape_pattern'], $text = str_replace($tmp['escape_pattern'],
@ -56,7 +58,6 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
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;
} }

View File

@ -208,7 +208,10 @@ class Doctrine_Hook
} }
/** /**
* set the hook limit
*
* @param integer $limit * @param integer $limit
* @return void
*/ */
public function hookLimit($limit) public function hookLimit($limit)
{ {
@ -216,6 +219,8 @@ class Doctrine_Hook
} }
/** /**
* set the hook offset
*
* @param integer $offset * @param integer $offset
*/ */
public function hookOffset($offset) public function hookOffset($offset)

View File

@ -254,15 +254,10 @@ 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) {
if ( ! ($driver instanceof Doctrine_Cache_Interface)) {
$msg = 'First argument should be instance of Doctrine_Cache_Interface or null.'; $msg = 'First argument should be instance of Doctrine_Cache_Interface or null.';
throw new Doctrine_Hydrate_Exception($msg); throw new Doctrine_Hydrate_Exception($msg);
} }
}
}
$this->_cache = $driver; $this->_cache = $driver;
return $this->setCacheLifeSpan($timeToLive); return $this->setCacheLifeSpan($timeToLive);
@ -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])) {
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
}
if ($name == 'limit' || $name == 'offset') { if ($name == 'limit' || $name == 'offset') {
$this->parts[$name] = false; $this->parts[$name] = false;
} else { } else {
$this->parts[$name] = array(); $this->parts[$name] = array();
} }
} else {
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
}
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,7 +1245,8 @@ 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 // first check the count (we do not want to get the last element
// of an empty collection/array) // of an empty collection/array)
if (count($coll) > 0) { if (count($coll) > 0) {
@ -1260,7 +1266,6 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
} }
} }
} }
}
/** /**
* @return string returns a string representation of this object * @return string returns a string representation of this object

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()

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()
@ -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,22 +114,15 @@ class Doctrine_Migration
} }
} }
/** /**
* loadMigrationClasses * loadMigrationClassesFromDirectory
*
* Loads the migration classes for the directory specified by the constructor
* *
* refactored out from loadMigrationClasses
* $param array An array of classes
* @return void * @return void
*/ */
protected function loadMigrationClasses() public function loadMigrationClassesFromDirectory($classes){
{
if ($this->_migrationClasses) {
return $this->_migrationClasses;
}
$classes = get_declared_classes();
if ($this->_migrationClassesDirectory !== null) {
foreach ((array) $this->_migrationClassesDirectory as $dir) { foreach ((array) $this->_migrationClassesDirectory as $dir) {
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
RecursiveIteratorIterator::LEAVES_ONLY); RecursiveIteratorIterator::LEAVES_ONLY);
@ -152,6 +145,26 @@ class Doctrine_Migration
} }
} }
/**
* loadMigrationClasses
*
* Loads the migration classes for the directory specified by the constructor
*
* @return void
*/
protected function loadMigrationClasses()
{
if ($this->_migrationClasses) {
return $this->_migrationClasses;
}
$classes = get_declared_classes();
if ($this->_migrationClassesDirectory !== null) {
$this->loadMigrationClassesFromDirectory($classes);
}
$parent = new ReflectionClass('Doctrine_Migration'); $parent = new ReflectionClass('Doctrine_Migration');
foreach ($this->_loadedMigrations as $name => $fileName) { foreach ($this->_loadedMigrations as $name => $fileName) {
@ -317,7 +330,9 @@ class Doctrine_Migration
*/ */
protected function doMigrate($direction) protected function doMigrate($direction)
{ {
if (method_exists($this, $direction)) { if (! method_exists($this, $direction)) {
return;
}
$this->$direction(); $this->$direction();
foreach ($this->_changes as $type => $changes) { foreach ($this->_changes as $type => $changes) {
@ -329,7 +344,6 @@ class Doctrine_Migration
} }
} }
} }
}
/** /**
* migrate * migrate

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()
{ {