1
0
mirror of synced 2024-12-12 22:36:02 +03:00

refactorings

This commit is contained in:
romanb 2008-03-17 13:26:34 +00:00
parent d3a261526e
commit 71ed924213
29 changed files with 541 additions and 1712 deletions

View File

@ -55,7 +55,7 @@ final class Doctrine
/**
* VERSION
*/
const VERSION = '1.0.0';
const VERSION = '2.0.0';
/**
* ERROR CONSTANTS
@ -171,46 +171,48 @@ final class Doctrine
* Doctrine constants
*/
const ATTR_LISTENER = 100;
const ATTR_QUOTE_IDENTIFIER = 101;
const ATTR_FIELD_CASE = 102;
const ATTR_IDXNAME_FORMAT = 103;
const ATTR_SEQNAME_FORMAT = 104;
const ATTR_SEQCOL_NAME = 105;
const ATTR_CMPNAME_FORMAT = 118;
const ATTR_DBNAME_FORMAT = 117;
const ATTR_TBLCLASS_FORMAT = 119;
const ATTR_TBLNAME_FORMAT = 120;
const ATTR_EXPORT = 140;
const ATTR_DECIMAL_PLACES = 141;
const ATTR_PORTABILITY = 106;
const ATTR_VALIDATE = 107;
const ATTR_COLL_KEY = 108;
const ATTR_QUERY_LIMIT = 109;
const ATTR_DEFAULT_TABLE_TYPE = 112;
const ATTR_DEF_TEXT_LENGTH = 113;
const ATTR_DEF_VARCHAR_LENGTH = 114;
const ATTR_DEF_TABLESPACE = 115;
const ATTR_EMULATE_DATABASE = 116;
const ATTR_USE_NATIVE_ENUM = 117;
const ATTR_DEFAULT_SEQUENCE = 133;
const ATTR_FETCHMODE = 118;
const ATTR_NAME_PREFIX = 121;
const ATTR_CREATE_TABLES = 122;
const ATTR_COLL_LIMIT = 123;
const ATTR_CACHE = 150;
const ATTR_RESULT_CACHE = 150;
const ATTR_CACHE_LIFESPAN = 151;
const ATTR_RESULT_CACHE_LIFESPAN = 151;
const ATTR_LOAD_REFERENCES = 153;
const ATTR_QUOTE_IDENTIFIER = 101; // manager/session attribute
const ATTR_FIELD_CASE = 102; // manager/session attribute
const ATTR_IDXNAME_FORMAT = 103; // manager/session attribute
const ATTR_SEQNAME_FORMAT = 104; // manager/session attribute
const ATTR_SEQCOL_NAME = 105; // class attribute
const ATTR_CMPNAME_FORMAT = 118; // ??
const ATTR_DBNAME_FORMAT = 117; // manager/session attribute
const ATTR_TBLCLASS_FORMAT = 119; // manager/session attribute
const ATTR_TBLNAME_FORMAT = 120; // manager/session attribute
const ATTR_EXPORT = 140; // manager/session attribute
const ATTR_DECIMAL_PLACES = 141; // manager/session attribute
const ATTR_PORTABILITY = 106; // manager/session attribute
const ATTR_VALIDATE = 107; // manager/session attribute
const ATTR_COLL_KEY = 108; // class attribute
const ATTR_QUERY_LIMIT = 109; // manager/session attribute
const ATTR_DEFAULT_TABLE_TYPE = 112; // manager/session attribute
const ATTR_DEF_TEXT_LENGTH = 113; // manager/session attribute
const ATTR_DEF_VARCHAR_LENGTH = 114; // manager/session attribute
const ATTR_DEF_TABLESPACE = 115; // manager/session attribute
const ATTR_EMULATE_DATABASE = 116; // manager/session attribute
const ATTR_USE_NATIVE_ENUM = 117; // manager/session attribute
const ATTR_DEFAULT_SEQUENCE = 133; // ??
const ATTR_FETCHMODE = 118; // deprecated
const ATTR_NAME_PREFIX = 121; // ??
const ATTR_CREATE_TABLES = 122; // manager/session attribute
const ATTR_COLL_LIMIT = 123; // manager/session attribute
const ATTR_CACHE = 150; // deprecated
const ATTR_RESULT_CACHE = 150; // manager/session attribute
const ATTR_CACHE_LIFESPAN = 151; // deprecated
const ATTR_RESULT_CACHE_LIFESPAN = 151; // manager/session attribute
const ATTR_LOAD_REFERENCES = 153; // class attribute
const ATTR_RECORD_LISTENER = 154;
const ATTR_THROW_EXCEPTIONS = 155;
const ATTR_DEFAULT_PARAM_NAMESPACE = 156;
const ATTR_QUERY_CACHE = 157;
const ATTR_QUERY_CACHE_LIFESPAN = 158;
const ATTR_MODEL_LOADING = 161;
const ATTR_LOCK = 162;
const ATTR_HYDRATE = 163;
const ATTR_IDENTIFIER = 164;
const ATTR_THROW_EXCEPTIONS = 155; // manager/session attribute
const ATTR_DEFAULT_PARAM_NAMESPACE = 156; // ??
const ATTR_QUERY_CACHE = 157; // manager/session attribute
const ATTR_QUERY_CACHE_LIFESPAN = 158; // manager/session attribute
const ATTR_MODEL_LOADING = 161; // manager/session attribute
const ATTR_LOCK = 162; // ??
const ATTR_HYDRATE = 163; // ??
const ATTR_IDENTIFIER = 164; // ??
const ATTR_METADATA_CACHE = 165; // manager/session attribute
const ATTR_METADATA_CACHE_LIFESPAN = 166; // manager/session attribute
/**
* QUERY_LIMIT CONSTANTS
@ -281,6 +283,7 @@ final class Doctrine
* FETCHMODE_VHOLDER
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_VHOLDER = 1;
@ -293,6 +296,7 @@ final class Doctrine
* This is the default fetchmode.
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_RECORD = 2;
@ -300,6 +304,7 @@ final class Doctrine
* FETCHMODE_ARRAY
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_ARRAY = 3;
@ -493,6 +498,7 @@ final class Doctrine
* VALIDATE_CONSTRAINTS
*
* @see self::ATTR_VALIDATE
* Not used? Purpose?
*/
const VALIDATE_CONSTRAINTS = 4;
@ -557,7 +563,7 @@ final class Doctrine
*
* @see self::ATTR_MODEL_LOADING
*/
const MODEL_LOADING_CONSERVATIVE= 2;
const MODEL_LOADING_CONSERVATIVE = 2;
/**
* INHERITANCE TYPE CONSTANTS.
@ -583,7 +589,7 @@ final class Doctrine
* @see http://martinfowler.com/eaaCatalog/concreteTableInheritance.html
*/
const INHERITANCETYPE_TABLE_PER_CLASS = 3;
/**
* Path
@ -763,8 +769,7 @@ final class Doctrine
// - not a subclass of Doctrine_Record
// - don't have a setTableDefinition method
if (!$class->isAbstract() &&
$class->isSubClassOf('Doctrine_Record') &&
$class->hasMethod('setTableDefinition')) {
$class->isSubClassOf('Doctrine_Record')) {
return true;
}

View File

@ -20,8 +20,8 @@
*/
/**
* A <tt>ClassMetadata</tt> instance holds all the information (metadata) of an entity and it's relations.
* These informations are used for the proper object-relational mapping of the class.
* A <tt>ClassMetadata</tt> instance holds all the information (metadata) of an entity and
* it's associations and how they're mapped to the relational model.
*
* @package Doctrine
* @subpackage ClassMetadata
@ -48,6 +48,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* The name of the custom mapper class used for the entity class.
* (Optional).
*
* @var string
*/
@ -60,7 +61,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
protected $_conn;
/**
* The names of the parent classes.
* The names of the parent classes (ancestors).
*/
protected $_parentClasses = array();
@ -75,13 +76,14 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* The identifier type of the class.
*
* @see Doctrine_Identifier constants
* @see Doctrine::IDENTIFIER_* constants
* @var integer
*/
protected $_identifierType;
/**
* The inheritance mapping type used by the class.
*
*
* @var integer
*/
@ -115,9 +117,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* The mapped columns and their mapping definitions.
* Keys are column names and values are definitions.
* Keys are column names and values are mapping definitions.
*
* The definition array has atleast the following values:
* The mapping definition array has at least the following values:
*
* -- type the column type, eg. 'integer'
* -- length the column length, eg. 11
@ -156,11 +158,6 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
protected $_enumValues = array();
/**
* @todo Implementation.
*/
protected $_readOnlyFieldNames = array();
/**
* Tree object associated with the class.
*
@ -219,8 +216,10 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* Inheritance options.
*/
protected $_inheritanceOptions = array(
// JOINED & TABLE_PER_CLASS options
'discriminatorColumn' => null,
'discriminatorMap' => array(),
// JOINED options
'joinSubclasses' => true
);
@ -261,9 +260,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* Constructs a new metadata instance.
* Constructs a new ClassMetadata instance.
*
* @param string $domainClassName Name of the class the metadata instance is used for.
* @param string $entityName Name of the entity class the metadata info is used for.
*/
public function __construct($entityName, Doctrine_Connection $conn)
{
@ -272,7 +271,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$this->_conn = $conn;
$this->_parser = new Doctrine_Relation_Parser($this);
$this->_filters[] = new Doctrine_Record_Filter_Standard();
$this->setParent($this->_conn);
$this->setConfigurableParent($this->_conn);
}
/**
@ -286,13 +285,20 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* getComponentName
*
* @return void
* @return string
*/
public function getClassName()
{
return $this->_entityName;
}
/**
* Gets the name of the root class of the entity hierarchy. If the entity described
* by the ClassMetadata is not participating in a hierarchy, this is the same as the
* name returned by {@link getClassName()}.
*
* @return string
*/
public function getRootClassName()
{
return $this->_rootEntityName;
@ -315,7 +321,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public function isIdentifier($fieldName)
{
return in_array($fieldName, (array)$this->getIdentifier());
return in_array($fieldName, $this->getIdentifier());
}
/**
@ -353,10 +359,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* @param string $name the name of the option to set
* @param mixed $value the value of the option
* @return Doctrine_Table this object
* @deprecated
*/
public function setOption($name, $value)
{
switch ($name) {
/*switch ($name) {
case 'tableName':
case 'index':
case 'sequenceName':
@ -368,7 +375,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
case 'enumMap':
$this->_enumMap = $value;
return;
}
}*/
$this->_options[$name] = $value;
}
@ -457,11 +464,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public function getColumnName($fieldName)
{
if (isset($this->_columnNames[$fieldName])) {
return $this->_columnNames[$fieldName];
}
return $fieldName;
return isset($this->_columnNames[$fieldName]) ?
$this->_columnNames[$fieldName] : $fieldName;
}
/**
@ -481,21 +485,21 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* getFieldName
*
* returns a column alias for a column name
* if no alias can be found the column name is returned.
* returns the field name for a column name
* if no field name can be found the column name is returned.
*
* @param string $columnName column name
* @return string column alias
*/
public function getFieldName($columnName)
{
if (isset($this->_fieldNames[$columnName])) {
return $this->_fieldNames[$columnName];
}
return $columnName;
return isset($this->_fieldNames[$columnName]) ?
$this->_fieldNames[$columnName] : $columnName;
}
/**
* @deprecated
*/
public function setColumns(array $definitions)
{
foreach ($definitions as $name => $options) {
@ -1792,6 +1796,21 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this;
}
public function hasAttribute($key)
{
switch ($key) {
case Doctrine::ATTR_SEQCOL_NAME:
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_VALIDATE:
return true;
default:
return false;
}
}
/**

View File

@ -20,9 +20,9 @@
*/
Doctrine::autoload('Doctrine_Access');
/**
* A Doctrine_Collection represents a collection of record objects.
* A Doctrine_Collection represents a collection of entities.
* A collection object is strongly typed in the sense that it can only contain
* records of a specific type or one it's subtypes.
* entities of a specific type or one it's subtypes.
*
* @package Doctrine
* @subpackage Collection
@ -113,7 +113,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
if ($keyColumn === null) {
$keyColumn = $mapper->getAttribute(Doctrine::ATTR_COLL_KEY);
$keyColumn = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY);
}
if ($keyColumn !== null) {

View File

@ -21,7 +21,6 @@
/**
* Doctrine_Configurable
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Connection
*
*
* @package Doctrine
@ -37,7 +36,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
/**
* @var array $attributes an array of containing all attributes
*/
protected $attributes = array();
protected $_attributes = array();
/**
* @var Doctrine_Configurable $parent the parent of this component
@ -49,12 +48,12 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
* keys as template names and values as names of the concrete
* implementation classes
*/
protected $_impl = array();
//protected $_impl = array();
/**
* @var array $_params an array of user defined parameters
*/
protected $_params = array();
//protected $_params = array();
/**
* setAttribute
@ -88,7 +87,6 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
if (defined($const)) {
$attribute = constant($const);
$this->_state = $attribute;
} else {
throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"');
}
@ -105,12 +103,12 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
}
switch ($attribute) {
case Doctrine::ATTR_FETCHMODE:
case Doctrine::ATTR_FETCHMODE: // deprecated
throw new Doctrine_Exception('Deprecated attribute. See http://www.phpdoctrine.org/documentation/manual?chapter=configuration');
case Doctrine::ATTR_LISTENER:
$this->setEventListener($value);
break;
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_COLL_KEY: // class attribute
if ( ! ($this instanceof Doctrine_ClassMetadata)) {
throw new Doctrine_Exception("This attribute can only be set at class level.");
}
@ -118,58 +116,58 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
throw new Doctrine_Exception("Couldn't set collection key attribute. No such field '$value'");
}
break;
case Doctrine::ATTR_CACHE:
case Doctrine::ATTR_RESULT_CACHE:
case Doctrine::ATTR_QUERY_CACHE:
case Doctrine::ATTR_CACHE: // deprecated
case Doctrine::ATTR_RESULT_CACHE:// manager/session attribute
case Doctrine::ATTR_QUERY_CACHE: // manager/session attribute
if ($value !== null) {
if ( ! ($value instanceof Doctrine_Cache_Interface)) {
throw new Doctrine_Exception('Cache driver should implement Doctrine_Cache_Interface');
}
}
break;
case Doctrine::ATTR_VALIDATE:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_EMULATE_DATABASE:
case Doctrine::ATTR_USE_NATIVE_ENUM:
case Doctrine::ATTR_DEFAULT_SEQUENCE:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_DECIMAL_PLACES:
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_RECORD_LISTENER:
case Doctrine::ATTR_THROW_EXCEPTIONS:
case Doctrine::ATTR_VALIDATE: // manager/session attribute
case Doctrine::ATTR_QUERY_LIMIT: // manager/session attribute
case Doctrine::ATTR_QUOTE_IDENTIFIER: // manager/session attribute
case Doctrine::ATTR_PORTABILITY: // manager/session attribute
case Doctrine::ATTR_DEFAULT_TABLE_TYPE: // manager/session attribute
case Doctrine::ATTR_EMULATE_DATABASE: // manager/session attribute
case Doctrine::ATTR_USE_NATIVE_ENUM: // manager/session attribute
case Doctrine::ATTR_DEFAULT_SEQUENCE: // ??
case Doctrine::ATTR_EXPORT: // manager/session attribute
case Doctrine::ATTR_DECIMAL_PLACES: // manager/session attribute
case Doctrine::ATTR_LOAD_REFERENCES: // class attribute
case Doctrine::ATTR_RECORD_LISTENER: // not an attribute
case Doctrine::ATTR_THROW_EXCEPTIONS: // manager/session attribute
case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE:
case Doctrine::ATTR_MODEL_LOADING:
case Doctrine::ATTR_MODEL_LOADING: // manager/session attribute
break;
case Doctrine::ATTR_SEQCOL_NAME:
case Doctrine::ATTR_SEQCOL_NAME: // class attribute
if ( ! is_string($value)) {
throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
}
break;
case Doctrine::ATTR_FIELD_CASE:
case Doctrine::ATTR_FIELD_CASE: // manager/session attribute
if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER)
throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.');
break;
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_IDXNAME_FORMAT:
case Doctrine::ATTR_TBLNAME_FORMAT:
if ($this instanceof Doctrine_Table) {
case Doctrine::ATTR_SEQNAME_FORMAT: // manager/session attribute
case Doctrine::ATTR_IDXNAME_FORMAT: // manager/session attribute
case Doctrine::ATTR_TBLNAME_FORMAT: // manager/session attribute
if ($this instanceof Doctrine_ClassMetadata) {
throw new Doctrine_Exception('Sequence / index name format attributes cannot be set'
. 'at table level (only at connection or global level).');
. ' at class level (only at connection or global level).');
}
break;
default:
throw new Doctrine_Exception("Unknown attribute.");
}
$this->attributes[$attribute] = $value;
$this->_attributes[$attribute] = $value;
}
public function getParams($namespace = null)
/*public function getParams($namespace = null)
{
if ($namespace == null) {
$namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE);
@ -180,14 +178,14 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
}
return $this->_params[$namespace];
}
}*/
public function getParamNamespaces()
/*public function getParamNamespaces()
{
return array_keys($this->_params);
}
}*/
public function setParam($name, $value, $namespace = null)
/*public function setParam($name, $value, $namespace = null)
{
if ($namespace == null) {
$namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE);
@ -196,9 +194,9 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
$this->_params[$namespace][$name] = $value;
return $this;
}
}*/
public function getParam($name, $value, $namespace)
/*public function getParam($name, $value, $namespace)
{
if ($namespace == null) {
$namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE);
@ -211,7 +209,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
return null;
}
return $this->_params[$name];
}
}*/
/**
* setImpl
@ -223,12 +221,12 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
* @param string $class name of the class to be bound
* @return Doctrine_Configurable this object
*/
public function setImpl($template, $class)
/*public function setImpl($template, $class)
{
$this->_impl[$template] = $class;
return $this;
}
}*/
/**
* getImpl
@ -236,7 +234,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
*
* @return string name of the concrete implementation
*/
public function getImpl($template)
/*public function getImpl($template)
{
if ( ! isset($this->_impl[$template])) {
if (isset($this->parent)) {
@ -245,10 +243,10 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
return null;
}
return $this->_impl[$template];
}
}*/
public function hasImpl($template)
/*public function hasImpl($template)
{
if ( ! isset($this->_impl[$template])) {
if (isset($this->parent)) {
@ -257,7 +255,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
return false;
}
return true;
}
}*/
/**
* @param Doctrine_EventListener $listener
@ -276,12 +274,12 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
*/
public function addRecordListener($listener, $name = null)
{
if ( ! isset($this->attributes[Doctrine::ATTR_RECORD_LISTENER]) ||
! ($this->attributes[Doctrine::ATTR_RECORD_LISTENER] instanceof Doctrine_Record_Listener_Chain)) {
if ( ! isset($this->_attributes[Doctrine::ATTR_RECORD_LISTENER]) ||
! ($this->_attributes[Doctrine::ATTR_RECORD_LISTENER] instanceof Doctrine_Record_Listener_Chain)) {
$this->attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener_Chain();
$this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener_Chain();
}
$this->attributes[Doctrine::ATTR_RECORD_LISTENER]->add($listener, $name);
$this->_attributes[Doctrine::ATTR_RECORD_LISTENER]->add($listener, $name);
return $this;
}
@ -293,13 +291,13 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
*/
public function getRecordListener()
{
if ( ! isset($this->attributes[Doctrine::ATTR_RECORD_LISTENER])) {
if ( ! isset($this->_attributes[Doctrine::ATTR_RECORD_LISTENER])) {
if (isset($this->parent)) {
return $this->parent->getRecordListener();
}
$this->attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener();
$this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener();
}
return $this->attributes[Doctrine::ATTR_RECORD_LISTENER];
return $this->_attributes[Doctrine::ATTR_RECORD_LISTENER];
}
/**
@ -315,15 +313,15 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
) {
throw new Doctrine_Exception("Couldn't set eventlistener. Record listeners should implement either Doctrine_Record_Listener_Interface or Doctrine_Overloadable");
}
$this->attributes[Doctrine::ATTR_RECORD_LISTENER] = $listener;
$this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = $listener;
return $this;
}
/*
public function removeRecordListeners()
{
$this->attributes[Doctrine::ATTR_RECORD_LISTENER] =
}*/
$this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = null;
}
/**
* addListener
@ -333,12 +331,12 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
*/
public function addListener($listener, $name = null)
{
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER]) ||
! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
if ( ! isset($this->_attributes[Doctrine::ATTR_LISTENER]) ||
! ($this->_attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
$this->_attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
}
$this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
$this->_attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
return $this;
}
@ -350,13 +348,13 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
*/
public function getListener()
{
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if ( ! isset($this->_attributes[Doctrine::ATTR_LISTENER])) {
if (isset($this->parent)) {
return $this->parent->getListener();
}
return null;
}
return $this->attributes[Doctrine::ATTR_LISTENER];
return $this->_attributes[Doctrine::ATTR_LISTENER];
}
/**
@ -371,7 +369,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
&& ! ($listener instanceof Doctrine_Overloadable)) {
throw new Doctrine_EventListener_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
}
$this->attributes[Doctrine::ATTR_LISTENER] = $listener;
$this->_attributes[Doctrine::ATTR_LISTENER] = $listener;
return $this;
}
@ -391,7 +389,6 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
if (defined($const)) {
$attribute = constant($const);
$this->_state = $attribute;
} else {
throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"');
}
@ -403,8 +400,8 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
throw new Doctrine_Exception('Unknown attribute.');
}
if (isset($this->attributes[$attribute])) {
return $this->attributes[$attribute];
if (isset($this->_attributes[$attribute])) {
return $this->_attributes[$attribute];
}
if (isset($this->parent)) {
@ -421,7 +418,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
*/
public function getAttributes()
{
return $this->attributes;
return $this->_attributes;
}
/**
@ -431,7 +428,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
* @param Doctrine_Configurable $component
* @return void
*/
public function setParent(Doctrine_Configurable $component)
public function setConfigurableParent(Doctrine_Configurable $component)
{
$this->parent = $component;
}

View File

@ -53,6 +53,9 @@ Doctrine::autoload('Doctrine_Configurable');
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (MDB2 library)
* @author Roman Borschel <roman@code-factory.org>
* @todo Split up into Doctrine::DBAL::Connection & Doctrine::ORM::EntityManager.
* Doctrine::DBAL::Connection must have no dependencies on ORM components since
* it sits one layer below.
*/
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate
{
@ -229,7 +232,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
$this->setParent($manager);
$this->setConfigurableParent($manager);
$this->setAttribute(Doctrine::ATTR_CASE, Doctrine::CASE_NATURAL);
$this->setAttribute(Doctrine::ATTR_ERRMODE, Doctrine::ERRMODE_EXCEPTION);
@ -275,10 +278,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function getAttribute($attribute)
{
if ($attribute >= 100) {
if ( ! isset($this->attributes[$attribute])) {
if ( ! isset($this->_attributes[$attribute])) {
return parent::getAttribute($attribute);
}
return $this->attributes[$attribute];
return $this->_attributes[$attribute];
}
if ($this->isConnected) {
@ -1563,4 +1566,48 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
return Doctrine_Lib::getConnectionAsString($this);
}
public function hasAttribute($key)
{
switch ($key) {
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_LISTENER:
case Doctrine::ATTR_RECORD_LISTENER:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_SEQCOL_NAME:
case Doctrine::ATTR_FIELD_CASE:
case Doctrine::ATTR_IDXNAME_FORMAT:
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_DBNAME_FORMAT:
case Doctrine::ATTR_TBLCLASS_FORMAT:
case Doctrine::ATTR_TBLNAME_FORMAT:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_DECIMAL_PLACES:
case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_VALIDATE:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_DEF_TEXT_LENGTH:
case Doctrine::ATTR_DEF_VARCHAR_LENGTH:
case Doctrine::ATTR_DEF_TABLESPACE:
case Doctrine::ATTR_EMULATE_DATABASE:
case Doctrine::ATTR_USE_NATIVE_ENUM:
case Doctrine::ATTR_CREATE_TABLES:
case Doctrine::ATTR_COLL_LIMIT:
case Doctrine::ATTR_CACHE: // deprecated
case Doctrine::ATTR_RESULT_CACHE:
case Doctrine::ATTR_CACHE_LIFESPAN: // deprecated
case Doctrine::ATTR_RESULT_CACHE_LIFESPAN:
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_THROW_EXCEPTIONS:
case Doctrine::ATTR_QUERY_CACHE:
case Doctrine::ATTR_QUERY_CACHE_LIFESPAN:
case Doctrine::ATTR_MODEL_LOADING:
case Doctrine::ATTR_METADATA_CACHE:
case Doctrine::ATTR_METADATA_CACHE_LIFESPAN:
return true;
default:
return false;
}
}
}

View File

@ -38,8 +38,9 @@ class Doctrine_Connection_Common extends Doctrine_Connection
* @param string $query
* @param mixed $limit
* @param mixed $offset
* @todo 4th parameter not used? Remove?
*/
public function modifyLimitQuery($query, $limit = false,$offset = false,$isManip=false)
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{
$limit = (int) $limit;
$offset = (int) $offset;

View File

@ -106,9 +106,9 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// Initialize
foreach ($this->_queryComponents as $dqlAlias => $component) {
// disable lazy-loading of related elements during hydration
$component['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
$component['table']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
$componentName = $component['mapper']->getComponentName();
$listeners[$componentName] = $component['mapper']->getRecordListener();
$listeners[$componentName] = $component['table']->getRecordListener();
$identifierMap[$dqlAlias] = array();
$prev[$dqlAlias] = array();
$id[$dqlAlias] = '';
@ -121,7 +121,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
$rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
//
// hydrate the data of the root component from the current row
// hydrate the data of the root entity from the current row
//
$table = $this->_queryComponents[$rootAlias]['table'];
$mapper = $this->_queryComponents[$rootAlias]['mapper'];
@ -162,9 +162,10 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// $prev[$rootAlias] now points to the last element in $result.
// now hydrate the rest of the data found in the current row, that belongs to other
// (related) components.
$oneToOne = false;
foreach ($rowData as $dqlAlias => $data) {
$index = false;
$oneToOne = false;
$map = $this->_queryComponents[$dqlAlias];
$table = $map['table'];
$mapper = $map['mapper'];
@ -181,7 +182,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
$path = $parent . '.' . $dqlAlias;
if ( ! isset($prev[$parent])) {
break;
continue;
}
// check the type of the relation
@ -232,7 +233,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// re-enable lazy loading
foreach ($this->_queryComponents as $dqlAlias => $data) {
$data['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true);
$data['table']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true);
}
//$e = microtime(true);

View File

@ -122,11 +122,57 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
}
return false;
}
public function hasAttribute($key)
{
switch ($key) {
case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE:
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_SEQCOL_NAME:
case Doctrine::ATTR_LISTENER:
case Doctrine::ATTR_RECORD_LISTENER:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_FIELD_CASE:
case Doctrine::ATTR_IDXNAME_FORMAT:
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_DBNAME_FORMAT:
case Doctrine::ATTR_TBLCLASS_FORMAT:
case Doctrine::ATTR_TBLNAME_FORMAT:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_DECIMAL_PLACES:
case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_VALIDATE:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_DEF_TEXT_LENGTH:
case Doctrine::ATTR_DEF_VARCHAR_LENGTH:
case Doctrine::ATTR_DEF_TABLESPACE:
case Doctrine::ATTR_EMULATE_DATABASE:
case Doctrine::ATTR_USE_NATIVE_ENUM:
case Doctrine::ATTR_CREATE_TABLES:
case Doctrine::ATTR_COLL_LIMIT:
case Doctrine::ATTR_CACHE: // deprecated
case Doctrine::ATTR_RESULT_CACHE:
case Doctrine::ATTR_CACHE_LIFESPAN: // deprecated
case Doctrine::ATTR_RESULT_CACHE_LIFESPAN:
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_THROW_EXCEPTIONS:
case Doctrine::ATTR_QUERY_CACHE:
case Doctrine::ATTR_QUERY_CACHE_LIFESPAN:
case Doctrine::ATTR_MODEL_LOADING:
case Doctrine::ATTR_METADATA_CACHE:
case Doctrine::ATTR_METADATA_CACHE_LIFESPAN:
return true;
default:
return false;
}
}
/**
* returns the root directory of Doctrine
*
* @return string
* @todo Better name.
*/
final public function getRoot()
{

View File

@ -31,11 +31,12 @@
* @link www.phpdoctrine.org
* @since 1.0
*/
class Doctrine_Mapper extends Doctrine_Configurable implements Countable
class Doctrine_Mapper
{
/**
* @var Doctrine_Table Metadata container that represents the database table this
* mapper is mapping objects to.
* Metadata object that descibes the mapping of the mapped entity class.
*
* @var Doctrine_ClassMetadata
*/
protected $_classMetadata;
@ -61,6 +62,16 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
* @todo Move to UnitOfWork.
*/
protected $_identityMap = array();
/**
* Null object.
*/
private $_nullObject;
/**
* A list of registered entity listeners.
*/
private $_entityListeners = array();
/**
@ -71,19 +82,11 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
* @throws Doctrine_Connection_Exception if there are no opened connections
*/
public function __construct($name, Doctrine_ClassMetadata $classMetadata)
{
if ($name != $classMetadata->getClassName()) {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br/><br/>";
}
}
{
$this->_domainClassName = $name;
$this->_conn = $classMetadata->getConnection();
$this->_classMetadata = $classMetadata;
$this->setParent($this->_conn);
$this->_nullObject = Doctrine_Null::getInstance();
if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) {
$this->_mappingStrategy = new Doctrine_Mapper_JoinedStrategy($this);
} else {
@ -91,34 +94,6 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
}
}
/**
* export
* exports this table to database based on column and option definitions
*
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
* occurred during the create table operation
* @return boolean whether or not the export operation was successful
* false if table already existed in the database
* @deprecated
* @todo Remove
*/
/*public function export()
{
$this->_conn->export->exportTable($this->_table);
}*/
/**
* getExportableFormat
* returns exportable presentation of this object
*
* @return array
* @todo move to Table
*/
/*public function getExportableFormat($parseForeignKeys = true)
{
return $this->_table->getExportableFormat($parseForeignKeys);
}*/
/**
* createQuery
* creates a new Doctrine_Query object and adds the component name
@ -146,7 +121,6 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
public function setConnection(Doctrine_Connection $conn)
{
$this->_conn = $conn;
$this->setParent($this->_conn);
return $this;
}
@ -175,6 +149,34 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
return $record;
}
public function addEntityListener(Doctrine_Record_Listener $listener)
{
if ( ! in_array($listener, $this->_entityListeners)) {
$this->_entityListeners[] = $listener;
return true;
}
return false;
}
public function removeEntityListener(Doctrine_Record_Listener $listener)
{
if ($key = array_search($listener, $this->_entityListeners, true)) {
unset($this->_entityListeners[$key]);
return true;
}
return false;
}
public function notifyEntityListeners(Doctrine_Record $entity, $callback, $eventType)
{
if ($this->_entityListeners) {
$event = new Doctrine_Event($entity, $eventType);
foreach ($this->_entityListeners as $listener) {
$listener->$callback($event);
}
}
}
public function detach(Doctrine_Record $entity)
{
return $this->_conn->unitOfWork->detach($entity);
@ -425,18 +427,6 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
return $where;
}
/**
* count
*
* @return integer
*/
public function count()
{
$a = $this->_conn->execute('SELECT COUNT(1) FROM ' . $this->_classMetadata->getTableName())
->fetch(Doctrine::FETCH_NUM);
return current($a);
}
/**
* prepareValue
* this method performs special data preparation depending on
@ -465,8 +455,8 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
*/
public function prepareValue($fieldName, $value, $typeHint = null)
{
if ($value === self::$_null) {
return self::$_null;
if ($value === $this->_nullObject) {
return $this->_nullObject;
} else if ($value === null) {
return null;
} else {
@ -619,6 +609,11 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
} else {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br/><br/>";
}
throw new Doctrine_Mapper_Exception("Undefined method '$method'.");
}
@ -716,28 +711,25 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
*/
protected function _insertOrUpdate(Doctrine_Record $record)
{
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_SAVE);
$record->preSave($event);
$this->getRecordListener()->preSave($event);
$record->preSave();
$this->notifyEntityListeners($record, 'preSave', Doctrine_Event::RECORD_SAVE);
if ( ! $event->skipOperation) {
switch ($record->state()) {
case Doctrine_Record::STATE_TDIRTY:
$this->_insert($record);
break;
case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_PROXY:
$this->_update($record);
break;
case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_TCLEAN:
// do nothing
break;
}
switch ($record->state()) {
case Doctrine_Record::STATE_TDIRTY:
$this->_insert($record);
break;
case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_PROXY:
$this->_update($record);
break;
case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_TCLEAN:
// do nothing
break;
}
$this->getRecordListener()->postSave($event);
$record->postSave($event);
$record->postSave();
$this->notifyEntityListeners($record, 'postSave', Doctrine_Event::RECORD_SAVE);
}
/**
@ -844,17 +836,14 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
*/
protected function _update(Doctrine_Record $record)
{
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE);
$record->preUpdate($event);
$table = $this->_classMetadata;
$this->getRecordListener()->preUpdate($event);
if ( ! $event->skipOperation) {
$this->_mappingStrategy->doUpdate($record);
}
$record->preUpdate();
$this->notifyEntityListeners($record, 'preUpdate', Doctrine_Event::RECORD_UPDATE);
$this->getRecordListener()->postUpdate($event);
$record->postUpdate($event);
$table = $this->_classMetadata;
$this->_mappingStrategy->doUpdate($record);
$record->postUpdate();
$this->notifyEntityListeners($record, 'postUpdate', Doctrine_Event::RECORD_UPDATE);
return true;
}
@ -866,20 +855,15 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
* @return boolean
*/
protected function _insert(Doctrine_Record $record)
{
// trigger event
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_INSERT);
$record->preInsert($event);
$this->getRecordListener()->preInsert($event);
{
$record->preInsert();
$this->notifyEntityListeners($record, 'preInsert', Doctrine_Event::RECORD_INSERT);
if ( ! $event->skipOperation) {
$this->_mappingStrategy->doInsert($record);
}
// trigger event
$this->_mappingStrategy->doInsert($record);
$this->addRecord($record);
$this->getRecordListener()->postInsert($event);
$record->postInsert($event);
$record->postInsert();
$this->notifyEntityListeners($record, 'postInsert', Doctrine_Event::RECORD_INSERT);
return true;
}
@ -907,28 +891,35 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
$conn = $this->_conn;
}
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_DELETE);
$record->preDelete($event);
$this->getRecordListener()->preDelete($event);
$record->preDelete();
$this->notifyEntityListeners($record, 'preDelete', Doctrine_Event::RECORD_DELETE);
$table = $this->_classMetadata;
$state = $record->state();
$record->state(Doctrine_Record::STATE_LOCKED);
if ( ! $event->skipOperation) {
$this->_mappingStrategy->doDelete($record);
} else {
// return to original state
$record->state($state);
}
$this->_mappingStrategy->doDelete($record);
$this->getRecordListener()->postDelete($event);
$record->postDelete($event);
$record->postDelete();
$this->notifyEntityListeners($record, 'postDelete', Doctrine_Event::RECORD_DELETE);
return true;
}
public function hasAttribute($key)
{
switch ($key) {
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_VALIDATE:
return true;
default:
return false;
}
}
public function executeQuery(Doctrine_Query $query)
{
@ -959,7 +950,7 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
$this->_mappingStrategy = null;
}
public function getMappingStrategy()
public function getMapping()
{
return $this->_mappingStrategy;
}
@ -976,9 +967,9 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
return $this->_mappingStrategy->getFieldNames();
}
public function getOwningTable($fieldName)
public function getOwningClass($fieldName)
{
return $this->_mappingStrategy->getOwningTable($fieldName);
return $this->_mappingStrategy->getOwningClass($fieldName);
}
/* Hooks used during SQL query construction to manipulate the query. */

View File

@ -238,15 +238,7 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
return $this->_columnNameFieldNameMap[$columnName];
}
foreach ($classMetadata->getParentClasses() as $parentClass) {
$parentTable = $conn->getClassMetadata($parentClass);
if ($parentTable->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $parentTable->getFieldName($columnName);
return $this->_columnNameFieldNameMap[$columnName];
}
}
foreach ((array)$classMetadata->getSubclasses() as $subClass) {
foreach ($classMetadata->getSubclasses() as $subClass) {
$subTable = $conn->getClassMetadata($subClass);
if ($subTable->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $subTable->getFieldName($columnName);
@ -261,7 +253,7 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
*
* @todo Looks like this better belongs into the ClassMetadata class.
*/
public function getOwningTable($fieldName)
public function getOwningClass($fieldName)
{
$conn = $this->_mapper->getConnection();
$classMetadata = $this->_mapper->getClassMetadata();
@ -283,13 +275,14 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
}
}
throw new Doctrine_Mapper_Exception("Unable to find owner of field '$fieldName'.");
throw new Doctrine_Mapper_Exception("Unable to find defining class of field '$fieldName'.");
}
/**
* Analyzes the fields of the entity and creates a map in which the field names
* are grouped by the class names they belong to.
*
* @return array
*/
protected function _groupFieldsByDefiningClass(Doctrine_Record $record)
{

View File

@ -90,7 +90,7 @@ abstract class Doctrine_Mapper_Strategy
return $this->_fieldNames;
}
public function getOwningTable($fieldName)
public function getOwningClass($fieldName)
{
return $this->_mapper->getClassMetadata();
}

View File

@ -34,7 +34,18 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
final class Doctrine_Null
{
{
private static $_instance;
public function __construct() {}
public static function getInstance()
{
if (is_null(self::$_instance)) {
self::$_instance = new Doctrine_Null();
}
return self::$_instance;
}
public function exists()
{
return false;

View File

@ -470,7 +470,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$sql = array();
foreach ($fields as $fieldName) {
$table = $mapper->getOwningTable($fieldName);
$table = $mapper->getOwningClass($fieldName);
if ($table !== $baseTable) {
$tableAlias = $this->getSqlTableAlias($componentAlias . '.' . $table->getComponentName());
} else {

View File

@ -31,10 +31,8 @@ Doctrine::autoload('Doctrine_Record_Abstract');
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @todo Remove the depdency on the ClassMetadata. All operations that involve the metadata
* should be left to the mapper.
*/
abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Countable, IteratorAggregate, Serializable
abstract class Doctrine_Record extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
{
/**
* STATE CONSTANTS
@ -90,23 +88,40 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
/**
* Boolean flag that indicated whether automatic accessor overriding is enabled.
*
* @var boolean
*/
private static $_useAutoAccessorOverride;
/**
* The accessor cache is used as a memory for the existance of custom accessors
* for fields.
* Only used when ATTR_ACCESSOR_OVERRIDE is set to ACCESSOR_OVERRIDE_AUTO.
*
* @var array
*/
private static $_accessorCache = array();
/**
* The mutator cache is used as a memory for the existance of custom mutators
* for fields.
* Only used when ATTR_ACCESSOR_OVERRIDE is set to ACCESSOR_OVERRIDE_MANUAL.
*
* @var array
*/
private static $_mutatorCache = array();
/**
* The metadata container that describes the entity class.
*
* @var Doctrine_ClassMetadata
*/
protected $_class;
/**
*
* @var Doctrine_Mapper
*/
protected $_mapper;
/**
*
*/
@ -164,16 +179,16 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
protected $_errorStack;
/**
* The names of all relations.
* The references for all associations of the entity to other entities.
*
* @var array $_references
* @var array
*/
protected $_references = array();
/**
* The object identifier of the object. Each object has a unique identifier during runtime.
*
* @var integer $oid
* @var integer
*/
private $_oid;
@ -194,11 +209,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
if (isset($mapper) && $mapper instanceof Doctrine_Mapper) {
$class = get_class($this);
$this->_mapper = Doctrine_Manager::getInstance()->getMapper($class);
$this->_table = $this->_mapper->getClassMetadata();
$this->_class = $this->_mapper->getClassMetadata();
$exists = ! $isNewEntry;
} else {
$this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this));
$this->_table = $this->_mapper->getClassMetadata();
$this->_class = $this->_mapper->getClassMetadata();
$exists = false;
}
@ -228,7 +243,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->assignDefaultValues();
} else {
$this->_state = Doctrine_Record::STATE_CLEAN;
if ($count < $this->_table->getColumnCount()) {
if ($count < $this->_class->getColumnCount()) {
$this->_state = Doctrine_Record::STATE_PROXY;
}
}
@ -286,7 +301,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function isValid()
{
if ( ! $this->_mapper->getAttribute(Doctrine::ATTR_VALIDATE)) {
if ( ! $this->_class->getAttribute(Doctrine::ATTR_VALIDATE)) {
return true;
}
@ -334,56 +349,56 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function preSerialize(Doctrine_Event $event)
public function preSerialize()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function postSerialize(Doctrine_Event $event)
public function postSerialize()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function preUnserialize(Doctrine_Event $event)
public function preUnserialize()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function postUnserialize(Doctrine_Event $event)
public function postUnserialize()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function preSave(Doctrine_Event $event)
public function preSave()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function postSave(Doctrine_Event $event)
public function postSave()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function preDelete(Doctrine_Event $event)
public function preDelete()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function postDelete(Doctrine_Event $event)
public function postDelete()
{ }
/**
@ -391,7 +406,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* to hook into the saving procedure only when the record is going to be
* updated.
*/
public function preUpdate(Doctrine_Event $event)
public function preUpdate()
{ }
/**
@ -399,7 +414,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* to hook into the saving procedure only when the record is going to be
* updated.
*/
public function postUpdate(Doctrine_Event $event)
public function postUpdate()
{ }
/**
@ -407,7 +422,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* to hook into the saving procedure only when the record is going to be
* inserted into the data store the first time.
*/
public function preInsert(Doctrine_Event $event)
public function preInsert()
{ }
/**
@ -415,7 +430,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* to hook into the saving procedure only when the record is going to be
* inserted into the data store the first time.
*/
public function postInsert(Doctrine_Event $event)
public function postInsert()
{ }
/**
@ -460,11 +475,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function assignDefaultValues($overwrite = false)
{
if ( ! $this->_table->hasDefaultValues()) {
if ( ! $this->_class->hasDefaultValues()) {
return false;
}
foreach ($this->_data as $column => $value) {
$default = $this->_table->getDefaultValueOf($column);
$default = $this->_class->getDefaultValueOf($column);
if ($default === null) {
continue;
@ -532,11 +547,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
private function _extractIdentifier($exists = true)
{
switch ($this->_table->getIdentifierType()) {
switch ($this->_class->getIdentifierType()) {
case Doctrine::IDENTIFIER_AUTOINC:
case Doctrine::IDENTIFIER_SEQUENCE:
case Doctrine::IDENTIFIER_NATURAL:
$name = (array)$this->_table->getIdentifier();
$name = (array)$this->_class->getIdentifier();
$name = $name[0];
if ($exists) {
if (isset($this->_data[$name]) && $this->_data[$name] !== self::$_null) {
@ -545,7 +560,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
break;
case Doctrine::IDENTIFIER_COMPOSITE:
$names = (array)$this->_table->getIdentifier();
$names = (array)$this->_class->getIdentifier();
foreach ($names as $name) {
if ($this->_data[$name] === self::$_null) {
@ -583,12 +598,12 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_data = array_merge($this->_data, $this->_id);
foreach ($this->_data as $k => $v) {
if ($v instanceof Doctrine_Record && $this->_table->getTypeOf($k) != 'object') {
if ($v instanceof Doctrine_Record && $this->_class->getTypeOf($k) != 'object') {
unset($vars['_data'][$k]);
} else if ($v === self::$_null) {
unset($vars['_data'][$k]);
} else {
switch ($this->_table->getTypeOf($k)) {
switch ($this->_class->getTypeOf($k)) {
case 'array':
case 'object':
$vars['_data'][$k] = serialize($vars['_data'][$k]);
@ -597,7 +612,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$vars['_data'][$k] = gzcompress($vars['_data'][$k]);
break;
case 'enum':
$vars['_data'][$k] = $this->_table->enumIndex($k, $vars['_data'][$k]);
$vars['_data'][$k] = $this->_class->enumIndex($k, $vars['_data'][$k]);
break;
}
}
@ -638,10 +653,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->$k = $v;
}
$this->_table = $this->_mapper->getTable();
$this->_class = $this->_mapper->getTable();
foreach ($this->_data as $k => $v) {
switch ($this->_table->getTypeOf($k)) {
switch ($this->_class->getTypeOf($k)) {
case 'array':
case 'object':
$this->_data[$k] = unserialize($this->_data[$k]);
@ -650,7 +665,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_data[$k] = gzuncompress($this->_data[$k]);
break;
case 'enum':
$this->_data[$k] = $this->_table->enumValue($k, $this->_data[$k]);
$this->_data[$k] = $this->_class->enumValue($k, $this->_data[$k]);
break;
}
@ -734,7 +749,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
foreach (array_keys($this->_references) as $name) {
$query->leftJoin(get_class($this) . '.' . $name);
}
$query->where(implode(' = ? AND ', $this->_table->getIdentifierColumnNames()) . ' = ?');
$query->where(implode(' = ? AND ', $this->_class->getIdentifierColumnNames()) . ' = ?');
$this->clearRelated();
$record = $query->fetchOne($id);
} else {
@ -771,11 +786,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
public function refreshRelated($name = null)
{
if (is_null($name)) {
foreach ($this->_table->getRelations() as $rel) {
foreach ($this->_class->getRelations() as $rel) {
$this->_references[$rel->getAlias()] = $rel->fetchRelatedFor($this);
}
} else {
$rel = $this->_table->getRelation($name);
$rel = $this->_class->getRelation($name);
$this->_references[$name] = $rel->fetchRelatedFor($this);
}
}
@ -868,7 +883,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
self::$_accessorCache[$this->_entityName][$fieldName] = false;
}
}
if ($getter = $this->_table->getCustomAccessor($fieldName)) {
if ($getter = $this->_class->getCustomAccessor($fieldName)) {
self::$_accessorCache[$this->_entityName][$fieldName] = $getter;
} else if ( ! isset(self::$_accessorCache[$this->_entityName][$fieldName])) {
self::$_accessorCache[$this->_entityName][$fieldName] = false;
@ -900,12 +915,12 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
try {
if ( ! isset($this->_references[$fieldName]) && $load) {
$rel = $this->_table->getRelation($fieldName);
$rel = $this->_class->getRelation($fieldName);
$this->_references[$fieldName] = $rel->fetchRelatedFor($this);
}
return $this->_references[$fieldName];
} catch (Doctrine_Relation_Exception $e) {
foreach ($this->_table->getFilters() as $filter) {
foreach ($this->_class->getFilters() as $filter) {
if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) {
return $value;
}
@ -952,7 +967,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
if (isset($this->_data[$fieldName])) {
if ($value instanceof Doctrine_Record) {
$type = $this->_table->getTypeOf($fieldName);
$type = $this->_class->getTypeOf($fieldName);
$id = $value->getIncremented();
if ($id !== null && $type !== 'object') {
$value = $id;
@ -985,7 +1000,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
try {
$this->_coreSetRelated($fieldName, $value);
} catch (Doctrine_Relation_Exception $e) {
foreach ($this->_table->getFilters() as $filter) {
foreach ($this->_class->getFilters() as $filter) {
if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) {
return $value;
}
@ -1000,7 +1015,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
private function _coreSetRelated($name, $value)
{
$rel = $this->_table->getRelation($name);
$rel = $this->_class->getRelation($name);
// one-to-many or one-to-one relation
if ($rel instanceof Doctrine_Relation_ForeignKey ||
@ -1068,8 +1083,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
return true;
}
if (isset($this->_references[$fieldName]) &&
$this->_references[$fieldName] !== self::$_null) {
$this->_references[$fieldName] !== self::$_null) {
return true;
}
return false;
@ -1094,8 +1108,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
/**
* Applies the changes made to this object into database.
* This method also saves the related components.
* Saves the current state of the entity into the database.
* This method also saves associated entities.
*
* @param Doctrine_Connection $conn optional connection parameter
* @return void
@ -1147,7 +1161,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$conn = $this->_mapper->getConnection();
}
return $conn->replace($this->_table, $this->getPrepared(), $this->_id);
return $conn->replace($this->_class, $this->getPrepared(), $this->_id);
}
/**
@ -1195,7 +1209,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
foreach ($modifiedFields as $field) {
$type = $this->_table->getTypeOf($field);
$type = $this->_class->getTypeOf($field);
if ($this->_data[$field] === self::$_null) {
$dataSet[$field] = null;
@ -1214,7 +1228,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$dataSet[$field] = $this->getTable()->getConnection()->convertBooleans($this->_data[$field]);
break;
case 'enum':
$dataSet[$field] = $this->_table->enumIndex($field, $this->_data[$field]);
$dataSet[$field] = $this->_class->enumIndex($field, $this->_data[$field]);
break;
default:
if ($this->_data[$field] instanceof Doctrine_Record) {
@ -1232,10 +1246,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
// @todo cleanup
// populates the discriminator field in Single & Class Table Inheritance
if ($this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED ||
$this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
$discCol = $this->_table->getInheritanceOption('discriminatorColumn');
$discMap = $this->_table->getInheritanceOption('discriminatorMap');
if ($this->_class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED ||
$this->_class->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
$discCol = $this->_class->getInheritanceOption('discriminatorColumn');
$discMap = $this->_class->getInheritanceOption('discriminatorMap');
$old = $this->get($discCol, false);
$discValue = array_search($this->_entityName, $discMap);
if ((string) $old !== (string) $discValue || $old === null) {
@ -1278,8 +1292,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$a[$column] = $value;
}
if ($this->_table->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) {
$idFieldNames = (array)$this->_table->getIdentifier();
if ($this->_class->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) {
$idFieldNames = (array)$this->_class->getIdentifier();
$id = $idFieldNames[0];
$a[$id] = $this->getIncremented();
}
@ -1434,13 +1448,14 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*
* @param mixed $name name of the property or reference
* @return boolean
* @todo Method name does not reflect the purpose.
*/
public function hasRelation($fieldName)
{
if (isset($this->_data[$fieldName]) || isset($this->_id[$fieldName])) {
return true;
}
return $this->_table->hasRelation($fieldName);
return $this->_class->hasRelation($fieldName);
}
/**
@ -1473,8 +1488,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
$data = $this->_data;
if ($this->_table->getIdentifierType() === Doctrine::IDENTIFIER_AUTOINC) {
$idFieldNames = (array)$this->_table->getIdentifier();
if ($this->_class->getIdentifierType() === Doctrine::IDENTIFIER_AUTOINC) {
$idFieldNames = (array)$this->_class->getIdentifier();
$id = $idFieldNames[0];
unset($data[$id]);
}
@ -1528,7 +1543,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_data[$fieldName] = $value;
}
} else {
$idFieldNames = (array)$this->_table->getIdentifier();
$idFieldNames = (array)$this->_class->getIdentifier();
$name = $idFieldNames[0];
$this->_id[$name] = $id;
$this->_data[$name] = $id;
@ -1568,6 +1583,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* hasRefence
* @param string $name
* @return boolean
* @todo Better name? hasAssociation() ?
*/
public function hasReference($name)
{
@ -1630,7 +1646,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function loadReference($name)
{
$rel = $this->_table->getRelation($name);
$rel = $this->_class->getRelation($name);
$this->_references[$name] = $rel->fetchRelatedFor($this);
}
@ -1641,6 +1657,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* @param string $column column name
* @param mixed arg1 ... argN optional callback arguments
* @return Doctrine_Record
* @todo Really needed/used? If not, remove.
*/
public function call($callback, $column)
{
@ -1666,7 +1683,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function getNode()
{
if ( ! $this->_table->isTree()) {
if ( ! $this->_class->isTree()) {
return false;
}
@ -1691,7 +1708,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function revert($version)
{
$data = $this->_table
$data = $this->_class
->getBehavior('Doctrine_Template_Versionable')
->getAuditLog()
->getVersion($this, $version);
@ -1707,7 +1724,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
public function unshiftFilter(Doctrine_Record_Filter $filter)
{
return $this->_table->unshiftFilter($filter);
return $this->_class->unshiftFilter($filter);
}
/**
@ -1854,15 +1871,15 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function __call($method, $args)
{
if (($behavior = $this->_table->getBehaviorForMethod($method)) !== false) {
if (($behavior = $this->_class->getBehaviorForMethod($method)) !== false) {
$behavior->setInvoker($this);
return call_user_func_array(array($behavior, $method), $args);
}
foreach ($this->_table->getBehaviors() as $behavior) {
foreach ($this->_class->getBehaviors() as $behavior) {
if (method_exists($behavior, $method)) {
$behavior->setInvoker($this);
$this->_table->addBehaviorMethod($method, $behavior);
$this->_class->addBehaviorMethod($method, $behavior);
return call_user_func_array(array($behavior, $method), $args);
}
}
@ -1879,7 +1896,40 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
$this->getNode()->delete();
}
/**
* getTable
* returns the table object for this record
*
* @return Doctrine_Table a Doctrine_Table object
* @deprecated
*/
public function getTable()
{
return $this->getClassMetadata();
}
/**
* Gets the ClassMetadata object that describes the entity class.
*/
public function getClassMetadata()
{
return $this->_class;
}
/**
* Returns the mapper of the entity.
*
* @return Doctrine_Mapper
*/
public function getMapper()
{
return $this->_mapper;
}
/**
* @todo Why toString() and __toString() ?
*/
public function toString()
{
return Doctrine::dump(get_object_vars($this));
@ -1887,6 +1937,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
/**
* returns a string representation of this object
* @todo Why toString() and __toString() ?
*/
public function __toString()
{

View File

@ -1,155 +0,0 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Access');
/**
* Doctrine_Record_Abstract
*
* @package Doctrine
* @subpackage Record
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
abstract class Doctrine_Record_Abstract extends Doctrine_Access
{
/**
* The metadata container that describes the entity class.
*
* @param Doctrine_ClassMetadata
*/
protected $_table;
/**
*
* @var Doctrine_Mapper
*/
protected $_mapper;
/**
* @deprecated
*/
public function setTableDefinition()
{}
/**
* @deprecated
*/
public function setUp()
{}
/**
* getTable
* returns the table object for this record
*
* @return Doctrine_Table a Doctrine_Table object
* @deprecated
*/
public function getTable()
{
return $this->getClassMetadata();
}
/**
* Gets the ClassMetadata object that describes the entity class.
*/
public function getClassMetadata()
{
return $this->_table;
}
/**
* Returns the mapper of the entity.
*
* @return Doctrine_Mapper
*/
public function getMapper()
{
return $this->_mapper;
}
/**
* addListener
*
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_Record
*/
public function addListener($listener, $name = null)
{
$this->_table->addRecordListener($listener, $name = null);
return $this;
}
/**
* getListener
*
* @return Doctrine_EventListener_Interface|Doctrine_Overloadable
*/
public function getListener()
{
return $this->_table->getRecordListener();
}
/**
* setListener
*
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_Record
*/
public function setListener($listener)
{
$this->_table->setRecordListener($listener);
return $this;
}
public function setAttribute($attr, $value)
{
$this->_table->setAttribute($attr, $value);
}
/**
* attribute
* sets or retrieves an option
*
* @see Doctrine::ATTR_* constants availible attributes
* @param mixed $attr
* @param mixed $value
* @return mixed
*/
public function attribute($attr, $value)
{
if ($value == null) {
if (is_array($attr)) {
foreach ($attr as $k => $v) {
$this->_table->setAttribute($k, $v);
}
} else {
return $this->_table->getAttribute($attr);
}
} else {
$this->_table->setAttribute($attr, $value);
}
}
}

View File

@ -97,7 +97,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
$id = $record->getIncremented();
//var_dump($id);
//echo "<br /><br />";
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
//echo "here" . $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES);
$coll = new Doctrine_Collection($this->getForeignComponentName());
} else {

View File

@ -55,7 +55,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
if ($this->isOneToOne()) {
if ( ! $record->exists() || empty($id) ||
! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->_foreignMapper->create();
} else {
$dql = 'FROM ' . $this->_foreignMapper->getComponentName()
@ -69,7 +69,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
$record, false);
} else {
if ( ! $record->exists() || empty($id) ||
! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = new Doctrine_Collection($this->_foreignMapper->getComponentName());
} else {
$query = $this->getRelationDql(1);

View File

@ -46,7 +46,7 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation
$localFieldName = $record->getTable()->getFieldName($this->definition['local']);
$id = $record->get($localFieldName);
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->_foreignMapper->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName()

View File

@ -105,7 +105,7 @@ class Doctrine_Relation_Nest extends Doctrine_Relation_Association
$id = $record->getIncremented();
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
return new Doctrine_Collection($this->getForeignComponentName());
} else {

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Record_Abstract');
/**
* Doctrine_Template
*
@ -30,7 +30,7 @@ Doctrine::autoload('Doctrine_Record_Abstract');
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Template extends Doctrine_Record_Abstract
class Doctrine_Template
{
/**
* @param Doctrine_Record $_invoker the record that invoked the last delegated call

View File

@ -160,7 +160,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
* get the current transaction nesting level
*
* @return integer
* @todo Name suggestion: getLevel(). $transaction->getTransactionLevel() looks odd.
* @todo Name suggestion: getNestingLevel(). $transaction->getTransactionLevel() looks odd.
*/
public function getTransactionLevel()
{

View File

@ -9,6 +9,7 @@ require_once 'lib/DoctrineTestInit.php';
require_once 'Orm/Component/AllTests.php';
require_once 'Orm/Ticket/AllTests.php';
require_once 'Orm/UnitOfWorkTestCase.php';
require_once 'Orm/ConfigurableTestCase.php';
class Orm_AllTests
{
@ -22,6 +23,8 @@ class Orm_AllTests
$suite = new Doctrine_OrmTestSuite('Doctrine Orm');
$suite->addTestSuite('Orm_UnitOfWorkTestCase');
$suite->addTestSuite('Orm_ConfigurableTestCase');
$suite->addTest(Orm_Component_AllTests::suite());
$suite->addTest(Orm_Ticket_AllTests::suite());

View File

@ -173,43 +173,6 @@ class Doctrine_Configurable_TestCase extends Doctrine_UnitTestCase {
$this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE, 5);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_BATCH_SIZE),5);
$this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_LOCKMODE), Doctrine::LOCK_PESSIMISTIC);
// test invalid arguments
/**
try {
$this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
try {
$this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
try {
$this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
*/
try {
$this->connection->beginTransaction();
$this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_OPTIMISTIC);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
$this->connection->commit();
}
try {
$this->connection->beginTransaction();
$this->connection->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
$this->connection->commit();
}
}
public function testGetAttributes() {
$this->assertTrue(is_array($this->manager->getAttributes()));

View File

@ -60,7 +60,8 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase
public function testHydrateHooks()
{
$user = new User();
$user->getMapper()->addRecordListener(new HydrationListener);
$listener = new HydrationListener;
$user->getClassMetadata()->addRecordListener($listener);
$user->name = 'zYne';
$user->save();
@ -72,7 +73,7 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user->name, 'ZYNE');
$this->assertEqual($user->password, 'DEFAULT PASS');
$user->getClassMetadata()->removeRecordListeners();
}
}
class HydrationListener extends Doctrine_Record_Listener

View File

@ -79,7 +79,7 @@ class Doctrine_Record_Hook_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($r->pop(), 'preDelete');
}
public function testSoftDelete()
/*public function testSoftDelete()
{
$r = new SoftDeleteTest();
$r->name = 'something';
@ -99,5 +99,5 @@ class Doctrine_Record_Hook_TestCase extends Doctrine_UnitTestCase
} catch(Doctrine_Exception $e) {
$this->fail();
}
}
}*/
}

View File

@ -7,35 +7,35 @@ class RecordHookTest extends Doctrine_Record
{
$class->setColumn('name', 'string', null, array('primary' => true));
}
public function preSave(Doctrine_Event $event)
public function preSave()
{
$this->_messages[] = __FUNCTION__;
}
public function postSave(Doctrine_Event $event)
public function postSave()
{
$this->_messages[] = __FUNCTION__;
}
public function preInsert(Doctrine_Event $event)
public function preInsert()
{
$this->_messages[] = __FUNCTION__;
}
public function postInsert(Doctrine_Event $event)
public function postInsert()
{
$this->_messages[] = __FUNCTION__;
}
public function preUpdate(Doctrine_Event $event)
public function preUpdate()
{
$this->_messages[] = __FUNCTION__;
}
public function postUpdate(Doctrine_Event $event)
public function postUpdate()
{
$this->_messages[] = __FUNCTION__;
}
public function preDelete(Doctrine_Event $event)
public function preDelete()
{
$this->_messages[] = __FUNCTION__;
}
public function postDelete(Doctrine_Event $event)
public function postDelete()
{
$this->_messages[] = __FUNCTION__;
}

View File

@ -7,14 +7,14 @@ class SoftDeleteTest extends Doctrine_Record
$class->setColumn('something', 'string', '25', array('notnull' => true, 'unique' => true));
$class->setColumn('deleted', 'boolean', 1);
}
public function preDelete(Doctrine_Event $event)
/*public function preDelete()
{
$event->skipOperation();
}
public function postDelete(Doctrine_Event $event)
public function postDelete()
{
$this->deleted = true;
$this->save();
}
}*/
}

View File

@ -122,7 +122,6 @@ $core->addTestCase(new Doctrine_Access_TestCase());
//$core->addTestCase(new Doctrine_Configurable_TestCase());
$core->addTestCase(new Doctrine_Manager_TestCase());
$core->addTestCase(new Doctrine_Connection_TestCase());
$core->addTestCase(new Doctrine_Table_TestCase());
$core->addTestCase(new Doctrine_UnitOfWork_TestCase());
//$core->addTestCase(new Doctrine_Collection_TestCase());
$core->addTestCase(new Doctrine_Collection_Snapshot_TestCase());
@ -259,8 +258,8 @@ $test->addTestCase(new Doctrine_Inheritance_TablePerClass_TestCase());
$test->addTestCase(new Doctrine_Metadata_Factory_TestCase());
// nestedset tests
$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
$test->addTestCase(new Doctrine_NestedSet_LoadInSetUp_TestCase());
//$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
//$test->addTestCase(new Doctrine_NestedSet_LoadInSetUp_TestCase());
// Search tests
$search = new GroupTest('Search tests','search');