Commit b6a6866b authored by romanb's avatar romanb

refactorings

parent 72316541
......@@ -240,6 +240,7 @@ final class Doctrine
* IMMEDIATE FETCHING
* mode for immediate fetching
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_IMMEDIATE = 0;
......@@ -249,6 +250,7 @@ final class Doctrine
* mode for batch fetching
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_BATCH = 1;
......@@ -258,6 +260,7 @@ final class Doctrine
* mode for offset fetching
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_OFFSET = 3;
......@@ -267,6 +270,7 @@ final class Doctrine
* mode for lazy offset fetching
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_LAZY_OFFSET = 4;
......@@ -387,6 +391,7 @@ final class Doctrine
*
* mode for optimistic locking
* @see self::ATTR_LOCK
* @deprecated???
*/
const LOCK_OPTIMISTIC = 0;
......@@ -396,6 +401,7 @@ final class Doctrine
* mode for pessimistic locking
*
* @see self::ATTR_LOCK
* @deprecated???
*/
const LOCK_PESSIMISTIC = 1;
......
......@@ -36,6 +36,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
protected $_entityName;
/**
* The name of the custom mapper class used for the entity class.
*
* @var string
*/
protected $_customMapperClassName;
/**
*
* @var Doctrine_Connection
......@@ -49,9 +56,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* The field names of all fields that are part of the identifier/primary key
* of the described class.
* of the described entity class.
*
* @var array
* @var array
*/
protected $_identifier = array();
......@@ -134,8 +141,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* An array of field names. used to look up field names from column names.
* Keys are column names and values are field names.
* This is the reverse lookup map of $_columnNames.
*
* @var array
* @var array
*/
protected $_fieldNames = array();
......@@ -161,10 +169,10 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
protected $_tree;
/**
* Cached column count, Doctrine_Record uses this column count in when
* Cached column count, Doctrine_Record uses this column count when
* determining its state.
*
* @var integer
* @var integer
*/
protected $_columnCount;
......@@ -201,8 +209,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
protected $_options = array(
'treeImpl' => null,
'treeOptions' => null,
'subclasses' => array(),
'queryParts' => array(),
'subclasses' => array(),
'parents' => array()
);
......@@ -1589,7 +1597,32 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
}
/**
* Registers a custom mapper for the entity class.
*
* @param string $mapperClassName The class name of the custom mapper.
*/
public function setCustomMapperClass($mapperClassName)
{
if ( ! is_subclass_of($mapperClassName, 'Doctrine_Mapper')) {
throw new Doctrine_ClassMetadata_Exception("The custom mapper must be a subclass"
. " of Doctrine_Mapper.");
}
$this->_customMapperClassName = $mapperClassName;
}
/**
* Gets the name of the custom mapper class used for the entity class.
*
* @return string|null The name of the custom mapper class or NULL if the entity
* class does not have a custom mapper class.
*/
public function getCustomMapperClass()
{
return $this->_customMapperClassName;
}
/**
* @todo Thoughts & Implementation.
*/
public function setType($type)
{
......@@ -1599,7 +1632,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
}
/**
* @todo Implementation.
* @todo Implementation. Immutable entities can not be updated or deleted once
* they are created. This means the entity can only be modified as long as it's
* in transient state (TCLEAN, TDIRTY).
*/
public function isImmutable()
{
......
......@@ -52,6 +52,7 @@ Doctrine::autoload('Doctrine_Configurable');
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (MDB2 library)
* @author Roman Borschel <roman@code-factory.org>
*/
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate
{
......@@ -63,16 +64,18 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
protected $dbh;
/**
* The metadata factory is used to retrieve the metadata of classes.
* The metadata factory is used to retrieve the metadata of entity classes.
*
* @var Doctrine_ClassMetadata_Factory
* @todo package:orm
*/
protected $_metadataFactory;
/**
* An array of mapper objects currently maintained by this connection.
*
* @var array
* @var array
* @todo package:orm
*/
protected $_mappers = array();
......@@ -202,6 +205,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*
* @param Doctrine_Manager $manager the manager object
* @param PDO|Doctrine_Adapter_Interface $adapter database driver
* @todo Remove the dependency on the Manager for DBAL/ORM separation.
*/
public function __construct(Doctrine_Manager $manager, $adapter, $user = null, $pass = null)
{
......@@ -985,7 +989,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ( ! empty($params)) {
$stmt = $this->prepare($query);
$stmt->execute($params);
//echo "<br /><br />" . $query . "<br /><br />";
return $stmt->rowCount();
} else {
$event = new Doctrine_Event($this, Doctrine_Event::CONN_EXEC, $query, $params);
......@@ -994,7 +997,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ( ! $event->skipOperation) {
$count = $this->dbh->exec($query);
//echo "<br /><br />" . $query . "<br /><br />";
$this->_count++;
}
$this->getAttribute(Doctrine::ATTR_LISTENER)->postExec($event);
......@@ -1042,6 +1044,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*
* @param mixed $name
* @return boolean
* @deprecated
* @todo package:orm
*/
public function hasTable($name)
{
......@@ -1052,6 +1056,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* Returns the metadata for a class.
*
* @return Doctrine_Metadata
* @deprecated Use getClassMetadata()
* @todo package:orm
*/
public function getMetadata($className)
......@@ -1080,6 +1085,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* classes.
*
* @param $driver The driver to use.
* @todo package:orm
*/
public function setClassMetadataDriver($driver)
{
......@@ -1090,35 +1096,35 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* Gets a mapper for the specified domain class that is used to map instances of
* the class between the relational database and their object representation.
*
* @param string $entityClassName The name of the entity class.
* @return Doctrine_Mapper The mapper object.
* @todo package:orm
*/
public function getMapper($className)
public function getMapper($entityClassName)
{
if (isset($this->_mappers[$className])) {
return $this->_mappers[$className];
if (isset($this->_mappers[$entityClassName])) {
return $this->_mappers[$entityClassName];
}
$customMapperClass = $className . 'Mapper';
$metadata = $this->getMetadata($className);
if (class_exists($customMapperClass, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) &&
in_array('Doctrine_Mapper_Abstract', class_parents($customMapperClass))) {
$mapper = new $customMapperClass($className, $metadata);
$metadata = $this->getClassMetadata($entityClassName);
$customMapperClassName = $metadata->getCustomMapperClass();
if ($customMapperClassName !== null) {
$mapper = new $customMapperClassName($entityClassName, $metadata);
} else {
// instantiate correct mapper type
$inheritanceType = $metadata->getInheritanceType();
if ($inheritanceType == Doctrine::INHERITANCETYPE_JOINED) {
$mapper = new Doctrine_Mapper_Joined($className, $metadata);
$mapper = new Doctrine_Mapper_Joined($entityClassName, $metadata);
} else if ($inheritanceType == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
$mapper = new Doctrine_Mapper_SingleTable($className, $metadata);
$mapper = new Doctrine_Mapper_SingleTable($entityClassName, $metadata);
} else if ($inheritanceType == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) {
$mapper = new Doctrine_Mapper_TablePerClass($className, $metadata);
$mapper = new Doctrine_Mapper_TablePerClass($entityClassName, $metadata);
} else {
throw new Doctrine_Connection_Exception("Unknown inheritance type '$inheritanceType'. Can't create mapper.");
}
}
$this->_mappers[$className] = $mapper;
$this->_mappers[$entityClassName] = $mapper;
return $mapper;
}
......
This diff is collapsed.
......@@ -330,6 +330,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*
* @param array $dsn An array of dsn information
* @return array The array parsed
* @todo package:dbal
*/
public function parsePdoDsn($dsn)
{
......@@ -367,6 +368,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*
* @param string $dsn
* @return array Parsed contents of DSN
* @todo package:dbal
*/
public function parseDsn($dsn)
{
......@@ -599,6 +601,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* @see Doctrine_Connection::getTable()
* @param string $componentName
* @return Doctrine_Table
* @deprecated
*/
public function getTable($componentName)
{
......@@ -698,6 +701,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* returns the number of opened connections
*
* @return integer
* @todo This is unintuitive.
*/
public function count()
{
......@@ -738,6 +742,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*
* @param string $specifiedConnections Array of connections you wish to create the database for
* @return void
* @todo package:dbal
*/
public function createDatabases($specifiedConnections = array())
{
......@@ -765,6 +770,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*
* @param string $specifiedConnections Array of connections you wish to drop the database for
* @return void
* @todo package:dbal
*/
public function dropDatabases($specifiedConnections = array())
{
......
......@@ -33,13 +33,15 @@ Doctrine::autoload('Doctrine_Access');
abstract class Doctrine_Record_Abstract extends Doctrine_Access
{
/**
* @param Doctrine_Table $_table reference to associated Doctrine_Table instance
* The metadata container that describes the entity class.
*
* @param Doctrine_ClassMetadata
*/
protected $_table;
/**
*
* @var Doctrine_Mapper_Abstract
* @var Doctrine_Mapper
*/
protected $_mapper;
......@@ -77,6 +79,8 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
/**
* Returns the mapper of the entity.
*
* @return Doctrine_Mapper
*/
public function getMapper()
{
......
......@@ -6,6 +6,7 @@
*
* @package Doctrine
* @author Roman Borschel <roman@code-factory.org>
* @todo Remove or is there use for such a class in the DBAL?
*/
class Doctrine_Table extends Doctrine_Configurable implements Serializable
{
......
<?php
$fixture = array(
'model' => 'ForumAdministrator',
'rows' => array(
array(
'id' => 1,
'foo' => 'bar'
),
array(
'id' => 2,
'foo' => 'bar2'
)
)
);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment