Commit ade4cd2a authored by romanb's avatar romanb

cosmetics

parent 57abb796
<?php <?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>.
*/
/** /**
* A MetadataClass instance holds all the information (metadata) of an entity class and it's relations. * A ClassMetadata instance holds all the information (metadata) of an entity and it's relations.
* These informations are needed for the proper object-relational mapping of the domain class. * These informations are used for the proper object-relational mapping of the class.
* *
* @package Doctrine * @package Doctrine
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @since 1.0
*/ */
class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializable class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializable
{ {
...@@ -14,7 +34,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -14,7 +34,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @var string * @var string
*/ */
protected $_domainClassName; protected $_entityName;
/** /**
* *
...@@ -71,6 +91,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -71,6 +91,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @see Doctrine_Template * @see Doctrine_Template
* @var array $_templates * @var array $_templates
* @todo Unify under 'Behaviors'.
*/ */
protected $_templates = array(); protected $_templates = array();
...@@ -79,11 +100,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -79,11 +100,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @see Doctrine_Record_Generator * @see Doctrine_Record_Generator
* @var array $_generators * @var array $_generators
* @todo Unify under 'Behaviors'.
*/ */
protected $_generators = array(); protected $_generators = array();
/** /**
* An array containing all filters attached to this class. * An array containing all filters attached to the class.
* *
* @see Doctrine_Record_Filter * @see Doctrine_Record_Filter
* @var array $_filters * @var array $_filters
...@@ -144,7 +166,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -144,7 +166,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @var integer * @var integer
*/ */
protected $columnCount; protected $_columnCount;
/** /**
* Whether or not this class has default values. * Whether or not this class has default values.
...@@ -160,12 +182,6 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -160,12 +182,6 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
protected $_parser; protected $_parser;
/**
* Contains the mapping of the discriminator column (which discriminator value identifies
* which class). Used in Single & Class Table Inheritance.
*/
protected $_inheritanceMap = array();
/** /**
* Enum value arrays. * Enum value arrays.
*/ */
...@@ -191,7 +207,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -191,7 +207,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
); );
/** /**
* * Inheritance options.
*/ */
protected $_inheritanceOptions = array( protected $_inheritanceOptions = array(
'discriminatorColumn' => null, 'discriminatorColumn' => null,
...@@ -234,9 +250,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -234,9 +250,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @param string $domainClassName Name of the class the metadata instance is used for. * @param string $domainClassName Name of the class the metadata instance is used for.
*/ */
public function __construct($domainClassName, Doctrine_Connection $conn) public function __construct($entityName, Doctrine_Connection $conn)
{ {
$this->_domainClassName = $domainClassName; $this->_entityName = $entityName;
$this->_conn = $conn; $this->_conn = $conn;
$this->_parser = new Doctrine_Relation_Parser($this); $this->_parser = new Doctrine_Relation_Parser($this);
$this->_filters[] = new Doctrine_Record_Filter_Standard(); $this->_filters[] = new Doctrine_Record_Filter_Standard();
...@@ -258,16 +274,19 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -258,16 +274,19 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
public function getClassName() public function getClassName()
{ {
return $this->_domainClassName; return $this->_entityName;
} }
/**
* @deprecated
*/
public function getComponentName() public function getComponentName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
/** /**
* Whether a field is part of the identifier/primary key field(s). * Checks whether a field is part of the identifier/primary key field(s).
* *
* @param string $fieldName The field name * @param string $fieldName The field name
* @return boolean TRUE if the field is part of the table identifier/primary key field(s), * @return boolean TRUE if the field is part of the table identifier/primary key field(s),
...@@ -329,31 +348,28 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -329,31 +348,28 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
case 'enumMap': case 'enumMap':
$this->_enumMap = $value; $this->_enumMap = $value;
return; return;
case 'inheritanceMap':
$this->_inheritanceMap = $value;
return;
} }
$this->_options[$name] = $value; $this->_options[$name] = $value;
} }
/** /**
* * Sets a table option.
*/ */
public function setTableOption($name, $value) public function setTableOption($name, $value)
{ {
if ( ! array_key_exists($name, $this->_tableOptions)) { if ( ! array_key_exists($name, $this->_tableOptions)) {
throw new Doctrine_MetadataClass_Exception("Unknown table option: '$name'."); throw new Doctrine_ClassMetadata_Exception("Unknown table option: '$name'.");
} }
$this->_tableOptions[$name] = $value; $this->_tableOptions[$name] = $value;
} }
/** /**
* * Gets a table option.
*/ */
public function getTableOption($name) public function getTableOption($name)
{ {
if ( ! array_key_exists($name, $this->_tableOptions)) { if ( ! array_key_exists($name, $this->_tableOptions)) {
throw new Doctrine_MetadataClass_Exception("Unknown table option: '$name'."); throw new Doctrine_ClassMetadata_Exception("Unknown table option: '$name'.");
} }
return $this->_tableOptions[$name]; return $this->_tableOptions[$name];
...@@ -455,13 +471,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -455,13 +471,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
} }
/**
* @deprecated
*/
public function mapField($name, $type, $length = null, $options = array(), $prepend = false) public function mapField($name, $type, $length = null, $options = array(), $prepend = false)
{ {
return $this->setColumn($name, $type, $length, $options, $prepend); return $this->setColumn($name, $type, $length, $options, $prepend);
} }
/** /**
* setColumn * addMappedColumn
* *
* @param string $name * @param string $name
* @param string $type * @param string $type
...@@ -469,10 +488,10 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -469,10 +488,10 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* @param mixed $options * @param mixed $options
* @param boolean $prepend Whether to prepend or append the new column to the column list. * @param boolean $prepend Whether to prepend or append the new column to the column list.
* By default the column gets appended. * By default the column gets appended.
* @throws Doctrine_Table_Exception if trying use wrongly typed parameter * @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter.
* @return void * @deprecated
*/ */
public function setColumn($name, $type, $length = null, $options = array(), $prepend = false) public function addMappedColumn($name, $type, $length = null, $options = array(), $prepend = false)
{ {
if (is_string($options)) { if (is_string($options)) {
$options = explode('|', $options); $options = explode('|', $options);
...@@ -557,7 +576,25 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -557,7 +576,25 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$this->_hasDefaultValues = true; $this->_hasDefaultValues = true;
} }
$this->columnCount++; $this->_columnCount++;
}
/**
* setColumn
*
* @param string $name
* @param string $type
* @param integer $length
* @param mixed $options
* @param boolean $prepend Whether to prepend or append the new column to the column list.
* By default the column gets appended.
* @throws Doctrine_Table_Exception if trying use wrongly typed parameter
* @return void
* @deprecated
*/
public function setColumn($name, $type, $length = null, $options = array(), $prepend = false)
{
return $this->addMappedColumn($name, $type, $length, $options, $prepend);
} }
/** /**
...@@ -696,7 +733,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -696,7 +733,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
public function getColumnCount() public function getColumnCount()
{ {
return $this->columnCount; return $this->_columnCount;
} }
/** /**
...@@ -725,7 +762,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -725,7 +762,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
unset($this->_columns[$columnName]); unset($this->_columns[$columnName]);
return true; return true;
} }
$this->columnCount--; $this->_columnCount--;
return false; return false;
} }
...@@ -841,8 +878,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -841,8 +878,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @param string $name The name under which the query gets registered. * @param string $name The name under which the query gets registered.
* @param string $query The DQL query. * @param string $query The DQL query.
* @todo Implementation.
*/ */
public function setNamedQuery($name, $query) public function addNamedQuery($name, $query)
{ {
} }
...@@ -943,7 +981,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -943,7 +981,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
public function setSubclasses(array $subclasses) public function setSubclasses(array $subclasses)
{ {
$this->setOption('subclasses', $subclasses); $this->_options['subclasses'] = $subclasses;
} }
/** /**
...@@ -957,7 +995,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -957,7 +995,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* Checks whether the class has any persistent subclasses.
* *
* @return boolean TRUE if the class has one or more persistent subclasses, FALSE otherwise.
*/
public function hasSubclasses()
{
return ! $this->getOption('subclasses');
}
/**
* Gets the names of all parent classes.
*/ */
public function getParentClasses() public function getParentClasses()
{ {
...@@ -965,7 +1013,25 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -965,7 +1013,25 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* Sets the inheritance type used by the class. * Sets the parent class names.
*/
public function setParentClasses(array $classNames)
{
$this->_options['parents'] = $classNames;
}
/**
* Checks whether the class has any persistence parent classes.
*
* @return boolean TRUE if the class has one or more persistent parent classes, FALSE otherwise.
*/
public function hasParentClasses()
{
return ! $this->getOption('parents');
}
/**
* Sets the inheritance type used by the class and it's subclasses.
* *
* @param integer $type * @param integer $type
*/ */
...@@ -978,7 +1044,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -978,7 +1044,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} else if ($type == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { } else if ($type == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) {
// concrete table inheritance ... // concrete table inheritance ...
} else { } else {
throw new Doctrine_MetadataClass_Exception("Invalid inheritance type '$type'."); throw new Doctrine_ClassMetadata_Exception("Invalid inheritance type '$type'.");
} }
$this->_inheritanceType = $type; $this->_inheritanceType = $type;
foreach ($options as $name => $value) { foreach ($options as $name => $value) {
...@@ -1178,6 +1244,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1178,6 +1244,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @param string $template * @param string $template
* @return void * @return void
* @todo Unify under 'Behaviors'.
*/ */
public function getTemplate($template) public function getTemplate($template)
{ {
...@@ -1188,11 +1255,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1188,11 +1255,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->_templates[$template]; return $this->_templates[$template];
} }
/**
* @todo Unify under 'Behaviors'.
*/
public function hasTemplate($template) public function hasTemplate($template)
{ {
return isset($this->_templates[$template]); return isset($this->_templates[$template]);
} }
/**
* @todo Unify under 'Behaviors'.
*/
public function addTemplate($template, Doctrine_Template $impl) public function addTemplate($template, Doctrine_Template $impl)
{ {
$this->_templates[$template] = $impl; $this->_templates[$template] = $impl;
...@@ -1200,11 +1273,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1200,11 +1273,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this; return $this;
} }
/**
* @todo Unify under 'Behaviors'.
*/
public function getGenerators() public function getGenerators()
{ {
return $this->_generators; return $this->_generators;
} }
/**
* @todo Unify under 'Behaviors'.
*/
public function getGenerator($generator) public function getGenerator($generator)
{ {
if ( ! isset($this->_generators[$generator])) { if ( ! isset($this->_generators[$generator])) {
...@@ -1214,11 +1293,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1214,11 +1293,17 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->_generators[$plugin]; return $this->_generators[$plugin];
} }
/**
* @todo Unify under 'Behaviors'.
*/
public function hasGenerator($generator) public function hasGenerator($generator)
{ {
return isset($this->_generators[$generator]); return isset($this->_generators[$generator]);
} }
/**
* @todo Unify under 'Behaviors'.
*/
public function addGenerator(Doctrine_Record_Generator $generator, $name = null) public function addGenerator(Doctrine_Record_Generator $generator, $name = null)
{ {
if ($name === null) { if ($name === null) {
...@@ -1229,6 +1314,26 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1229,6 +1314,26 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this; return $this;
} }
/**
* loadTemplate
*
* @param string $template
* @todo Unify under 'Behaviors'.
*/
public function loadTemplate($template, array $options = array())
{
$this->actAs($template, $options);
}
/**
* @todo Unify under 'Behaviors'.
*/
public function loadGenerator(Doctrine_Record_Generator $generator)
{
$generator->initialize($this->_table);
$this->addGenerator($generator, get_class($generator));
}
/** /**
* unshiftFilter * unshiftFilter
* *
...@@ -1249,6 +1354,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1249,6 +1354,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* getter for associated tree * getter for associated tree
* *
* @return mixed if tree return instance of Doctrine_Tree, otherwise returns false * @return mixed if tree return instance of Doctrine_Tree, otherwise returns false
* @todo Belongs to the NestedSet Behavior.
*/ */
public function getTree() public function getTree()
{ {
...@@ -1269,6 +1375,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1269,6 +1375,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* determine if table acts as tree * determine if table acts as tree
* *
* @return mixed if tree return true, otherwise returns false * @return mixed if tree return true, otherwise returns false
* @todo Belongs to the NestedSet Behavior.
*/ */
public function isTree() public function isTree()
{ {
...@@ -1286,7 +1393,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1286,7 +1393,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* Checks whether a persistent field is inherited from a superclass.
* *
* @return boolean TRUE if the field is inherited, FALSE otherwise.
*/ */
public function isInheritedField($fieldName) public function isInheritedField($fieldName)
{ {
...@@ -1335,10 +1444,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1335,10 +1444,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* setTableName * Sets the name of the primary table the class is mapped to.
* *
* @param string $tableName * @param string $tableName The table name.
* @return void
*/ */
public function setTableName($tableName) public function setTableName($tableName)
{ {
...@@ -1370,7 +1478,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1370,7 +1478,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* * @todo Implementation.
*/ */
public function oneToOne($targetEntity, $definition) public function oneToOne($targetEntity, $definition)
{ {
...@@ -1378,7 +1486,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1378,7 +1486,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* * @todo Implementation.
*/ */
public function oneToMany($targetEntity, $definition) public function oneToMany($targetEntity, $definition)
{ {
...@@ -1386,7 +1494,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1386,7 +1494,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* * @todo Implementation.
*/ */
public function manyToOne($targetEntity, $definition) public function manyToOne($targetEntity, $definition)
{ {
...@@ -1394,36 +1502,20 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1394,36 +1502,20 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
/** /**
* * @todo Implementation.
*/ */
public function manyToMany($targetEntity, $definition) public function manyToMany($targetEntity, $definition)
{ {
} }
/**
* loadTemplate
*
* @param string $template
*/
public function loadTemplate($template, array $options = array())
{
$this->actAs($template, $options);
}
public function loadGenerator(Doctrine_Record_Generator $generator)
{
$generator->initialize($this->_table);
$this->addGenerator($generator, get_class($generator));
}
/** /**
* actAs * actAs
* loads the given plugin * loads the given plugin
* *
* @param mixed $tpl * @param mixed $tpl
* @param array $options * @param array $options
* @todo Unify under 'Behaviors'.
*/ */
public function actAs($tpl, array $options = array()) public function actAs($tpl, array $options = array())
{ {
...@@ -1432,12 +1524,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1432,12 +1524,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$tpl = new $tpl($options); $tpl = new $tpl($options);
} else { } else {
$className = 'Doctrine_Template_' . $tpl; $className = 'Doctrine_Template_' . $tpl;
if ( ! class_exists($className, true)) { if ( ! class_exists($className, true)) {
throw new Doctrine_Record_Exception("Couldn't load plugin."); throw new Doctrine_Record_Exception("Couldn't load plugin.");
} }
$tpl = new $className($options); $tpl = new $className($options);
} }
} }
...@@ -1492,6 +1581,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1492,6 +1581,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* Mixes a predefined behaviour into the class. * Mixes a predefined behaviour into the class.
* *
* @param string|object The name of the behavior or the behavior object. * @param string|object The name of the behavior or the behavior object.
* @todo Implementation.
*/ */
public function addBehavior($behavior) public function addBehavior($behavior)
{ {
...@@ -1508,6 +1598,14 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1508,6 +1598,14 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
//Doctrine::CLASSTYPE_TRANSIENT //Doctrine::CLASSTYPE_TRANSIENT
} }
/**
* @todo Implementation.
*/
public function isImmutable()
{
return false;
}
/** /**
* hasOne * hasOne
* binds One-to-One aggregate relation * binds One-to-One aggregate relation
......
<?php <?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>.
*/
/** /**
* A table factory is used to create table objects and load them with meta data. * The metadata factory is used to create ClassMetadata objects that contain all the
* metadata of a class.
* *
* @todo Support different drivers for loading the metadata from different sources.
* @package Doctrine * @package Doctrine
* @since 1.0
*/ */
class Doctrine_ClassMetadata_Factory class Doctrine_ClassMetadata_Factory
{ {
...@@ -12,10 +32,18 @@ class Doctrine_ClassMetadata_Factory ...@@ -12,10 +32,18 @@ class Doctrine_ClassMetadata_Factory
protected $_driver; protected $_driver;
/** /**
* * The already loaded metadata objects.
*/ */
protected $_loadedMetadata = array(); protected $_loadedMetadata = array();
/**
* Constructor.
* Creates a new factory instance that uses the given connection and metadata driver
* implementations.
*
* @param $conn The connection to use.
* @param $driver The metadata driver to use.
*/
public function __construct(Doctrine_Connection $conn, $driver) public function __construct(Doctrine_Connection $conn, $driver)
{ {
$this->_conn = $conn; $this->_conn = $conn;
...@@ -87,7 +115,6 @@ class Doctrine_ClassMetadata_Factory ...@@ -87,7 +115,6 @@ class Doctrine_ClassMetadata_Factory
$this->_addInheritedRelations($subClass, $parent); $this->_addInheritedRelations($subClass, $parent);
$this->_loadMetadata($subClass, $subclassName); $this->_loadMetadata($subClass, $subclassName);
if ($parent->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { if ($parent->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
//echo "<br />". $subClass->getClassName() . $parent->getTableName() . "<br />";
$subClass->setTableName($parent->getTableName()); $subClass->setTableName($parent->getTableName());
} }
$classes[$subclassName] = $subClass; $classes[$subclassName] = $subClass;
...@@ -98,12 +125,9 @@ class Doctrine_ClassMetadata_Factory ...@@ -98,12 +125,9 @@ class Doctrine_ClassMetadata_Factory
protected function _addInheritedFields($subClass, $parentClass) protected function _addInheritedFields($subClass, $parentClass)
{ {
foreach ($parentClass->getColumns() as $name => $definition) { foreach ($parentClass->getColumns() as $name => $definition) {
/*if (isset($definition['autoincrement']) && $definition['autoincrement'] === true) {
unset($definition['autoincrement']);
}*/
$fullName = "$name as " . $parentClass->getFieldName($name); $fullName = "$name as " . $parentClass->getFieldName($name);
$definition['inherited'] = true; $definition['inherited'] = true;
$subClass->setColumn($fullName, $definition['type'], $definition['length'], $subClass->addMappedColumn($fullName, $definition['type'], $definition['length'],
$definition); $definition);
} }
} }
...@@ -145,7 +169,7 @@ class Doctrine_ClassMetadata_Factory ...@@ -145,7 +169,7 @@ class Doctrine_ClassMetadata_Factory
} }
// save parents // save parents
$class->setOption('parents', $names); $class->setParentClasses($names);
// load further metadata // load further metadata
$this->_driver->loadMetadataForClass($name, $class); $this->_driver->loadMetadataForClass($name, $class);
...@@ -244,13 +268,13 @@ class Doctrine_ClassMetadata_Factory ...@@ -244,13 +268,13 @@ class Doctrine_ClassMetadata_Factory
$found = true; $found = true;
if ($value) { if ($value) {
$class->setOption('sequenceName', $value); $class->setTableOption('sequenceName', $value);
} else { } else {
if (($sequence = $class->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) { if (($sequence = $class->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
$class->setOption('sequenceName', $sequence); $class->setTableOption('sequenceName', $sequence);
} else { } else {
$class->setOption('sequenceName', $class->getConnection() $class->setTableOption('sequenceName', $class->getConnection()
->getSequenceName($class->getOption('tableName'))); ->getSequenceName($class->getTableName()));
} }
} }
break; break;
......
...@@ -60,7 +60,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int ...@@ -60,7 +60,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
*/ */
public function hasChildren() public function hasChildren()
{ {
return (($this->getRightValue() - $this->getLeftValue() ) >1 ); return (($this->getRightValue() - $this->getLeftValue()) > 1);
} }
/** /**
......
...@@ -16,7 +16,7 @@ class Orm_Component_TestTest extends Doctrine_OrmTestCase ...@@ -16,7 +16,7 @@ class Orm_Component_TestTest extends Doctrine_OrmTestCase
public function testFixture() public function testFixture()
{ {
$forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u"); $forumUsers = $this->sharedFixture['connection']->query("FROM Forum_User u");
$this->assertEquals(2, count($forumUsers)); $this->assertEquals(2, count($forumUsers));
$forumUsers[0]->delete(); $forumUsers[0]->delete();
unset($forumUsers[0]); unset($forumUsers[0]);
...@@ -25,7 +25,7 @@ class Orm_Component_TestTest extends Doctrine_OrmTestCase ...@@ -25,7 +25,7 @@ class Orm_Component_TestTest extends Doctrine_OrmTestCase
public function testFixture2() public function testFixture2()
{ {
$forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u"); $forumUsers = $this->sharedFixture['connection']->query("FROM Forum_User u");
$this->assertEquals(2, count($forumUsers)); $this->assertEquals(2, count($forumUsers));
} }
} }
\ No newline at end of file
<?php <?php
$fixture = array( $fixture = array(
'model' => 'ForumUser', 'model' => 'Forum_User',
'rows' => array( 'rows' => array(
array( array(
'id' => 1, 'id' => 1,
......
<?php
class ForumUser extends Doctrine_Record
{
public static function initMetadata($class)
{
$class->setColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$class->setColumn('username', 'string', 255);
}
}
\ No newline at end of file
<?php
class Forum_User extends Doctrine_Record
{
public static function initMetadata($class)
{
// inheritance mapping
$class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array(
'discriminatorColumn' => 'dtype',
'discriminatorMap' => array(
1 => 'Forum_User',
2 => 'Forum_Administrator')
));
$class->setSubclasses(array('Forum_Administrator'));
// property mapping
$class->addMappedColumn('id', 'integer', 4, array(
'primary' => true,
'autoincrement' => true));
$class->addMappedColumn('username', 'string', 50);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment