Commit edcc8be2 authored by romanb's avatar romanb

some smaller refactorings. started to replace the term 'template' with 'behavior'.

parent c1c3f489
...@@ -78,16 +78,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -78,16 +78,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
protected $_inheritanceType = Doctrine::INHERITANCETYPE_TABLE_PER_CLASS; protected $_inheritanceType = Doctrine::INHERITANCETYPE_TABLE_PER_CLASS;
/** /**
* An array containing all templates attached to the class. * An array containing all behaviors attached to the class.
* *
* @see Doctrine_Template * @see Doctrine_Template
* @var array $_templates * @var array $_templates
* @todo Unify under 'Behaviors'. * @todo Unify under 'Behaviors'.
*/ */
protected $_templates = array(); protected $_behaviors = array();
/** /**
* An array containing all generators attached to this class. * An array containing all behavior generators attached to the class.
* *
* @see Doctrine_Record_Generator * @see Doctrine_Record_Generator
* @var array $_generators * @var array $_generators
...@@ -244,6 +244,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -244,6 +244,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
'checks' => array() 'checks' => array()
); );
/**
* @var array $_invokedMethods method invoker cache
*/
protected $_invokedMethods = array();
/** /**
* Constructs a new metadata instance. * Constructs a new metadata instance.
* *
...@@ -374,6 +380,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -374,6 +380,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->_tableOptions[$name]; return $this->_tableOptions[$name];
} }
public function getBehaviorForMethod($method)
{
return (isset($this->_invokedMethods[$method])) ?
$this->_invokedMethods[$method] : false;
}
public function addBehaviorMethod($method, $behavior)
{
$this->_invokedMethods[$method] = $class;
}
/** /**
* getOption * getOption
* returns the value of given option * returns the value of given option
...@@ -590,6 +607,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -590,6 +607,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/** /**
* Gets the names of all validators that are applied on a field. * Gets the names of all validators that are applied on a field.
* *
* @param string The field name.
* @return array The names of all validators that are applied on the specified field.
*/ */
public function getFieldValidators($fieldName) public function getFieldValidators($fieldName)
{ {
...@@ -599,10 +618,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -599,10 +618,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* hasDefaultValues * Checks whether the class mapped class has a default value on any field.
* returns true if this class has default values, otherwise false
* *
* @return boolean * @return boolean TRUE if the entity has a default value on any field, otherwise false.
*/ */
public function hasDefaultValues() public function hasDefaultValues()
{ {
...@@ -630,6 +648,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -630,6 +648,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* Gets the identifier (primary key) field(s) of the mapped class.
*
* @return mixed * @return mixed
*/ */
public function getIdentifier() public function getIdentifier()
...@@ -643,6 +663,10 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -643,6 +663,10 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* Gets the type of the identifier (primary key) used by the mapped class. The type
* can be either "Doctrine::IDENTIFIER_NATURAL", "Doctrine::IDENTIFIER_AUTOINCREMENT",
* "Doctrine::IDENTIFIER_SEQUENCE" or "Doctrine::IDENTIFIER_COMPOSITE".
*
* @return integer * @return integer
*/ */
public function getIdentifierType() public function getIdentifierType()
...@@ -650,6 +674,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -650,6 +674,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->_identifierType; return $this->_identifierType;
} }
/**
* Sets the identifier type used by the mapped class.
*/
public function setIdentifierType($type) public function setIdentifierType($type)
{ {
$this->_identifierType = $type; $this->_identifierType = $type;
...@@ -658,12 +685,18 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -658,12 +685,18 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/** /**
* hasColumn * hasColumn
* @return boolean * @return boolean
* @deprecated
*/ */
public function hasColumn($columnName) public function hasColumn($columnName)
{ {
return isset($this->_mappedColumns[$columnName]); return isset($this->_mappedColumns[$columnName]);
} }
public function hasMappedColumn($columnName)
{
return isset($this->_mappedColumns[$columnName]);
}
/** /**
* hasField * hasField
* @return boolean * @return boolean
...@@ -864,6 +897,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -864,6 +897,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* getDefinitionOf * getDefinitionOf
* *
* @return mixed array on success, false on failure * @return mixed array on success, false on failure
* @deprecated
*/ */
public function getDefinitionOf($fieldName) public function getDefinitionOf($fieldName)
{ {
...@@ -872,16 +906,29 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -872,16 +906,29 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->getColumnDefinition($columnName); return $this->getColumnDefinition($columnName);
} }
public function getMappingForField($fieldName)
{
$columnName = $this->getColumnName($fieldName);
return $this->getColumnDefinition($columnName);
}
/** /**
* getTypeOf * getTypeOf
* *
* @return mixed string on success, false on failure * @return mixed string on success, false on failure
* @deprecated
*/ */
public function getTypeOf($fieldName) public function getTypeOf($fieldName)
{ {
return $this->getTypeOfColumn($this->getColumnName($fieldName)); return $this->getTypeOfColumn($this->getColumnName($fieldName));
} }
public function getTypeOfField($fieldName)
{
return $this->getTypeOfColumn($this->getColumnName($fieldName));
}
/** /**
* getTypeOfColumn * getTypeOfColumn
* *
...@@ -994,15 +1041,15 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -994,15 +1041,15 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* getTemplates * getBehaviors
* returns all templates attached to this table * returns all behaviors attached to the class.
* *
* @return array an array containing all templates * @return array an array containing all templates
* @todo Unify under 'Behaviors' * @todo Unify under 'Behaviors'
*/ */
public function getTemplates() public function getBehaviors()
{ {
return $this->_templates; return $this->_behaviors;
} }
/** /**
...@@ -1308,29 +1355,29 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1308,29 +1355,29 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* @return void * @return void
* @todo Unify under 'Behaviors'. * @todo Unify under 'Behaviors'.
*/ */
public function getTemplate($template) public function getBehavior($behaviorName)
{ {
if ( ! isset($this->_templates[$template])) { if ( ! isset($this->_behaviors[$behaviorName])) {
throw new Doctrine_Table_Exception('Template ' . $template . ' not loaded'); throw new Doctrine_Table_Exception('Template ' . $behaviorName . ' not loaded');
} }
return $this->_templates[$template]; return $this->_behaviors[$behaviorName];
} }
/** /**
* @todo Unify under 'Behaviors'. * @todo Unify under 'Behaviors'.
*/ */
public function hasTemplate($template) public function hasBehavior($behaviorName)
{ {
return isset($this->_templates[$template]); return isset($this->_behaviors[$behaviorName]);
} }
/** /**
* @todo Unify under 'Behaviors'. * @todo Unify under 'Behaviors'.
*/ */
public function addTemplate($template, Doctrine_Template $impl) public function addBehavior($behaviorName, Doctrine_Template $impl)
{ {
$this->_templates[$template] = $impl; $this->_behaviors[$behaviorName] = $impl;
return $this; return $this;
} }
...@@ -1599,7 +1646,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1599,7 +1646,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$className = get_class($tpl); $className = get_class($tpl);
$this->addTemplate($className, $tpl); $this->addBehavior($className, $tpl);
$tpl->setTable($this); $tpl->setTable($this);
$tpl->setUp(); $tpl->setUp();
...@@ -1639,17 +1686,6 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1639,17 +1686,6 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
} }
/**
* Mixes a predefined behaviour into the class.
*
* @param string|object The name of the behavior or the behavior object.
* @todo Implementation.
*/
public function addBehavior($behavior)
{
// ...
}
/** /**
* Registers a custom mapper for the entity class. * Registers a custom mapper for the entity class.
* *
...@@ -1727,6 +1763,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1727,6 +1763,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this; return $this;
} }
/** /**
* *
*/ */
......
...@@ -485,8 +485,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -485,8 +485,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/ */
public function add($record, $key = null) public function add($record, $key = null)
{ {
if( ! $record instanceOf Doctrine_Record) { if ( ! $record instanceof Doctrine_Record) {
throw new Doctrine_Record_Exception('Value variable in set is not an instance of Doctrine_Record'); throw new Doctrine_Record_Exception('Value variable in set is not an instance of Doctrine_Record.');
} }
if (isset($this->referenceField)) { if (isset($this->referenceField)) {
...@@ -527,6 +527,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -527,6 +527,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} else { } else {
$this->data[] = $record; $this->data[] = $record;
} }
return true; return true;
} }
......
...@@ -178,7 +178,7 @@ class Doctrine_Data_Import extends Doctrine_Data ...@@ -178,7 +178,7 @@ class Doctrine_Data_Import extends Doctrine_Data
// This is simple here to get the templates present for this model // This is simple here to get the templates present for this model
// better way? // better way?
$obj = new $className(null, true); $obj = new $className(null, true);
$templates = array_keys($obj->getTable()->getTemplates()); $templates = array_keys($obj->getTable()->getBehaviors());
if (in_array('Doctrine_Template_NestedSet', $templates)) { if (in_array('Doctrine_Template_NestedSet', $templates)) {
$nestedSets[$className][] = $data; $nestedSets[$className][] = $data;
......
...@@ -68,11 +68,6 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable ...@@ -68,11 +68,6 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
*/ */
protected $_repository; protected $_repository;
/**
* @var array $_invokedMethods method invoker cache
*/
protected $_invokedMethods = array();
/** /**
* Constructs a new mapper. * Constructs a new mapper.
...@@ -95,17 +90,6 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable ...@@ -95,17 +90,6 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
} }
} }
public function getMethodOwner($method)
{
return (isset($this->_invokedMethods[$method])) ?
$this->_invokedMethods[$method] : false;
}
public function setMethodOwner($method, $class)
{
$this->_invokedMethods[$method] = $class;
}
/** /**
* export * export
* exports this table to database based on column and option definitions * exports this table to database based on column and option definitions
......
...@@ -1682,7 +1682,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1682,7 +1682,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
public function revert($version) public function revert($version)
{ {
$data = $this->_table $data = $this->_table
->getTemplate('Doctrine_Template_Versionable') ->getBehavior('Doctrine_Template_Versionable')
->getAuditLog() ->getAuditLog()
->getVersion($this, $version); ->getVersion($this, $version);
...@@ -1841,17 +1841,16 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1841,17 +1841,16 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/ */
public function __call($method, $args) public function __call($method, $args)
{ {
if (($template = $this->_mapper->getMethodOwner($method)) !== false) { if (($behavior = $this->_table->getBehaviorForMethod($method)) !== false) {
$template->setInvoker($this); $behavior->setInvoker($this);
return call_user_func_array(array($template, $method), $args); return call_user_func_array(array($behavior, $method), $args);
} }
foreach ($this->_mapper->getTable()->getTemplates() as $template) { foreach ($this->_table->getBehaviors() as $behavior) {
if (method_exists($template, $method)) { if (method_exists($behavior, $method)) {
$template->setInvoker($this); $behavior->setInvoker($this);
$this->_mapper->setMethodOwner($method, $template); $this->_table->addBehaviorMethod($method, $behavior);
return call_user_func_array(array($behavior, $method), $args);
return call_user_func_array(array($template, $method), $args);
} }
} }
......
...@@ -136,12 +136,12 @@ class Doctrine_Relation_Parser ...@@ -136,12 +136,12 @@ class Doctrine_Relation_Parser
$this->getRelations(); $this->getRelations();
return $this->getRelation($alias, false); return $this->getRelation($alias, false);
} else { } else {
try { /*try {
throw new Exception(); throw new Exception();
} catch (Exception $e) { } catch (Exception $e) {
//echo "" . "<br />"; //echo "" . "<br />";
///echo $e->getTraceAsString() . "<br /><br /><br />"; ///echo $e->getTraceAsString() . "<br /><br /><br />";
} }*/
throw new Doctrine_Relation_Exception("Unknown relation '$alias'."); throw new Doctrine_Relation_Exception("Unknown relation '$alias'.");
} }
} }
...@@ -171,19 +171,7 @@ class Doctrine_Relation_Parser ...@@ -171,19 +171,7 @@ class Doctrine_Relation_Parser
$def = $this->completeAssocDefinition($def); $def = $this->completeAssocDefinition($def);
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getClassName())); $localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getClassName()));
// if the two many-many related components share the same table, we need
// custom relation names to distinguish the relations.
/*if ($this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE &&
in_array($def['class'], $this->_table->getOption('subclasses'))) {
if ( ! isset($def['refRelationName']) || ! isset($def['refReverseRelationName'])) {
throw new Doctrine_Relation_Exception("Incomplete relation. Many-to-many relations between "
. "classes that share the same table (single table inheritance) need to specify "
. "a 'refRelationName' and a 'refReverseRelationName' to distinguish relations.");
}
$relationName = $def['refRelationName'];
} else {*/
$relationName = $def['refClass']; $relationName = $def['refClass'];
//}
if ( ! isset($this->_pending[$relationName]) && ! isset($this->_relations[$relationName])) { if ( ! isset($this->_pending[$relationName]) && ! isset($this->_relations[$relationName])) {
$this->_completeManyToManyRelation($def); $this->_completeManyToManyRelation($def);
...@@ -222,12 +210,7 @@ class Doctrine_Relation_Parser ...@@ -222,12 +210,7 @@ class Doctrine_Relation_Parser
$identifierColumnNames = $this->_table->getIdentifierColumnNames(); $identifierColumnNames = $this->_table->getIdentifierColumnNames();
$idColumnName = array_pop($identifierColumnNames); $idColumnName = array_pop($identifierColumnNames);
// if the two many-many related components shared the same table, we need a relation name
// to distinguish the relations.
$relationName = $def['refClass']; $relationName = $def['refClass'];
/*if (isset($def['refRelationName'])) {
$relationName .= ' as ' . $def['refRelationName'];
}*/
// add a relation pointing from the intermediary table to the table of this parser // add a relation pointing from the intermediary table to the table of this parser
$parser = $def['refTable']->getRelationParser(); $parser = $def['refTable']->getRelationParser();
...@@ -416,7 +399,6 @@ class Doctrine_Relation_Parser ...@@ -416,7 +399,6 @@ class Doctrine_Relation_Parser
{ {
$conn = $this->_table->getConnection(); $conn = $this->_table->getConnection();
$def['table'] = $this->getImpl($def, 'class'); $def['table'] = $this->getImpl($def, 'class');
//$def['class'] = $def['table']->getComponentName();
$def['localTable'] = $this->_table; $def['localTable'] = $this->_table;
$foreignClasses = array_merge($def['table']->getOption('parents'), array($def['class'])); $foreignClasses = array_merge($def['table']->getOption('parents'), array($def['class']));
......
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