1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

Merged r3518:r3700 from branch to trunk. Branch to be deleted, soon. Development continues in trunk.

This commit is contained in:
romanb 2008-02-03 21:29:57 +00:00
parent cf808531ca
commit 56407f785a
235 changed files with 3943 additions and 2161 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,18 @@
<?php
/**
* The code metadata driver loads the metadata of the classes through invoking
* a static callback method that needs to be implemented when using this driver.
*
* @author Roman Borschel <roman@code-factory.org>
*/
class Doctrine_ClassMetadata_CodeDriver
{
/**
* Loads the metadata for the specified class into the provided container.
*/
public function loadMetadataForClass($className, Doctrine_ClassMetadata $metadata)
{
call_user_func_array(array($className, 'initMetadata'), array($metadata));
}
}

View file

@ -0,0 +1,3 @@
<?php
class Doctrine_ClassMetadata_Exception extends Doctrine_Exception {}

View file

@ -0,0 +1,276 @@
<?php
/**
* A table factory is used to create table objects and load them with meta data.
*
* @todo Support different drivers for loading the metadata from different sources.
* @package Doctrine
*/
class Doctrine_ClassMetadata_Factory
{
protected $_conn;
protected $_driver;
/**
*
*/
protected $_loadedMetadata = array();
public function __construct(Doctrine_Connection $conn, $driver)
{
$this->_conn = $conn;
$this->_driver = $driver;
}
/**
* Returns the metadata object for a class.
*
* @param string $className The name of the class.
* @return Doctrine_Metadata
*/
public function getMetadataFor($className)
{
if (isset($this->_loadedMetadata[$className])) {
return $this->_loadedMetadata[$className];
}
$this->_loadClasses($className, $this->_loadedMetadata);
return $this->_loadedMetadata[$className];
}
/**
* Loads the metadata of the class in question and all it's ancestors whose metadata
* is still not loaded.
*
* @param string $name The name of the class for which the metadata should get loaded.
* @param array $tables The metadata collection to which the loaded metadata is added.
*/
protected function _loadClasses($name, array &$classes)
{
$parentClass = $name;
$parentClasses = array();
$loadedParentClass = false;
while ($parentClass = get_parent_class($parentClass)) {
if ($parentClass == 'Doctrine_Record') {
break;
}
if (isset($classes[$parentClass])) {
$loadedParentClass = $parentClass;
break;
}
$parentClasses[] = $parentClass;
}
$parentClasses = array_reverse($parentClasses);
$parentClasses[] = $name;
if ($loadedParentClass) {
$class = $classes[$loadedParentClass];
} else {
$rootClassOfHierarchy = count($parentClasses) > 0 ? array_shift($parentClasses) : $name;
$class = new Doctrine_ClassMetadata($rootClassOfHierarchy, $this->_conn);
$this->_loadMetadata($class, $rootClassOfHierarchy);
$classes[$rootClassOfHierarchy] = $class;
}
if (count($parentClasses) == 0) {
return $class;
}
// load metadata of subclasses
// -> child1 -> child2 -> $name
$parent = $class;
foreach ($parentClasses as $subclassName) {
$subClass = new Doctrine_ClassMetadata($subclassName, $this->_conn);
$subClass->setInheritanceType($parent->getInheritanceType(), $parent->getInheritanceOptions());
$this->_addInheritedFields($subClass, $parent);
$this->_addInheritedRelations($subClass, $parent);
$this->_loadMetadata($subClass, $subclassName);
if ($parent->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
//echo "<br />". $subClass->getClassName() . $parent->getTableName() . "<br />";
$subClass->setTableName($parent->getTableName());
}
$classes[$subclassName] = $subClass;
$parent = $subClass;
}
}
protected function _addInheritedFields($subClass, $parentClass)
{
foreach ($parentClass->getColumns() as $name => $definition) {
/*if (isset($definition['autoincrement']) && $definition['autoincrement'] === true) {
unset($definition['autoincrement']);
}*/
$fullName = "$name as " . $parentClass->getFieldName($name);
$definition['inherited'] = true;
$subClass->setColumn($fullName, $definition['type'], $definition['length'],
$definition);
}
}
protected function _addInheritedRelations($subClass, $parentClass) {
foreach ($parentClass->getRelationParser()->getRelations() as $name => $relation) {
$subClass->getRelationParser()->addRelation($name, $relation);
}
}
/**
* Current code driver.
*/
protected function _loadMetadata(Doctrine_ClassMetadata $class, $name)
{
if ( ! class_exists($name) || empty($name)) {
/*try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString();
}*/
throw new Doctrine_Exception("Couldn't find class " . $name . ".");
}
$names = array();
$className = $name;
// get parent classes
do {
if ($className === 'Doctrine_Record') {
break;
} else if ($className == $name) {
continue;
}
$names[] = $className;
} while ($className = get_parent_class($className));
if ($className === false) {
throw new Doctrine_ClassMetadata_Factory_Exception("Unknown component '$className'.");
}
// save parents
$class->setOption('parents', $names);
// load further metadata
$this->_driver->loadMetadataForClass($name, $class);
$tableName = $class->getTableName();
if ( ! isset($tableName)) {
$class->setTableName(Doctrine::tableize($class->getClassName()));
}
$this->_initIdentifier($class);
return $class;
}
/**
* Code driver.
*
* @todo Move to code driver.
*/
/*protected function _loadMetadataFromCode($class, $name)
{
call_user_func_array(array($name, 'initMetadata'), array($class));
}*/
/**
* Initializes the class identifier(s)/primary key(s).
*
* @param Doctrine_Metadata The metadata container of the class in question.
*/
protected function _initIdentifier(Doctrine_ClassMetadata $class)
{
switch (count($class->getIdentifier())) {
case 0:
if ($class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED &&
count($class->getOption('parents')) > 0) {
$parents = $class->getOption('parents');
$root = end($parents);
$rootClass = $class->getConnection()->getMetadata($root);
$class->setIdentifier($rootClass->getIdentifier());
if ($class->getIdentifierType() !== Doctrine::IDENTIFIER_AUTOINC) {
$class->setIdentifierType($rootClass->getIdentifierType());
} else {
$class->setIdentifierType(Doctrine::IDENTIFIER_NATURAL);
}
// add all inherited primary keys
foreach ((array) $class->getIdentifier() as $id) {
$definition = $rootClass->getDefinitionOf($id);
// inherited primary keys shouldn't contain autoinc
// and sequence definitions
unset($definition['autoincrement']);
unset($definition['sequence']);
// add the inherited primary key column
$fullName = $rootClass->getColumnName($id) . ' as ' . $id;
$class->setColumn($fullName, $definition['type'], $definition['length'],
$definition, true);
}
} else {
$definition = array('type' => 'integer',
'length' => 20,
'autoincrement' => true,
'primary' => true);
$class->setColumn('id', $definition['type'], $definition['length'], $definition, true);
$class->setIdentifier('id');
$class->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC);
}
break;
case 1:
foreach ($class->getIdentifier() as $pk) {
$columnName = $class->getColumnName($pk);
$thisColumns = $class->getColumns();
$e = $thisColumns[$columnName];
$found = false;
foreach ($e as $option => $value) {
if ($found) {
break;
}
$e2 = explode(':', $option);
switch (strtolower($e2[0])) {
case 'autoincrement':
case 'autoinc':
$class->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC);
$found = true;
break;
case 'seq':
case 'sequence':
$class->setIdentifierType(Doctrine::IDENTIFIER_SEQUENCE);
$found = true;
if ($value) {
$class->setOption('sequenceName', $value);
} else {
if (($sequence = $class->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
$class->setOption('sequenceName', $sequence);
} else {
$class->setOption('sequenceName', $class->getConnection()
->getSequenceName($class->getOption('tableName')));
}
}
break;
}
}
$identifierType = $class->getIdentifierType();
if ( ! isset($identifierType)) {
$class->setIdentifierType(Doctrine::IDENTIFIER_NATURAL);
}
}
$class->setIdentifier($pk);
break;
default:
$class->setIdentifierType(Doctrine::IDENTIFIER_COMPOSITE);
}
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* The yaml driver loads metadata informations about classes from .yml files.
*
*/
class Doctrine_ClassMetadata_YamlDriver
{
/**
*
*/
public function loadMetadataForClass($className, Doctrine_ClassMetadata $metadata)
{
throw new Doctrine_ClassMetadata_Exception("YAML driver not yet implemented.");
}
}

View file

@ -1,158 +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_Column
* This class represents a database column
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine
* @subpackage Column
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Countable
{
/**
* @var array $definition
*/
protected $_definition = array(
'type' => null,
'length' => 0,
);
/**
* @var array $definition
*/
public function __construct(array $definition = array())
{
$this->_definition = $definition;
}
/**
* @return array
*/
public function getDefinition()
{
return $this->_definition;
}
/**
* contains
*
* @return boolean
*/
public function contains($name)
{
return isset($this->_definition[$name]);
}
/**
* get
*
* @param string $name
* @return mixed
*/
public function get($name)
{
if ( ! isset($this->_definition[$name])) {
return null;
}
return $this->_definition[$name];
}
/**
* set
*
* @param string $name
* @return mixed
*/
public function set($name, $value)
{
$this->_definition[$name] = $value;
}
/**
* @param string $field
* @return array
*/
public function getEnumValues()
{
if (isset($this->_definition['values'])) {
return $this->_definition['values'];
} else {
return array();
}
}
/**
* enumValue
*
* @param string $field
* @param integer $index
* @return mixed
*/
public function enumValue($index)
{
if ($index instanceof Doctrine_Null) {
return $index;
}
return isset($this->_definition['values'][$index]) ? $this->_definition['values'][$index] : $index;
}
/**
* enumIndex
*
* @param string $field
* @param mixed $value
* @return mixed
*/
public function enumIndex($field, $value)
{
$values = $this->getEnumValues($field);
return array_search($value, $values);
}
/**
* count
*
* @return integer
*/
public function count()
{
return count($this->_definition);
}
/**
* getIterator
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_definition);
}
}

View file

@ -111,8 +111,8 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
$this->setEventListener($value);
break;
case Doctrine::ATTR_COLL_KEY:
if ( ! ($this instanceof Doctrine_Table)) {
throw new Doctrine_Exception("This attribute can only be set at table level.");
if ( ! ($this instanceof Doctrine_ClassMetadata)) {
throw new Doctrine_Exception("This attribute can only be set at class level.");
}
if ($value !== null && ! $this->hasField($value)) {
throw new Doctrine_Exception("Couldn't set collection key attribute. No such field '$value'");
@ -320,6 +320,11 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
return $this;
}
/*
public function removeRecordListeners()
{
$this->attributes[Doctrine::ATTR_RECORD_LISTENER] =
}*/
/**
* addListener
@ -364,8 +369,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
public function setListener($listener)
{
if ( ! ($listener instanceof Doctrine_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
&& ! ($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;

View file

@ -56,23 +56,23 @@ Doctrine::autoload('Doctrine_Configurable');
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate
{
/**
* @var $dbh the database handler
* The PDO database handle.
*
* @var PDO
*/
protected $dbh;
/**
* The metadata factory is used to retrieve the metadata of classes.
*
* @var Doctrine_ClassMetadata_Factory
*/
protected $_tableFactory;
protected $_metadataFactory;
/**
* @var array $tables an array containing all the initialized Doctrine_Table objects
* keys representing component names and values as Doctrine_Table objects
*/
protected $tables = array();
/**
* @var array An array of mapper objects currently maintained by this connection.
* An array of mapper objects currently maintained by this connection.
*
* @var array
*/
protected $_mappers = array();
@ -86,19 +86,24 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
protected $_name;
/**
* @var string $driverName the name of this connection driver
* The name of this connection driver.
*
* @var string $driverName
*/
protected $driverName;
/**
* @var boolean $isConnected whether or not a connection has been established
* Whether or not a connection has been established.
*
* @var boolean $isConnected
*/
protected $isConnected = false;
protected $isConnected = false;
/**
* @var array $supported an array containing all features this driver supports,
* keys representing feature names and values as
* one of the following (true, false, 'emulated')
* An array containing all features this driver supports, keys representing feature
* names and values as one of the following (true, false, 'emulated').
*
* @var array $supported
*/
protected $supported = array();
@ -167,12 +172,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/
protected $serverInfo = array();
/**
*
*/
protected $options = array();
/**
* @var array $availableDrivers an array containing all available drivers
*/
private static $availableDrivers = array(
private static $availableDrivers = array(
'Mysql',
'Pgsql',
'Oracle',
@ -383,12 +391,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function getDbh()
{
$this->connect();
return $this->dbh;
}
/**
* connect
* connects into database
* Establishes the connection with the database.
*
* @return boolean
*/
@ -401,7 +409,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$event = new Doctrine_Event($this, Doctrine_Event::CONN_CONNECT);
$this->getListener()->preConnect($event);
$e = explode(':', $this->options['dsn']);
$e = explode(':', $this->options['dsn']);
$found = false;
if (extension_loaded('pdo')) {
@ -438,8 +446,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->getListener()->postConnect($event);
return true;
}
public function incrementQueryCount()
/**
* @todo Remove. Breaks encapsulation.
*/
public function incrementQueryCount()
{
$this->_count++;
}
@ -450,8 +461,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param
*/
public function driverName($name)
{
}
{}
/**
* supports
@ -498,7 +508,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @throws Doctrine_Connection_Exception if some of the key values was null
* @throws Doctrine_Connection_Exception if there were no key fields
* @throws PDOException if something fails at PDO level
* @ return integer number of rows affected
* @return integer number of rows affected
*/
public function replace(Doctrine_Table $table, array $fields, array $keys)
{
@ -537,8 +547,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string $table The table to delete data from
* @param array $identifier An associateve array containing identifier fieldname-value pairs.
* @return integer The number of affected rows
*
* @todo First argument should just be a table name. Move the conversion from
* field to column names one layer up.
*/
public function delete(Doctrine_Table $table, array $identifier)
public function delete(Doctrine_ClassMetadata $table, array $identifier)
{
$criteria = array();
foreach (array_keys($identifier) as $id) {
@ -560,8 +573,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $values An associateve array containing column-value pairs.
* @return mixed boolean false if empty value array was given,
* otherwise returns the number of affected rows
*
* @todo First argument should just be a table name. Move the conversion from
* field to column names one layer up.
*/
public function update(Doctrine_Table $table, array $fields, array $identifier)
public function update(Doctrine_ClassMetadata $table, array $fields, array $identifier)
{
if (empty($fields)) {
return false;
@ -594,8 +610,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $fields An associateve array containing fieldname-value pairs.
* @return mixed boolean false if empty value array was given,
* otherwise returns the number of affected rows
*
* @todo First argument should just be a table name. Move the conversion from
* field to column names one layer up.
*/
public function insert(Doctrine_Table $table, array $fields)
public function insert(Doctrine_ClassMetadata $table, array $fields)
{
if (empty($fields)) {
return false;
@ -933,6 +952,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
try {
if ( ! empty($params)) {
//echo $query . "<br />";
$stmt = $this->prepare($query);
$stmt->execute($params);
return $stmt;
@ -1008,6 +1028,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR);
$this->getListener()->preError($event);
/*if (strstr($e->getMessage(), 'no such column')) {
echo $e->getMessage() . "<br />" . $e->getTraceAsString() . "<br />";
}*/
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
$exc = new $name($e->getMessage(), (int) $e->getCode());
@ -1036,31 +1060,49 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* Gets the table object that represents the database table that is used to
* persist the specified domain class.
* Returns the metadata for a class.
*
* @param string $name component name
* @return Doctrine_Table
* @return Doctrine_Metadata
* @todo package:orm
*/
public function getTable($className)
public function getMetadata($className)
{
if (isset($this->tables[$className])) {
return $this->tables[$className];
}
if (!($this->_tableFactory instanceOf Doctrine_Table_Factory)) {
$this->_tableFactory = new Doctrine_Table_Factory($this);
}
$this->_tableFactory->loadTables($className, $this->tables);
return $this->tables[$className];
return $this->getClassMetadata($className);
}
/**
* Returns the metadata for a class.
*
* @return Doctrine_Metadata
* @todo package:orm
*/
public function getClassMetadata($className)
{
if ( ! $this->_metadataFactory) {
$this->_metadataFactory = new Doctrine_ClassMetadata_Factory($this,
new Doctrine_ClassMetadata_CodeDriver());
}
return $this->_metadataFactory->getMetadataFor($className);
}
/**
* Sets the driver that is used to obtain metadata informations about entity
* classes.
*
* @param $driver The driver to use.
*/
public function setClassMetadataDriver($driver)
{
$this->_metadataFactory->setDriver($driver);
}
/**
* Gets a mapper for the specified domain class that is used to map instances of
* the class between the relational database and their object representation.
*
* @return Doctrine_Mapper_Abstract The mapper object.
* @return Doctrine_Mapper The mapper object.
* @todo package:orm
*/
public function getMapper($className)
{
@ -1069,20 +1111,19 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
$customMapperClass = $className . 'Mapper';
$metadata = $this->getMetadata($className);
if (class_exists($customMapperClass, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) &&
in_array('Doctrine_Mapper_Abstract', class_parents($customMapperClass))) {
$table = $this->getTable($className);
$mapper = new $customMapperClass($className, $table);
$mapper = new $customMapperClass($className, $metadata);
} else {
// instantiate correct mapper type
$table = $this->getTable($className);
$inheritanceType = $table->getInheritanceType();
$inheritanceType = $metadata->getInheritanceType();
if ($inheritanceType == Doctrine::INHERITANCETYPE_JOINED) {
$mapper = new Doctrine_Mapper_Joined($className, $table);
$mapper = new Doctrine_Mapper_Joined($className, $metadata);
} else if ($inheritanceType == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
$mapper = new Doctrine_Mapper_SingleTable($className, $table);
$mapper = new Doctrine_Mapper_SingleTable($className, $metadata);
} else if ($inheritanceType == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) {
$mapper = new Doctrine_Mapper_TablePerClass($className, $table);
$mapper = new Doctrine_Mapper_TablePerClass($className, $metadata);
} else {
throw new Doctrine_Connection_Exception("Unknown inheritance type '$inheritanceType'. Can't create mapper.");
}
@ -1094,23 +1135,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* returns an array of all initialized tables
* Gets all mappers that are currently maintained by the connection.
*
* @return array
* @todo package:orm
*/
public function getTables()
{
return $this->tables;
}
public function getMappers()
{
//var_dump($this->_mappers);
return $this->_mappers;
}
/**
* returns an iterator that iterators through all
* returns an iterator that iterates through all
* initialized table objects
*
* <code>
@ -1127,33 +1162,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* returns the count of initialized table objects
* Returns the number of queries executed by the connection.
*
* @return integer
* @todo Better name: getQueryCount()
*/
public function count()
{
return $this->_count;
}
/**
* addTable
* adds a Doctrine_Table object into connection registry
*
* @param $table a Doctrine_Table object to be added into registry
* @return boolean
*/
public function addTable(Doctrine_Table $table)
{
$name = $table->getComponentName();
if (isset($this->tables[$name])) {
return false;
}
$this->tables[$name] = $table;
return true;
}
/**
* create
* creates a record
@ -1161,6 +1179,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* create creates a record
* @param string $name component name
* @return Doctrine_Record Doctrine_Record object
* @todo Any strong reasons why this should not be removed?
* @todo package:orm
*/
public function create($name)
{
@ -1169,12 +1189,18 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/**
* Creates a new Doctrine_Query object that operates on this connection.
*
*
* @return Doctrine_Query
* @todo package:orm
*/
public function createQuery()
public function createQuery($dql = "")
{
return new Doctrine_Query($this);
$query = new Doctrine_Query($this);
if ( ! empty($dql)) {
$query->parseQuery($dql);
}
return $query;
}
/**
@ -1184,6 +1210,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*
* @throws PDOException if something went wrong at database level
* @return void
* @todo package:orm
*/
public function flush()
{
@ -1197,6 +1224,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* clears all repositories
*
* @return void
* @todo package:orm
*/
public function clear()
{
@ -1211,6 +1239,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* evicts all tables
*
* @return void
* @todo package:orm
*/
public function evictTables()
{
@ -1220,8 +1249,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* close
* closes the connection
* Closes the connection.
*
* @return void
*/
@ -1239,9 +1267,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* get the current transaction nesting level
* Returns the current total transaction nesting level.
*
* @return integer
* @return integer The nesting level. A value of 0 means theres no active transaction.
*/
public function getTransactionLevel()
{
@ -1249,9 +1277,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* get the current internal transaction nesting level
* Returns the current internal transaction nesting level.
*
* @return integer
* @return integer The nesting level. A value of 0 means theres no active transaction.
* @todo package:orm???
*/
public function getInternalTransactionLevel()
{
@ -1267,6 +1296,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function errorCode()
{
$this->connect();
return $this->dbh->errorCode();
}
@ -1279,6 +1309,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function errorInfo()
{
$this->connect();
return $this->dbh->errorInfo();
}
@ -1297,12 +1328,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* getResultCacheDriver
*
* @return Doctrine_Cache_Interface
* @todo package:orm
*/
public function getResultCacheDriver()
{
if ( ! $this->getAttribute(Doctrine::ATTR_RESULT_CACHE)) {
throw new Doctrine_Exception('Result Cache driver not initialized.');
}
return $this->getAttribute(Doctrine::ATTR_RESULT_CACHE);
}
@ -1310,12 +1343,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* getQueryCacheDriver
*
* @return Doctrine_Cache_Interface
* @todo package:orm
*/
public function getQueryCacheDriver()
{
if ( ! $this->getAttribute(Doctrine::ATTR_QUERY_CACHE)) {
throw new Doctrine_Exception('Query Cache driver not initialized.');
}
return $this->getAttribute(Doctrine::ATTR_QUERY_CACHE);
}
@ -1328,8 +1363,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* Note: This method may not return a meaningful or consistent result across different drivers,
* because the underlying database may not even support the notion of auto-increment fields or sequences.
*
* @param string $table name of the table into which a new row was inserted
* @param string $field name of the field into which a new row was inserted
* @param string $table Name of the table into which a new row was inserted.
* @param string $field Name of the field into which a new row was inserted.
*/
public function lastInsertId($table = null, $field = null)
{
@ -1359,6 +1394,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*
* This method must only be used by Doctrine itself to initiate transactions.
* Userland-code must use {@link beginTransaction()}.
*
* @todo package:orm???
*/
public function beginInternalTransaction($savepoint = null)
{

View file

@ -1068,7 +1068,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
* @return void
*/
public function exportClasses(array $classes)
{
{
$connections = array();
foreach ($classes as $class) {
$record = new $class();
@ -1083,6 +1083,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
}
$sql = $this->exportClassesSql(array($class));
// Build array of all the creates
// We need these to happen first
foreach ($sql as $key => $query) {
@ -1137,29 +1138,37 @@ class Doctrine_Export extends Doctrine_Connection_Module
* occurred during the create table operation
* @param array $classes
* @return void
* @todo package:orm
*/
public function exportClassesSql(array $classes)
{
$models = Doctrine::filterInvalidModels($classes);
$sql = array();
$finishedClasses = array();
foreach ($models as $name) {
$record = new $name();
$table = $record->getTable();
$parents = $table->getOption('joinedParents');
foreach ($parents as $parent) {
$data = $table->getConnection()->getTable($parent)->getExportableFormat();
$query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']);
$sql = array_merge($sql, (array) $query);
if (in_array($name, $finishedClasses)) {
continue;
}
$data = $table->getExportableFormat();
$classMetadata = $this->conn->getClassMetadata($name);
// In Class Table Inheritance we have to make sure that ALL tables are exported
// as soon as ONE table is exported, because the data of one class is stored
// across many tables.
if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) {
//echo "joined.<br />";
$parents = $classMetadata->getOption('parents');
foreach ($parents as $parent) {
$data = $classMetadata->getConnection()->getClassMetadata($parent)->getExportableFormat();
$query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']);
$sql = array_merge($sql, (array) $query);
$finishedClasses[] = $parent;
}
}
$data = $classMetadata->getExportableFormat();
$query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']);
if (is_array($query)) {
@ -1168,8 +1177,8 @@ class Doctrine_Export extends Doctrine_Connection_Module
$sql[] = $query;
}
if ($table->getAttribute(Doctrine::ATTR_EXPORT) & Doctrine::EXPORT_PLUGINS) {
$sql = array_merge($sql, $this->exportGeneratorsSql($table));
if ($classMetadata->getAttribute(Doctrine::ATTR_EXPORT) & Doctrine::EXPORT_PLUGINS) {
$sql = array_merge($sql, $this->exportGeneratorsSql($classMetadata));
}
}
@ -1185,8 +1194,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
*
* @param Doctrine_Table $table table object to retrieve the generators from
* @return array an array of Doctrine_Record_Generator objects
* @todo package:orm
*/
public function getAllGenerators(Doctrine_Table $table)
public function getAllGenerators(Doctrine_ClassMetadata $table)
{
$generators = array();
@ -1213,11 +1223,12 @@ class Doctrine_Export extends Doctrine_Connection_Module
*
* @param Doctrine_Table $table the table in which the generators belong to
* @return array an array of sql strings
* @todo package:orm
*/
public function exportGeneratorsSql(Doctrine_Table $table)
public function exportGeneratorsSql(Doctrine_ClassMetadata $class)
{
$sql = array();
foreach ($this->getAllGenerators($table) as $name => $generator) {
foreach ($this->getAllGenerators($class) as $name => $generator) {
$table = $generator->getTable();
// Make sure plugin has a valid table

View file

@ -60,16 +60,15 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
*/
public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null)
{
//$s = microtime(true);
$this->_tableAliases = $tableAliases;
if ($hydrationMode === null) {
$hydrationMode = $this->_hydrationMode;
}
if ($hydrationMode == Doctrine::HYDRATE_NONE) {
return $stmt->fetchAll(PDO::FETCH_NUM);
}
if ($hydrationMode === null) {
$hydrationMode = $this->_hydrationMode;
}
$this->_tableAliases = $tableAliases;
if ($hydrationMode === Doctrine::HYDRATE_ARRAY) {
$driver = new Doctrine_Hydrator_ArrayDriver();
@ -108,7 +107,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
foreach ($this->_queryComponents as $dqlAlias => $data) {
$data['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
$componentName = $data['mapper']->getComponentName();
$listeners[$componentName] = $data['table']->getRecordListener();
$listeners[$componentName] = $data['mapper']->getRecordListener();
$identifierMap[$dqlAlias] = array();
$prev[$dqlAlias] = array();
$id[$dqlAlias] = '';

View file

@ -20,8 +20,8 @@
*/
/**
* Doctrine_Hydrate_Array
* defines an array fetching strategy for Doctrine_Hydrate
* Doctrine_Hydrator_ArrayDriver
* Defines an array fetching strategy.
*
* @package Doctrine
* @subpackage Hydrate
@ -33,47 +33,69 @@
*/
class Doctrine_Hydrator_ArrayDriver
{
/**
*
*/
public function getElementCollection($component)
{
return array();
}
/**
*
*/
public function getElement(array $data, $component)
{
return $data;
}
/**
*
*/
public function isIdentifiable(array $data, Doctrine_Table $table)
{
return ( ! empty($data));
}
/**
*
*/
public function registerCollection($coll)
{
}
{ /* Nothing to do */ }
/**
*
*/
public function initRelated(array &$data, $name)
{
if ( ! isset($data[$name])) {
$data[$name] = array();
}
return true;
}
/**
*
*/
public function getNullPointer()
{
return null;
}
/**
*
*/
public function getLastKey(&$data)
{
end($data);
return key($data);
}
/**
*
*/
public function flush()
{
}
{ /* Nothing to do */ }
}

View file

@ -104,11 +104,11 @@ class Doctrine_Hydrator_RecordDriver extends Doctrine_Locator_Injectable
public function getElement(array $data, $component)
{
$component = $this->_getClassnameToReturn($data, $component);
if ( ! isset($this->_mappers[$component])) {
$this->_mappers[$component] = Doctrine_Manager::getInstance()->getMapper($component);
}
$component = $this->_getClassnameToReturn($data, $component);
$record = $this->_mappers[$component]->getRecord($data);
if ( ! isset($this->_records[$record->getOid()]) ) {
@ -128,35 +128,31 @@ class Doctrine_Hydrator_RecordDriver extends Doctrine_Locator_Injectable
}
/**
* Check the dataset for a discriminator column, to determine the correct
* Check the dataset for a discriminator column to determine the correct
* class to instantiate. If no discriminator column is found, the given
* classname will be returned.
*
* @todo this function could use reflection to check the first time it runs
* if the subclassing option is not set.
*
* @return string The name of the class to instantiate.
*
* @todo Can be optimized performance-wise.
*/
protected function _getClassnameToReturn(array $data, $className)
{
$subClasses = $this->_mappers[$className]->getTable()->getOption('subclasses');
if ( ! isset($subClasses)) {
if ( ! isset($this->_mappers[$className])) {
$this->_mappers[$className] = Doctrine_Manager::getInstance()->getMapper($className);
}
$discCol = $this->_mappers[$className]->getTable()->getInheritanceOption('discriminatorColumn');
if ( ! $discCol) {
return $className;
}
foreach ($subClasses as $subclass) {
if ( ! isset($this->_mappers[$subclass])) {
$this->_mappers[$subclass] = Doctrine_Manager::getInstance()->getMapper($subclass);
}
$mapper = $this->_mappers[$subclass];
$inheritanceMap = $mapper->getDiscriminatorColumn();
foreach ($inheritanceMap as $key => $value) {
if (isset($data[$key]) && $data[$key] == $value) {
return $mapper->getComponentName();
}
$discMap = $this->_mappers[$className]->getTable()->getInheritanceOption('discriminatorMap');
foreach ($discMap as $value => $class) {
if (isset($data[$discCol]) && $data[$discCol] == $value) {
return $class;
}
}
return $className;
}
}

View file

@ -64,6 +64,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
protected $_queryRegistry;
/**
*
*/
protected static $driverMap = array('oci' => 'oracle');
/**
@ -476,6 +479,32 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return $this->_connections[$name];
}
/**
* Creates a new Doctrine_Query object that uses the currently active connection.
*
* @return Doctrine_Query
*/
public function createQuery($dql = "")
{
$query = new Doctrine_Query($this->getCurrentConnection());
if ( ! empty($dql)) {
$query->parseQuery($dql);
}
return $query;
}
/**
* Creates a query object out of a registered, named query.
*
* @param string $name The name of the query.
* @return Doctrine_Query The query object.
*/
public function createNamedQuery($name)
{
return $this->_queryRegistry->get($name);
}
/**
* getComponentAlias

View file

@ -31,14 +31,13 @@
* @link www.phpdoctrine.org
* @since 1.0
*/
abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
implements Countable
abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable implements Countable
{
/**
* @var Doctrine_Table Metadata container that represents the database table this
* mapper is mapping objects to.
*/
protected $_table;
protected $_classMetadata;
/**
* The name of the domain class this mapper is used for.
@ -82,11 +81,11 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
* @param Doctrine_Table $table The table object used for the mapping procedure.
* @throws Doctrine_Connection_Exception if there are no opened connections
*/
public function __construct($name, Doctrine_Table $table)
public function __construct($name, Doctrine_ClassMetadata $metadata)
{
$this->_domainClassName = $name;
$this->_conn = $table->getConnection();
$this->_table = $table;
$this->_conn = $metadata->getConnection();
$this->_classMetadata = $metadata;
$this->setParent($this->_conn);
$this->_repository = new Doctrine_Table_Repository($this);
}
@ -110,11 +109,13 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
* 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()
/*public function export()
{
$this->_conn->export->exportTable($this->_table);
}
}*/
/**
* getExportableFormat
@ -123,10 +124,10 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
* @return array
* @todo move to Table
*/
public function getExportableFormat($parseForeignKeys = true)
/*public function getExportableFormat($parseForeignKeys = true)
{
return $this->_table->getExportableFormat($parseForeignKeys);
}
}*/
/**
* createQuery
@ -169,9 +170,9 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
}
/**
* returns the connection associated with this table (if any)
* Returns the connection the mapper is currently using.
*
* @return Doctrine_Connection|null the connection object
* @return Doctrine_Connection|null The connection object.
*/
public function getConnection()
{
@ -207,8 +208,9 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
}
$id = is_array($id) ? array_values($id) : array($id);
return $this->createQuery()
->where(implode(' = ? AND ', (array) $this->_table->getIdentifier()) . ' = ?')
->where(implode(' = ? AND ', (array) $this->_classMetadata->getIdentifier()) . ' = ?')
->fetchOne($id, $hydrationMode);
}
@ -324,7 +326,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
*
* @param Doctrine_Record $record record to be added
* @return boolean
* @todo Better name? registerRecord?
* @todo Better name? registerRecord? Move elsewhere to the new location of the identity maps.
*/
public function addRecord(Doctrine_Record $record)
{
@ -346,6 +348,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
*
* @param Doctrine_Record $record record to be removed
* @return boolean
* @todo Move elsewhere to the new location of the identity maps.
*/
public function removeRecord(Doctrine_Record $record)
{
@ -369,7 +372,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
public function getRecord(array $data)
{
if ( ! empty($data)) {
$identifierFieldNames = $this->_table->getIdentifier();
$identifierFieldNames = $this->_classMetadata->getIdentifier();
if ( ! is_array($identifierFieldNames)) {
$identifierFieldNames = array($identifierFieldNames);
@ -386,8 +389,6 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
}
if ($found) {
//$recordName = $this->getClassnameToReturn();
//$record = new $recordName($this, true);
$record = new $this->_domainClassName($this, true, $data);
$data = array();
return $record;
@ -400,61 +401,17 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
$record = $this->_identityMap[$id];
$record->hydrate($data);
} else {
//$recordName = $this->getClassnameToReturn();
//$record = new $recordName($this);
$record = new $this->_domainClassName($this, false, $data);
$this->_identityMap[$id] = $record;
}
$data = array();
} else {
//$recordName = $this->getClassnameToReturn();
//$record = new $recordName($this, true);
$record = new $this->_domainClassName($this, true, $data);
}
return $record;
}
/**
* Get the classname to return. Most often this is just the options['name']
*
* USED FOR SINGLE TABLE INHERITANCE & CLASS TABLE INHERITANCE.
*
* Check the subclasses option and the inheritanceMap for each subclass to see
* if all the maps in a subclass is met. If this is the case return that
* subclass name. If no subclasses match or if there are no subclasses defined
* return the name of the class for this tables record.
*
* @todo this function could use reflection to check the first time it runs
* if the subclassing option is not set.
*
* @return string The name of the class to create
*
*/
/*public function getClassnameToReturn()
{
$subClasses = $this->_table->getOption('subclasses');
if ( ! isset($subClasses)) {
return $this->_domainClassName;
}
foreach ($subClasses as $subclass) {
$mapper = $this->_conn->getMapper($subclass);
$nomatch = false;
$inheritanceMap = $this->getDiscriminatorColumn($subclass);
foreach ($inheritanceMap as $key => $value) {
if ( ! isset($this->_data[$key]) || $this->_data[$key] != $value) {
$nomatch = true;
break;
}
}
if ( ! $nomatch) {
return $mapper->getComponentName();
}
}
return $this->_domainClassName;
}*/
/**
* @param $id database row id
* @throws Doctrine_Find_Exception
@ -462,9 +419,9 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
final public function getProxy($id = null)
{
if ($id !== null) {
$identifierColumnNames = $this->_table->getIdentifierColumnNames();
$identifierColumnNames = $this->_classMetadata->getIdentifierColumnNames();
$query = 'SELECT ' . implode(', ', $identifierColumnNames)
. ' FROM ' . $this->_table->getTableName()
. ' FROM ' . $this->_classMetadata->getTableName()
. ' WHERE ' . implode(' = ? && ', $identifierColumnNames) . ' = ?';
$query = $this->applyInheritance($query);
@ -476,6 +433,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
return false;
}
}
return $this->getRecord($data);
}
@ -486,15 +444,22 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
*/
final public function applyInheritance($where)
{
$inheritanceMap = $this->getDiscriminatorColumn();
$discCol = $this->_classMetadata->getInheritanceOption('discriminatorColumn');
if ( ! $discCol) {
return $where;
}
$discMap = $this->_classMetadata->getInheritanceOption('discriminatorMap');
$inheritanceMap = array($discCol => array_search($this->_domainClassName, $discMap));
if ( ! empty($inheritanceMap)) {
$a = array();
foreach ($inheritanceMap as $field => $value) {
$a[] = $this->_table->getColumnName($field) . ' = ?';
foreach ($inheritanceMap as $column => $value) {
$a[] = $column . ' = ?';
}
$i = implode(' AND ', $a);
$where .= ' AND ' . $i;
}
return $where;
}
@ -505,7 +470,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
*/
public function count()
{
$a = $this->_conn->execute('SELECT COUNT(1) FROM ' . $this->_table->getOption('tableName'))->fetch(Doctrine::FETCH_NUM);
$a = $this->_conn->execute('SELECT COUNT(1) FROM ' . $this->_classMetadata->getOption('tableName'))->fetch(Doctrine::FETCH_NUM);
return current($a);
}
@ -549,7 +514,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
} else if ($value === null) {
return null;
} else {
$type = $this->_table->getTypeOf($fieldName);
$type = $this->_classMetadata->getTypeOf($fieldName);
switch ($type) {
case 'integer':
@ -557,7 +522,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
// don't do any casting here PHP INT_MAX is smaller than what the databases support
break;
case 'enum':
return $this->_table->enumValue($fieldName, $value);
return $this->_classMetadata->enumValue($fieldName, $value);
break;
case 'boolean':
return (boolean) $value;
@ -590,10 +555,11 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
* getter for associated tree
*
* @return mixed if tree return instance of Doctrine_Tree, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public function getTree()
{
return $this->_table->getTree();
return $this->_classMetadata->getTree();
}
/**
@ -602,10 +568,11 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
* determine if table acts as tree
*
* @return mixed if tree return true, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public function isTree()
{
return $this->_table->isTree();
return $this->_classMetadata->isTree();
}
/**
@ -673,20 +640,22 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
} else if (substr($method, 0, 9) == 'findOneBy') {
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
}
}/* else {
throw new Doctrine_Mapper_Exception("Unknown method '$method'.");
}*/
if (isset($by)) {
if ( ! isset($arguments[0])) {
throw new Doctrine_Table_Exception('You must specify the value to findBy');
throw new Doctrine_Mapper_Exception('You must specify the value to findBy');
}
$fieldName = Doctrine::tableize($by);
$hydrationMode = isset($arguments[1]) ? $arguments[1]:null;
if ($this->_table->hasField($fieldName)) {
if ($this->_classMetadata->hasField($fieldName)) {
return $this->$method($fieldName, $arguments[0], $hydrationMode);
} else if ($this->_table->hasRelation($by)) {
$relation = $this->_table->getRelation($by);
} else if ($this->_classMetadata->hasRelation($by)) {
$relation = $this->_classMetadata->getRelation($by);
if ($relation['type'] === Doctrine_Relation::MANY) {
throw new Doctrine_Table_Exception('Cannot findBy many relationship.');
@ -727,7 +696,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
try {
$conn->beginInternalTransaction();
$saveLater = $this->saveRelated($record);
$saveLater = $this->_saveRelated($record);
//echo "num savelater:" . count($saveLater) . "<br />";
$record->state($state);
@ -814,13 +783,12 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
$fields[$seqName] = $id;
$record->assignIdentifier($id);
}
$this->_conn->insert($table, $fields);
if (empty($seq) && count($identifier) == 1 && $identifier[0] == $table->getIdentifier() &&
$table->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) {
if (strtolower($this->getName()) == 'pgsql') {
if (strtolower($this->_conn->getName()) == 'pgsql') {
$seq = $table->getTableName() . '_' . $identifier[0];
}
@ -874,16 +842,14 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
$record->postSave($event);
}
/**
* saveRelated
* _saveRelated
* saves all related records to $record
*
* @throws PDOException if something went wrong at database level
* @param Doctrine_Record $record
*/
protected function saveRelated(Doctrine_Record $record)
protected function _saveRelated(Doctrine_Record $record)
{
$saveLater = array();
foreach ($record->getReferences() as $k => $v) {
@ -934,12 +900,13 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
public function saveAssociations(Doctrine_Record $record)
{
foreach ($record->getReferences() as $relationName => $relatedObject) {
$rel = $record->getTable()->getRelation($relationName);
if ($rel instanceof Doctrine_Relation_Association) {
if ($rel instanceof Doctrine_Relation_Association) {
$relatedObject->save($this->_conn);
$assocTable = $rel->getAssociationTable();
foreach ($relatedObject->getDeleteDiff() as $r) {
$query = 'DELETE FROM ' . $assocTable->getTableName()
. ' WHERE ' . $rel->getForeign() . ' = ?'
@ -947,7 +914,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
$this->_conn->execute($query, array($r->getIncremented(), $record->getIncremented()));
}
foreach ($relatedObject->getInsertDiff() as $r) {
foreach ($relatedObject->getInsertDiff() as $r) {
$assocRecord = $this->_conn->getMapper($assocTable->getComponentName())->create();
$assocRecord->set($assocTable->getFieldName($rel->getForeign()), $r);
$assocRecord->set($assocTable->getFieldName($rel->getLocal()), $record);
@ -969,7 +936,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
{
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE);
$record->preUpdate($event);
$table = $this->_table;
$table = $this->_classMetadata;
$this->getRecordListener()->preUpdate($event);
if ( ! $event->skipOperation) {
@ -986,7 +953,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
{
$identifier = $record->identifier();
$array = $record->getPrepared();
$this->_conn->update($this->_table, $array, $identifier);
$this->_conn->update($this->_classMetadata, $array, $identifier);
$record->assignIdentifier(true);
}
@ -1048,7 +1015,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
$record->preDelete($event);
$this->getRecordListener()->preDelete($event);
$table = $this->_table;
$table = $this->_classMetadata;
$state = $record->state();
$record->state(Doctrine_Record::STATE_LOCKED);
@ -1074,7 +1041,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
$record->state(Doctrine_Record::STATE_TDIRTY);
$conn->delete($this->_table, $record->identifier());
$conn->delete($this->_classMetadata, $record->identifier());
$record->state(Doctrine_Record::STATE_TCLEAN);
$this->removeRecord($record);
@ -1095,7 +1062,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
*/
protected function deleteComposites(Doctrine_Record $record)
{
foreach ($this->_table->getRelations() as $fk) {
foreach ($this->_classMetadata->getRelations() as $fk) {
if ($fk->isComposite()) {
$obj = $record->get($fk->getAlias());
if ($obj instanceof Doctrine_Record &&
@ -1113,12 +1080,12 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
public function getTable()
{
return $this->_table;
return $this->_classMetadata;
}
public function getFieldName($columnName)
{
return $this->_table->getFieldName($columnName);
return $this->_classMetadata->getFieldName($columnName);
}
public function getFieldNames()
@ -1126,13 +1093,13 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable
if ($this->_fieldNames) {
return $this->_fieldNames;
}
$this->_fieldNames = $this->_table->getFieldNames();
$this->_fieldNames = $this->_classMetadata->getFieldNames();
return $this->_fieldNames;
}
public function getOwningTable($fieldName)
{
return $this->_table;
return $this->_classMetadata;
}
public function getIdentityMap()

View file

@ -13,19 +13,19 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
*/
protected function _doInsert(Doctrine_Record $record)
{
$table = $this->_table;
$table = $this->_classMetadata;
$dataSet = $this->_formatDataSet($record);
$component = $table->getComponentName();
$component = $table->getClassName();
$classes = $table->getOption('joinedParents');
$classes = $table->getOption('parents');
array_unshift($classes, $component);
try {
$this->_conn->beginInternalTransaction();
$identifier = null;
foreach (array_reverse($classes) as $k => $parent) {
$parentTable = $this->_conn->getTable($parent);
$parentTable = $this->_conn->getMetadata($parent);
if ($k == 0) {
$identifierType = $parentTable->getIdentifierType();
if ($identifierType == Doctrine::IDENTIFIER_AUTOINC) {
@ -67,11 +67,11 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
*/
protected function _doUpdate(Doctrine_Record $record)
{
$table = $this->_table;
$table = $this->_classMetadata;
$identifier = $record->identifier();
$dataSet = $this->_formatDataSet($record);
$component = $table->getComponentName();
$classes = $table->getOption('joinedParents');
$component = $table->getClassName();
$classes = $table->getOption('parents');
array_unshift($classes, $component);
foreach ($record as $field => $value) {
@ -84,7 +84,7 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
}
foreach (array_reverse($classes) as $class) {
$parentTable = $this->_conn->getTable($class);
$parentTable = $this->_conn->getMetadata($class);
$this->_conn->update($parentTable, $dataSet[$class], $identifier);
}
@ -97,7 +97,7 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
protected function _doDelete(Doctrine_Record $record, Doctrine_Connection $conn)
{
try {
$table = $this->_table;
$table = $this->_classMetadata;
$conn->beginInternalTransaction();
$this->deleteComposites($record);
@ -128,10 +128,10 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
public function getCustomJoins()
{
$customJoins = array();
foreach ($this->_table->getOption('joinedParents') as $parentClass) {
foreach ($this->_classMetadata->getOption('parents') as $parentClass) {
$customJoins[$parentClass] = 'INNER';
}
foreach ((array)$this->_table->getOption('subclasses') as $subClass) {
foreach ((array)$this->_classMetadata->getOption('subclasses') as $subClass) {
if ($subClass != $this->_domainClassName) {
$customJoins[$subClass] = 'LEFT';
}
@ -141,10 +141,11 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
public function getCustomFields()
{
$fields = array();
if ($this->_table->getOption('subclasses')) {
foreach ($this->_table->getOption('subclasses') as $subClass) {
$fields = array_merge($this->_conn->getTable($subClass)->getFieldNames(), $fields);
$fields = array($this->_classMetadata->getInheritanceOption('discriminatorColumn'));
//$fields = array();
if ($this->_classMetadata->getOption('subclasses')) {
foreach ($this->_classMetadata->getOption('subclasses') as $subClass) {
$fields = array_merge($this->_conn->getMetadata($subClass)->getFieldNames(), $fields);
}
}
return array_unique($fields);
@ -155,9 +156,9 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
*/
public function getDiscriminatorColumn()
{
$joinedParents = $this->_table->getOption('joinedParents');
$joinedParents = $this->_classMetadata->getOption('joinedParents');
if (count($joinedParents) <= 0) {
$inheritanceMap = $this->_table->getOption('inheritanceMap');
$inheritanceMap = $this->_classMetadata->getOption('inheritanceMap');
} else {
$inheritanceMap = $this->_conn->getTable(array_pop($joinedParents))->getOption('inheritanceMap');
}
@ -173,11 +174,7 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
return $this->_fieldNames;
}
$fieldNames = $this->_table->getFieldNames();
foreach ($this->_table->getOption('joinedParents') as $parent) {
$parentTable = $this->_conn->getTable($parent);
$fieldNames = array_merge($parentTable->getFieldNames(), $fieldNames);
}
$fieldNames = $this->_classMetadata->getFieldNames();
$this->_fieldNames = array_unique($fieldNames);
return $fieldNames;
@ -189,46 +186,46 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
return $this->_columnNameFieldNameMap[$columnName];
}
if ($this->_table->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $this->_table->getFieldName($columnName);
if ($this->_classMetadata->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $this->_classMetadata->getFieldName($columnName);
return $this->_columnNameFieldNameMap[$columnName];
}
foreach ($this->_table->getOption('joinedParents') as $parentClass) {
$parentTable = $this->_conn->getTable($parentClass);
foreach ($this->_classMetadata->getOption('parents') as $parentClass) {
$parentTable = $this->_conn->getMetadata($parentClass);
if ($parentTable->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $parentTable->getFieldName($columnName);
return $this->_columnNameFieldNameMap[$columnName];
}
}
foreach ((array)$this->_table->getOption('subclasses') as $subClass) {
$subTable = $this->_conn->getTable($subClass);
foreach ((array)$this->_classMetadata->getOption('subclasses') as $subClass) {
$subTable = $this->_conn->getMetadata($subClass);
if ($subTable->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $subTable->getFieldName($columnName);
return $this->_columnNameFieldNameMap[$columnName];
}
}
throw new Doctrine_Mapper_Exception("No field name found for column name '$columnName'.");
}
public function getOwningTable($fieldName)
{
if ($this->_table->hasField($fieldName)) {
return $this->_table;
{
if ($this->_classMetadata->hasField($fieldName) && ! $this->_classMetadata->isInheritedField($fieldName)) {
return $this->_classMetadata;
}
foreach ($this->_table->getOption('joinedParents') as $parentClass) {
$parentTable = $this->_conn->getTable($parentClass);
if ($parentTable->hasField($fieldName)) {
foreach ($this->_classMetadata->getOption('parents') as $parentClass) {
$parentTable = $this->_conn->getMetadata($parentClass);
if ($parentTable->hasField($fieldName) && ! $parentTable->isInheritedField($fieldName)) {
return $parentTable;
}
}
foreach ((array)$this->_table->getOption('subclasses') as $subClass) {
$subTable = $this->_conn->getTable($subClass);
if ($subTable->hasField($fieldName)) {
foreach ((array)$this->_classMetadata->getOption('subclasses') as $subClass) {
$subTable = $this->_conn->getMetadata($subClass);
if ($subTable->hasField($fieldName) && ! $subTable->isInheritedField($fieldName)) {
return $subTable;
}
}
@ -241,17 +238,18 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract
*/
protected function _formatDataSet(Doctrine_Record $record)
{
$table = $this->_table;
$table = $this->_classMetadata;
$dataSet = array();
$component = $table->getComponentName();
$component = $table->getClassName();
$array = $record->getPrepared();
$classes = array_merge(array($component), $this->_table->getOption('joinedParents'));
$classes = array_merge(array($component), $this->_classMetadata->getParentClasses());
foreach ($classes as $class) {
$table = $this->_conn->getTable($class);
foreach ($table->getColumns() as $columnName => $definition) {
if (isset($definition['primary'])) {
$metadata = $this->_conn->getMetadata($class);
foreach ($metadata->getColumns() as $columnName => $definition) {
if ((isset($definition['primary']) && $definition['primary'] === true) ||
(isset($definition['inherited']) && $definition['inherited'] === true)) {
continue;
}
$fieldName = $table->getFieldName($columnName);

View file

@ -5,7 +5,7 @@ class Doctrine_Mapper_SingleTable extends Doctrine_Mapper_Abstract
public function getDiscriminatorColumn()
{
$inheritanceMap = $this->_table->getOption('inheritanceMap');
$inheritanceMap = $this->_classMetadata->getOption('inheritanceMap');
return isset($inheritanceMap[$this->_domainClassName]) ? $inheritanceMap[$this->_domainClassName] : array();
}

View file

@ -302,8 +302,10 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
{
$path = array();
$ancestors = $this->getAncestors();
foreach ($ancestors as $ancestor) {
$path[] = $ancestor->__toString();
if ($ancestors) {
foreach ($ancestors as $ancestor) {
$path[] = $ancestor->__toString();
}
}
if ($includeRecord) {
$path[] = $this->getRecord()->__toString();

View file

@ -1620,7 +1620,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$this->_conn = $manager->getConnectionForComponent($name);
}
$table = $this->_conn->getTable($name);
$table = $this->_conn->getMetadata($name);
$tableName = $table->getTableName();
// get the short alias for this table

View file

@ -528,12 +528,12 @@ abstract class Doctrine_Query_Abstract
*/
protected function _createCustomJoinSql($componentName, $componentAlias)
{
$table = $this->_conn->getTable($componentName);
$table = $this->_conn->getMetadata($componentName);
$tableAlias = $this->getSqlTableAlias($componentAlias, $table->getTableName());
$customJoins = $this->_conn->getMapper($componentName)->getCustomJoins();
$sql = '';
foreach ($customJoins as $componentName => $joinType) {
$joinedTable = $this->_conn->getTable($componentName);
$joinedTable = $this->_conn->getMetadata($componentName);
$joinedAlias = $componentAlias . '.' . $componentName;
$joinedTableAlias = $this->getSqlTableAlias($joinedAlias, $joinedTable->getTableName());
$sql .= " $joinType JOIN " . $this->_conn->quoteIdentifier($joinedTable->getTableName())
@ -553,6 +553,7 @@ abstract class Doctrine_Query_Abstract
/**
* Creates the SQL snippet for the WHERE part that contains the discriminator
* column conditions.
* Used solely for Single Table Inheritance.
*
* @return string The created SQL snippet.
*/
@ -564,7 +565,25 @@ abstract class Doctrine_Query_Abstract
if ( ! $data['mapper'] instanceof Doctrine_Mapper_SingleTable) {
$array[$sqlTableAlias][] = array();
} else {
$array[$sqlTableAlias][] = $data['mapper']->getDiscriminatorColumn();
$discCol = $data['table']->getInheritanceOption('discriminatorColumn');
$discMap = $data['table']->getInheritanceOption('discriminatorMap');
$discValue = array_search($data['table']->getClassName(), $discMap);
if ($discValue === false) {
continue;
}
$discriminator = array();
$discriminator[] = array($discCol => $discValue);
$subclasses = $data['table']->getSubclasses();
foreach ((array)$subclasses as $subclass) {
$subClassMetadata = $this->_conn->getClassMetadata($subclass);
$discCol = $subClassMetadata->getInheritanceOption('discriminatorColumn');
$discMap = $subClassMetadata->getInheritanceOption('discriminatorMap');
$discValue = array_search($subclass, $discMap);
$discriminator[] = array($discCol => $discValue);
}
$array[$sqlTableAlias][] = $discriminator;
}
}
//var_dump($array);
@ -584,10 +603,11 @@ abstract class Doctrine_Query_Abstract
}
foreach ($maps as $map) {
//echo "start";
$b = array();
foreach ($map as $field => $value) {
$identifier = $this->_conn->quoteIdentifier($tableAlias . $field);
foreach ($map as $discriminator) {
list($column, $value) = each($discriminator);
$identifier = $this->_conn->quoteIdentifier($tableAlias . $column);
if ($index > 0) {
$b[] = '(' . $identifier . ' = ' . $this->_conn->quote($value)
. ' OR ' . $identifier . ' IS NULL)';
@ -597,10 +617,14 @@ abstract class Doctrine_Query_Abstract
}
if ( ! empty($b)) {
$a[] = implode(' AND ', $b);
if (count($b) > 1) {
$a[] = '(' . implode(' OR ', $b) . ')';
} else {
$a[] = implode(' OR ', $b);
}
}
}
//echo "end<br />";
if ( ! empty($a)) {
$c[] = implode(' AND ', $a);
}

View file

@ -53,7 +53,7 @@ class Doctrine_Query_Check
if ( ! ($table instanceof Doctrine_Table)) {
$table = Doctrine_Manager::getInstance()
->getCurrentConnection()
->getTable($table);
->getClassMetadata($table);
}
$this->table = $table;
$this->_tokenizer = new Doctrine_Query_Tokenizer();

View file

@ -86,7 +86,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
}
}
public function parseValue($value, Doctrine_Table $table = null, $field = null)
public function parseValue($value, $table = null, $field = null)
{
$conn = $this->query->getConnection();

View file

@ -81,6 +81,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
} else {
$this->_sqlParts[$queryPartName][] = $queryPart;
}
return $this;
}
@ -316,7 +317,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
$conn = Doctrine_Manager::getInstance()
->getConnectionForComponent($component);
$table = $conn->getTable($component);
$table = $conn->getClassMetadata($component);
$this->_queryComponents[$componentAlias] = array(
'table' => $table, 'mapper' => $conn->getMapper($component));
} else {
@ -324,7 +325,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
$this->_queryComponents[$componentAlias] = array(
'table' => $relation->getTable(),
'mapper' => $this->_conn->getMapper($component),
'mapper' => $this->_conn->getMapper($component),
'parent' => $parent,
'relation' => $relation);
}

View file

@ -26,6 +26,7 @@ Doctrine::autoload('Doctrine_Record_Abstract');
* @package Doctrine
* @subpackage Record
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
@ -41,33 +42,33 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* DIRTY STATE
* a Doctrine_Record is in dirty state when its properties are changed
*/
const STATE_DIRTY = 1;
const STATE_DIRTY = 1;
/**
* TDIRTY STATE
* a Doctrine_Record is in transient dirty state when it is created
* and some of its fields are modified but it is NOT yet persisted into database
*/
const STATE_TDIRTY = 2;
const STATE_TDIRTY = 2;
/**
* CLEAN STATE
* a Doctrine_Record is in clean state when all of its properties are loaded from the database
* and none of its properties are changed
*/
const STATE_CLEAN = 3;
const STATE_CLEAN = 3;
/**
* PROXY STATE
* a Doctrine_Record is in proxy state when its properties are not fully loaded
*/
const STATE_PROXY = 4;
const STATE_PROXY = 4;
/**
* NEW TCLEAN
* a Doctrine_Record is in transient clean state when it is created and none of its fields are modified
*/
const STATE_TCLEAN = 5;
const STATE_TCLEAN = 5;
/**
* LOCKED STATE
@ -76,7 +77,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* This state is used internally to ensure that circular deletes
* and saves will not cause infinite loops
*/
const STATE_LOCKED = 6;
const STATE_LOCKED = 6;
/**
*
@ -85,58 +86,78 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
/**
* @var Doctrine_Node_<TreeImpl> node object
* @todo Specific to the NestedSet Behavior plugin. Move outta here.
*/
protected $_node;
/**
* @var integer $_id the primary keys of this object
* The values that make up the ID/primary key of the object.
*
* @var array
*/
protected $_id = array();
protected $_id = array();
/**
* @var array $_data the record data
* The record data.
*
* @var array
*/
protected $_data = array();
protected $_data = array();
/**
* @var array $_values the values array, aggregate values and such are mapped into this array
* The values array, aggregate values and such are mapped into this array.
*
* @var array
*/
protected $_values = array();
protected $_values = array();
/**
* @var integer $_state the state of this record
* The state of the object.
*
* @var integer
* @see STATE_* constants
*/
protected $_state;
/**
* @var array $_modified an array containing field names that have been modified
* The names of fields that have been modified but not yet persisted.
*
* @var array
* @todo Better name? $_modifiedFields?
*/
protected $_modified = array();
protected $_modified = array();
/**
* @var Doctrine_Validator_ErrorStack error stack object
* The error stack used to collect errors during validation.
*
* @var Doctrine_Validator_ErrorStack
*/
protected $_errorStack;
/**
* @var array $_references an array containing all the references
* The names of all relations.
*
* @var array $_references
*/
protected $_references = array();
protected $_references = array();
/**
* @var integer $index this index is used for creating object identifiers
* Index used for creating object identifiers (oid's).
*
* @var integer $index
*/
private static $_index = 1;
/**
* @var integer $oid object identifier, each Record object has a unique object identifier
* The object identifier of the object. Each object has a unique identifier during runtime.
*
* @var integer $oid
*/
private $_oid;
/**
* constructor
* Constructor.
*
* @param Doctrine_Table|null $table a Doctrine_Table object or null,
* if null the table object is retrieved from current connection
*
@ -148,21 +169,12 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function __construct($mapper = null, $isNewEntry = false, array $data = array())
{
//echo get_class($this) . "<br />";
if (isset($mapper) && $mapper instanceof Doctrine_Table) {
//echo "one<br />";
$this->_table = $mapper;
//$this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this));
$exists = ! $isNewEntry;
return;
} else if (isset($mapper) && $mapper instanceof Doctrine_Mapper_Abstract) {
//echo "two<br />";
if (isset($mapper) && $mapper instanceof Doctrine_Mapper_Abstract) {
$class = get_class($this);
$this->_mapper = Doctrine_Manager::getInstance()->getMapper($class);
$this->_table = $this->_mapper->getTable();
$exists = ! $isNewEntry;
} else {
//echo "three<br />";
$this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this));
$this->_table = $this->_mapper->getTable();
$exists = false;
@ -302,56 +314,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($event)
public function preSerialize(Doctrine_Event $event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function postSerialize($event)
public function postSerialize(Doctrine_Event $event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function preUnserialize($event)
public function preUnserialize(Doctrine_Event $event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function postUnserialize($event)
public function postUnserialize(Doctrine_Event $event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function preSave($event)
public function preSave(Doctrine_Event $event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function postSave($event)
public function postSave(Doctrine_Event $event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function preDelete($event)
public function preDelete(Doctrine_Event $event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function postDelete($event)
public function postDelete(Doctrine_Event $event)
{ }
/**
@ -359,7 +371,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($event)
public function preUpdate(Doctrine_Event $event)
{ }
/**
@ -367,7 +379,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($event)
public function postUpdate(Doctrine_Event $event)
{ }
/**
@ -375,7 +387,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($event)
public function preInsert(Doctrine_Event $event)
{ }
/**
@ -383,7 +395,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($event)
public function postInsert(Doctrine_Event $event)
{ }
/**
@ -855,9 +867,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_references[$fieldName] = $rel->fetchRelatedFor($this);
}
return $this->_references[$fieldName];
} catch (Doctrine_Table_Exception $e) {
//echo $e->getTraceAsString();
//echo "<br /><br />";
} catch (Doctrine_Relation_Exception $e) {
//echo $this->_domainClassName . "<br />";
//var_dump($this->_values);
echo $e->getTraceAsString();
echo "<br /><br />";
foreach ($this->_table->getFilters() as $filter) {
if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) {
return $value;
@ -932,8 +946,17 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
} else {
try {
/*echo $this->_domainClassName;
var_dump($this->_data);
echo "<br /><br />";
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br />";
}
echo "<br /><br />";*/
$this->_coreSetRelated($fieldName, $value);
} catch (Doctrine_Table_Exception $e) {
} catch (Doctrine_Relation_Exception $e) {
foreach ($this->_table->getFilters() as $filter) {
if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) {
return $value;
@ -1187,16 +1210,21 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$a[$field] = $this->_data[$field];
}
}
//$map = $this->_table->getOption('inheritanceMap');
$map = $this->_mapper->getDiscriminatorColumn();
foreach ($map as $k => $v) {
$old = $this->get($k, false);
// @todo cleanup
if ($this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED ||
$this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
$discCol = $this->_table->getInheritanceOption('discriminatorColumn');
$discMap = $this->_table->getInheritanceOption('discriminatorMap');
$old = $this->get($discCol, false);
$v = array_search($this->_domainClassName, $discMap);
if ((string) $old !== (string) $v || $old === null) {
$a[$k] = $v;
$this->_data[$k] = $v;
$a[$discCol] = $v;
$this->_data[$discCol] = $v;
}
}
return $a;
}

View file

@ -42,16 +42,21 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
* @var Doctrine_Mapper_Abstract
*/
protected $_mapper;
public function setTableDefinition()
{
}
/**
* @deprecated
*/
public function setTableDefinition()
{}
/**
* @deprecated
*/
public function setUp()
{
}
{}
public static function initMapping(Doctrine_MetadataClass $class)
{}
/**
@ -65,6 +70,9 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
return $this->_table;
}
/**
* Returns the mapper of the entity.
*/
public function getMapper()
{
return $this->_mapper;
@ -105,51 +113,12 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
return $this;
}
/**
* index
* defines or retrieves an index
* if the second parameter is set this method defines an index
* if not this method retrieves index named $name
*
* @param string $name the name of the index
* @param array $definition the definition array
* @return mixed
*/
public function index($name, array $definition = array())
{
if ( ! $definition) {
return $this->_table->getIndex($name);
} else {
return $this->_table->addIndex($name, $definition);
}
}
public function setAttribute($attr, $value)
{
$this->_table->setAttribute($attr, $value);
}
public function setTableName($tableName)
{
$this->_table->setTableName($tableName);
}
/**
*
* @deprecated Use setSubclasses()
*/
public function setInheritanceMap($map)
{
$this->_table->setOption('inheritanceMap', $map);
}
public function setSubclasses($map)
{
//echo "setting inheritance map on " . get_class($this) . "<br />";
$this->_table->setOption('inheritanceMap', $map);
$this->_table->setOption('subclasses', array_keys($map));
$this->_table->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE);
}
/**
* attribute
* sets or retrieves an option
@ -174,6 +143,50 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
}
}
/* THE FOLLOWING STUFF WILL ALL BE REMOVED SOON */
public function setTableName($tableName)
{
$this->_table->setTableName($tableName);
}
/**
* index
* defines or retrieves an index
* if the second parameter is set this method defines an index
* if not this method retrieves index named $name
*
* @param string $name the name of the index
* @param array $definition the definition array
* @return mixed
*/
public function index($name, array $definition = array())
{
if ( ! $definition) {
return $this->_table->getIndex($name);
} else {
return $this->_table->addIndex($name, $definition);
}
}
/**
*
* @deprecated Use setSubclasses()
*/
public function setInheritanceMap($map)
{
$this->_table->setOption('inheritanceMap', $map);
}
public function setSubclasses($map)
{
//echo "setting inheritance map on " . get_class($this) . "<br />";
$this->_table->setOption('inheritanceMap', $map);
$this->_table->setOption('subclasses', array_keys($map));
$this->_table->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE);
}
/**
* option
* sets or retrieves an option
@ -282,7 +295,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
{
$this->_table->setColumn($name, $type, $length, $options);
}
/**
* hasColumns
*
@ -389,11 +402,6 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
}
$this->_table->setInheritanceType($type);
}
protected function _getMapper($className)
{
}
/**
* check

View file

@ -35,7 +35,7 @@ abstract class Doctrine_Record_Filter
{
protected $_table;
public function setTable(Doctrine_Table $table)
public function setTable(Doctrine_ClassMetadata $table)
{
$this->_table = $table;
}

View file

@ -111,7 +111,7 @@ abstract class Doctrine_Record_Generator extends Doctrine_Record_Abstract
return $this->_options;
}
public function initialize(Doctrine_Table $table)
public function initialize($table)
{
if ($this->_initialized) {
return false;
@ -188,7 +188,7 @@ abstract class Doctrine_Record_Generator extends Doctrine_Record_Abstract
* @param Doctrine_Table $table the table object that owns the plugin
* @return array an array of foreign key definitions
*/
public function buildForeignKeys(Doctrine_Table $table)
public function buildForeignKeys($table)
{
$fk = array();

View file

@ -143,6 +143,11 @@ abstract class Doctrine_Relation implements ArrayAccess
$def = array();
foreach ($this->definition as $key => $val) {
if ( ! isset($definition[$key]) && $val) {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br />";
}
throw new Doctrine_Exception($key . ' is required!');
}
if (isset($definition[$key])) {
@ -257,7 +262,7 @@ abstract class Doctrine_Relation implements ArrayAccess
{
return Doctrine_Manager::getInstance()
->getConnectionForComponent($this->definition['class'])
->getTable($this->definition['class']);
->getMetadata($this->definition['class']);
}
/**

View file

@ -61,19 +61,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
public function getRelationDql($count, $context = 'record')
{
//$table = $this->definition['refTable'];
$assocRelationName = isset($this->definition['refReverseRelationName']) ?
$this->definition['refReverseRelationName'] : $this->definition['refClass'];
/*if ($this->definition['localTable'] === $this->definition['table']) {
echo $this->definition['class'];
$rel = $this->definition['table']->getRelation('User');
$relationName = $rel->getRelationName();
}*/
//var_dump($this->definition['foreign']) . "<br />";
//echo $component;
//$rel = $this->definition['refTable']->getRelation($this->_foreignMapper->getComponentName());
//echo "LOCAL:" . $rel->getLocal() . "<br />";
$assocRelationName = $this->definition['refClass'];
$relatedClassName = $this->_foreignMapper->getComponentName();

View file

@ -53,7 +53,7 @@ class Doctrine_Relation_Parser
*
* @param Doctrine_Table $table the table object this parser belongs to
*/
public function __construct(Doctrine_Table $table)
public function __construct(/*Doctrine_Table*/ $table)
{
$this->_table = $table;
}
@ -100,8 +100,8 @@ class Doctrine_Relation_Parser
*/
public function bind($name, $options = array())
{
if (isset($this->relations[$name])) {
unset($this->relations[$name]);
if (isset($this->_relations[$name])) {
unset($this->_relations[$name]);
}
$e = explode(' as ', $name);
@ -111,7 +111,7 @@ class Doctrine_Relation_Parser
if ( ! isset($options['type'])) {
throw new Doctrine_Relation_Exception('Relation type not set.');
}
$this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias));
return $this->_pending[$alias];
@ -125,9 +125,6 @@ class Doctrine_Relation_Parser
public function getRelation($alias, $recursive = true)
{
if (isset($this->_relations[$alias])) {
/*if ($alias == 'Groupuser') {
//var_dump($this->_relations[$alias]['foreign']);
}*/
return $this->_relations[$alias];
}
@ -139,16 +136,24 @@ class Doctrine_Relation_Parser
$this->getRelations();
return $this->getRelation($alias, false);
} else {
/*try {
throw new Doctrine_Table_Exception('Unknown relation alias ' . $alias);
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString();
echo "<br /><br />";
}*/
throw new Doctrine_Table_Exception('Unknown relation alias ' . $alias);
//echo "" . "<br />";
///echo $e->getTraceAsString() . "<br /><br /><br />";
}
throw new Doctrine_Relation_Exception("Unknown relation '$alias'.");
}
}
public function addRelation($name, Doctrine_Relation $relation)
{
if (isset($this->_relations[$name])) {
throw new Doctrine_Relation_Exception("Relation '$name' does already exist.");
}
$this->_relations[$name] = $relation;
}
/**
* Loads a relation and puts it into the collection of loaded relations.
* In the process of initializing a relation it is common that multiple other, closely related
@ -164,11 +169,11 @@ class Doctrine_Relation_Parser
// if it does we are dealing with an association relation (many-many)
if (isset($def['refClass'])) {
$def = $this->completeAssocDefinition($def);
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName()));
$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 &&
/*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 "
@ -176,9 +181,9 @@ class Doctrine_Relation_Parser
. "a 'refRelationName' and a 'refReverseRelationName' to distinguish relations.");
}
$relationName = $def['refRelationName'];
} else {
} else {*/
$relationName = $def['refClass'];
}
//}
if ( ! isset($this->_pending[$relationName]) && ! isset($this->_relations[$relationName])) {
$this->_completeManyToManyRelation($def);
@ -220,14 +225,14 @@ class Doctrine_Relation_Parser
// if the two many-many related components shared the same table, we need a relation name
// to distinguish the relations.
$relationName = $def['refClass'];
if (isset($def['refRelationName'])) {
/*if (isset($def['refRelationName'])) {
$relationName .= ' as ' . $def['refRelationName'];
}
}*/
// add a relation pointing from the intermediary table to the table of this parser
$parser = $def['refTable']->getRelationParser();
if ( ! $parser->hasRelation($this->_table->getComponentName())) {
$parser->bind($this->_table->getComponentName(),
if ( ! $parser->hasRelation($this->_table->getClassName())) {
$parser->bind($this->_table->getClassName(),
array('type' => Doctrine_Relation::ONE,
'local' => $def['local'],
'foreign' => $idColumnName,
@ -280,7 +285,7 @@ class Doctrine_Relation_Parser
$def[$key] = $impl;
}
return $conn->getTable($def[$key]);
return $conn->getMetadata($def[$key]);
}
protected function _isTemplate($className)
@ -345,7 +350,7 @@ class Doctrine_Relation_Parser
*
* @param Doctrine_Table $table table object to retrieve identifiers from
*/
public function getIdentifiers(Doctrine_Table $table)
public function getIdentifiers($table)
{
$componentNameToLower = strtolower($table->getComponentName());
if (is_array($table->getIdentifier())) {
@ -368,13 +373,13 @@ class Doctrine_Relation_Parser
* @param Doctrine_Table $foreignTable foreign table object
* @return array an array of column names
*/
public function guessColumns(array $classes, Doctrine_Table $foreignTable)
public function guessColumns(array $classes, $foreignTable)
{
$conn = $this->_table->getConnection();
foreach ($classes as $class) {
try {
$table = $conn->getTable($class);
$table = $conn->getClassMetadata($class);
} catch (Doctrine_Table_Exception $e) {
continue;
}
@ -415,9 +420,18 @@ class Doctrine_Relation_Parser
$def['localTable'] = $this->_table;
$foreignClasses = array_merge($def['table']->getOption('parents'), array($def['class']));
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName()));
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getClassName()));
$localIdentifierColumnNames = $this->_table->getIdentifierColumnNames();
if ((count($localIdentifierColumnNames) - 1) < 0) {
echo $this->_table->getClassName();
var_dump($this->_table->getIdentifier());
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br />";
}
}
$localIdColumnName = $localIdentifierColumnNames[count($localIdentifierColumnNames) - 1];
$foreignIdentifierColumnNames = $def['table']->getIdentifierColumnNames();
$foreignIdColumnName = $foreignIdentifierColumnNames[count($foreignIdentifierColumnNames) - 1];
@ -462,14 +476,14 @@ class Doctrine_Relation_Parser
// the following loops are needed for covering inheritance
foreach ($localClasses as $class) {
$table = $conn->getTable($class);
$table = $conn->getClassMetadata($class);
$identifierColumnNames = $table->getIdentifierColumnNames();
$idColumnName = array_pop($identifierColumnNames);
$column = strtolower($table->getComponentName())
. '_' . $idColumnName;
foreach ($foreignClasses as $class2) {
$table2 = $conn->getTable($class2);
$table2 = $conn->getClassMetadata($class2);
if ($table2->hasColumn($column)) {
$def['foreign'] = $column;
$def['local'] = $idColumnName;
@ -479,14 +493,14 @@ class Doctrine_Relation_Parser
}
foreach ($foreignClasses as $class) {
$table = $conn->getTable($class);
$table = $conn->getClassMetadata($class);
$identifierColumnNames = $table->getIdentifierColumnNames();
$idColumnName = array_pop($identifierColumnNames);
$column = strtolower($table->getComponentName())
. '_' . $idColumnName;
foreach ($localClasses as $class2) {
$table2 = $conn->getTable($class2);
$table2 = $conn->getClassMetadata($class2);
if ($table2->hasColumn($column)) {
$def['foreign'] = $idColumnName;
$def['local'] = $column;

View file

@ -27,7 +27,7 @@ class Doctrine_Table_Factory
* @param array $tables The metadata collection to which the loaded metadata is added.
*/
public function loadTables($name, array &$tables)
{
{
$parentClass = $name;
$parentClasses = array();
$parentClassWithTable = false;
@ -104,13 +104,6 @@ class Doctrine_Table_Factory
}
}
protected function _createTable($domainClassName)
{
return $this->_loadMetaDataFromCode($table, $domainClassName);
}
/**
* Initializes the in-memory metadata for the domain class this mapper belongs to.
* Uses reflection and code setup.
@ -187,11 +180,12 @@ class Doctrine_Table_Factory
$joinedParents[] = $parentColumns[$columnName]['owner'];*/
$joinedParents[] = $parentTable->getComponentName();
}
} else {
}/* else {
//echo "adding primary key $columnName on ".$table->getComponentName().".<br />";
unset($definition['autoincrement']);
$fullName = $columnName . ' as ' . $parentTable->getFieldName($columnName);
$table->setColumn($fullName, $definition['type'], $definition['length'], $definition, true);
}
}*/
}
}
$table->setOption('joinedParents', array_values(array_unique($joinedParents)));
@ -289,7 +283,7 @@ class Doctrine_Table_Factory
unset($definition['sequence']);
// add the inherited primary key column
$fullName = $id . ' as ' . $rootTable->getFieldName($id);
$fullName = $rootTable->getColumnName($id) . ' as ' . $id;
$table->setColumn($fullName, $definition['type'], $definition['length'],
$definition, true);
}

View file

@ -45,7 +45,7 @@ class Doctrine_Template extends Doctrine_Record_Abstract
*
* @param Doctrine_Table $_table the table object this Template belongs to
*/
public function setTable(Doctrine_Table $table)
public function setTable($table)
{
$this->_table = $table;
}

View file

@ -49,7 +49,7 @@ class Doctrine_Tree
* @param object $table instance of Doctrine_Table
* @param array $options options
*/
public function __construct(Doctrine_Table $table, $options)
public function __construct($table, $options)
{
$this->table = $table;
$this->options = $options;
@ -92,7 +92,7 @@ class Doctrine_Tree
* @return object $options instance of Doctrine_Node
* @throws Doctrine_Exception if class does not extend Doctrine_Tree
*/
public static function factory(Doctrine_Table $table, $implName, $options = array())
public static function factory($table, $implName, $options = array())
{
$class = 'Doctrine_Tree_' . $implName;
if ( ! class_exists($class)) {

View file

@ -41,7 +41,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
* @param object $table instance of Doctrine_Table
* @param array $options options
*/
public function __construct(Doctrine_Table $table, $options)
public function __construct($table, $options)
{
// set default many root attributes
$options['hasManyRoots'] = isset($options['hasManyRoots']) ? $options['hasManyRoots'] : false;

View file

@ -21,7 +21,7 @@
/**
* Doctrine_Validator
* Doctrine_Validator performs validations in record properties
* Doctrine_Validator performs validations on record properties
*
* @package Doctrine
* @subpackage Validator
@ -105,14 +105,15 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
foreach ($column as $name => $args) {
if (empty($name)
|| $name == 'primary'
|| $name == 'protected'
|| $name == 'autoincrement'
|| $name == 'default'
|| $name == 'values'
|| $name == 'sequence'
|| $name == 'zerofill'
|| $name == 'scale') {
|| $name == 'primary'
|| $name == 'protected'
|| $name == 'autoincrement'
|| $name == 'default'
|| $name == 'values'
|| $name == 'sequence'
|| $name == 'zerofill'
|| $name == 'scale'
|| $name == 'inherited') {
continue;
}

View file

@ -1,10 +1,10 @@
<?php
class Account extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('entity_id', 'integer');
$this->hasColumn('amount', 'integer');
$class->setColumn('entity_id', 'integer');
$class->setColumn('amount', 'integer');
}
}

View file

@ -1,13 +1,11 @@
<?php
class Address extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->hasMany('User', array('local' => 'address_id',
$class->setColumn('address', 'string', 200);
$class->hasMany('User', array('local' => 'address_id',
'foreign' => 'user_id',
'refClass' => 'EntityAddress'));
}
public function setTableDefinition() {
$this->hasColumn('address', 'string', 200);
}
}

View file

@ -1,17 +1,14 @@
<?php
class Album extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->hasMany('Song', array('local' => 'id', 'foreign' => 'album_id'));
$this->hasOne('User', array('local' => 'user_id',
$class->setColumn('user_id', 'integer');
$class->setColumn('name', 'string',20);
$class->hasMany('Song', array('local' => 'id', 'foreign' => 'album_id'));
$class->hasOne('User', array('local' => 'user_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
public function setTableDefinition()
{
$this->hasColumn('user_id', 'integer');
$this->hasColumn('name', 'string',20);
}
}

View file

@ -1,13 +1,11 @@
<?php
class App extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 32);
$this->hasColumn('user_id', 'integer', 11);
$this->hasColumn('app_category_id', 'integer', 11);
}
public function setUp() {
$this->hasOne('User', 'User.id');
$this->hasMany('App_Category as Category', 'App_Category.id');
}
public static function initMetadata($class) {
$class->setColumn('name', 'string', 32);
$class->setColumn('user_id', 'integer', 11);
$class->setColumn('app_category_id', 'integer', 11);
$class->hasOne('User', array('local' => 'user_id', 'foreign' => 'id'));
$class->hasOne('App_Category as Category', array('local' => 'app_category_id', 'foreign' => 'id'));
}
}

View file

@ -1,11 +1,9 @@
<?php
class App_Category extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 32);
$this->hasColumn('parent_id', 'integer');
}
public function setUp() {
$this->hasMany('App', 'App.app_category_id');
$this->hasMany('App_Category as Parent', 'App_Category.parent_id');
public static function initMetadata($class) {
$class->setColumn('name', 'string', 32);
$class->setColumn('parent_id', 'integer');
$class->hasMany('App', array('local' => 'id', 'foreign' => 'app_category_id'));
$class->hasOne('App_Category as Parent', array('local' => 'parent_id', 'foreign' => 'id'));
}
}

View file

@ -1,15 +1,13 @@
<?php
class App_User extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('first_name', 'string', 32);
$this->hasColumn('last_name', 'string', 32);
$this->hasColumn('email', 'string', 128, 'email');
$this->hasColumn('username', 'string', 16, 'unique, nospace');
$this->hasColumn('password', 'string', 128, 'notblank');
$this->hasColumn('country', 'string', 2, 'country');
$this->hasColumn('zipcode', 'string', 9, 'nospace');
public static function initMetadata($class) {
$class->setColumn('first_name', 'string', 32);
$class->setColumn('last_name', 'string', 32);
$class->setColumn('email', 'string', 128, 'email');
$class->setColumn('username', 'string', 16, 'unique, nospace');
$class->setColumn('password', 'string', 128, 'notblank');
$class->setColumn('country', 'string', 2, 'country');
$class->setColumn('zipcode', 'string', 9, 'nospace');
$class->hasMany('App', array('local' => 'id', 'foreign' => 'user_id'));
}
public function setUp() {
$this->hasMany('App', 'App.user_id');
}
}

View file

@ -1,8 +1,8 @@
<?php
class Assignment extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('task_id', 'integer');
$this->hasColumn('resource_id', 'integer');
public static function initMetadata($class) {
$class->setColumn('task_id', 'integer');
$class->setColumn('resource_id', 'integer');
}
}

View file

@ -1,14 +1,11 @@
<?php
class Auth extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('roleid', 'integer', 10);
$this->hasColumn('name', 'string', 50);
}
public function setUp()
{
$this->hasOne('Role', array('local' => 'roleid', 'foreign' => 'id'));
$class->setColumn('roleid', 'integer', 10);
$class->setColumn('name', 'string', 50);
$class->hasOne('Role', array('local' => 'roleid', 'foreign' => 'id'));
}
}

View file

@ -1,15 +1,12 @@
<?php
class Author extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->hasOne('Book', array('local' => 'book_id',
$class->setColumn('book_id', 'integer');
$class->setColumn('name', 'string',20);
$class->hasOne('Book', array('local' => 'book_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
public function setTableDefinition()
{
$this->hasColumn('book_id', 'integer');
$this->hasColumn('name', 'string',20);
}
}

View file

@ -1,8 +1,7 @@
<?php
class BadLyNamed__Class extends Doctrine_Record {
public function setTableDefinition() {
public static function initMetadata($class) {
}
public function setUp() { }
}

View file

@ -1,13 +1,10 @@
<?php
class BarRecord extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->setTableName('bar');
$this->hasColumn('name', 'string', 200);
}
public function setUp()
{
$this->hasMany('FooRecord as Foo', array('local' => 'barId', 'foreign' => 'fooId', 'refClass' => 'FooBarRecord'));
$class->setTableName('bar');
$class->setColumn('name', 'string', 200);
$class->hasMany('FooRecord as Foo', array('local' => 'barId', 'foreign' => 'fooId', 'refClass' => 'FooBarRecord'));
}
}

View file

@ -1,13 +1,9 @@
<?php
abstract class BaseSymfonyRecord extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
}
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 30);
$class->setColumn('name', 'string', 30);
}
}

View file

@ -1,32 +1,23 @@
<?php
class Blog extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
}
public function setUp()
{
$this->loadTemplate('Taggable');
$class->loadTemplate('Taggable');
}
}
class Taggable extends Doctrine_Template
{
public function setUp()
public static function initMetadata($class)
{
//$this->hasMany('[Component]TagTemplate as Tag');
}
}
class TagTemplate extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string', 100);
$this->hasColumn('description', 'string');
}
public function setUp()
{
//$this->hasOne('[Component]', array('onDelete' => 'CASCADE'));
$class->setColumn('name', 'string', 100);
$class->setColumn('description', 'string');
}
}

View file

@ -1,13 +1,10 @@
<?php
class BlogTag extends Doctrine_Record
{
public function setTableDefinition()
<?php
class BlogTag extends Doctrine_Record
{
public static function initMetadata($class)
{
$this->hasColumn('name', 'string', 100);
$this->hasColumn('description', 'string');
$class->setColumn('name', 'string', 100);
$class->setColumn('description', 'string');
$class->hasOne('Blog', array('onDelete' => 'CASCADE'));
}
public function setUp()
{
$this->hasOne('Blog', array('onDelete' => 'CASCADE'));
}
}
}

View file

@ -1,10 +1,8 @@
<?php
class BoardWithPosition extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('position', 'integer');
$this->hasColumn('category_id', 'integer');
}
public function setUp() {
$this->hasOne('CategoryWithPosition as Category', array('local' => 'category_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
public static function initMetadata($class) {
$class->setColumn('position', 'integer');
$class->setColumn('category_id', 'integer');
$class->hasOne('CategoryWithPosition as Category', array('local' => 'category_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
}
}

View file

@ -1,16 +1,13 @@
<?php
class Book extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->hasMany('Author', array('local' => 'id', 'foreign' => 'book_id'));
$this->hasOne('User', array('local' => 'user_id',
$class->setColumn('user_id', 'integer');
$class->setColumn('name', 'string',20);
$class->hasMany('Author', array('local' => 'id', 'foreign' => 'book_id'));
$class->hasOne('User', array('local' => 'user_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
public function setTableDefinition()
{
$this->hasColumn('user_id', 'integer');
$this->hasColumn('name', 'string',20);
}
}

View file

@ -1,9 +1,9 @@
<?php
class Bookmark extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('user_id', 'integer', null, array('primary' => true));
$this->hasColumn('page_id', 'integer', null, array('primary' => true));
$class->setColumn('user_id', 'integer', null, array('primary' => true));
$class->setColumn('page_id', 'integer', null, array('primary' => true));
}
}

View file

@ -1,14 +1,11 @@
<?php
class BookmarkUser extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->hasMany('Bookmark as Bookmarks',
$class->setColumn('name', 'string', 30);
$class->hasMany('Bookmark as Bookmarks',
array('local' => 'id',
'foreign' => 'user_id'));
}
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 30);
}
}

View file

@ -1,7 +1,7 @@
<?php
class BooleanTest extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('is_working', 'boolean');
$this->hasColumn('is_working_notnull', 'boolean', 1, array('default' => false, 'notnull' => true));
public static function initMetadata($class) {
$class->setColumn('is_working', 'boolean');
$class->setColumn('is_working_notnull', 'boolean', 1, array('default' => false, 'notnull' => true));
}
}

View file

@ -1,7 +1,7 @@
<?php
class CPK_Association extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('test1_id', 'integer', 11, 'primary');
$this->hasColumn('test2_id', 'integer', 11, 'primary');
public static function initMetadata($class) {
$class->setColumn('test1_id', 'integer', 11, 'primary');
$class->setColumn('test2_id', 'integer', 11, 'primary');
}
}

View file

@ -1,9 +1,7 @@
<?php
class CPK_Test extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 255);
}
public function setUp() {
$this->hasMany('CPK_Test2 as Test', 'CPK_Association.test2_id');
public static function initMetadata($class) {
$class->setColumn('name', 'string', 255);
$class->hasMany('CPK_Test2 as Test', array('local' => 'test_id', 'foreign' => 'test2_id', 'refClass' => 'CPK_Association'));
}
}

View file

@ -1,9 +1,7 @@
<?php
class CPK_Test2 extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 255);
}
public function setUp() {
$this->hasMany('CPK_Test as Test', 'CPK_Association.test1_id');
public static function initMetadata($class) {
$class->setColumn('name', 'string', 255);
$class->hasMany('CPK_Test as Test', array('local' => 'test2_id', 'test1_id', 'refClass' => 'CPK_Association'));
}
}

View file

@ -1,19 +1,16 @@
<?php
class CascadeDeleteRelatedTest extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string');
$this->hasColumn('cscd_id', 'integer');
}
public function setUp()
{
$this->hasOne('CascadeDeleteTest', array('local' => 'cscd_id',
$class->setColumn('name', 'string');
$class->setColumn('cscd_id', 'integer');
$class->hasOne('CascadeDeleteTest', array('local' => 'cscd_id',
'foreign' => 'id',
'onDelete' => 'CASCADE',
'onUpdate' => 'SET NULL'));
$this->hasMany('CascadeDeleteRelatedTest2 as Related',
$class->hasMany('CascadeDeleteRelatedTest2 as Related',
array('local' => 'id',
'foreign' => 'cscd_id'));
}

View file

@ -1,14 +1,11 @@
<?php
class CascadeDeleteRelatedTest2 extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string');
$this->hasColumn('cscd_id', 'integer');
}
public function setUp()
{
$this->hasOne('CascadeDeleteRelatedTest', array('local' => 'cscd_id',
$class->setColumn('name', 'string');
$class->setColumn('cscd_id', 'integer');
$class->hasOne('CascadeDeleteRelatedTest', array('local' => 'cscd_id',
'foreign' => 'id',
'onDelete' => 'SET NULL'));
}

View file

@ -1,13 +1,10 @@
<?php
class CascadeDeleteTest extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string');
}
public function setUp()
{
$this->hasMany('CascadeDeleteRelatedTest as Related',
$class->setColumn('name', 'string');
$class->hasMany('CascadeDeleteRelatedTest as Related',
array('local' => 'id',
'foreign' => 'cscd_id'));
}

View file

@ -1,17 +1,12 @@
<?php
class CategoryNestedSet extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->setTableName('category_nested_set');
$this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$this->hasColumn('name', 'string', 255, array('notnull' => true));
$class->setTableName('category_nested_set');
$class->setColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$class->setColumn('name', 'string', 255, array('notnull' => true));
$this->actAs('NestedSet');
$class->actAs('NestedSet');
}
public function setUp()
{
}
}
}

View file

@ -1,10 +1,8 @@
<?php
class CategoryWithPosition extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('position', 'integer');
$this->hasColumn('name', 'string', 255);
public static function initMetadata($class) {
$class->setColumn('position', 'integer');
$class->setColumn('name', 'string', 255);
$class->hasMany('BoardWithPosition as Boards', array('local' => 'id' , 'foreign' => 'category_id'));
}
public function setUp() {
$this->hasMany('BoardWithPosition as Boards', array('local' => 'id' , 'foreign' => 'category_id'));
}
}

View file

@ -1,10 +1,10 @@
<?php
class CheckConstraintTest extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('price', 'decimal', 2, array('max' => 5000, 'min' => 100));
$this->hasColumn('discounted_price', 'decimal', 2);
$this->check('price > discounted_price');
$class->setColumn('price', 'decimal', 2, array('max' => 5000, 'min' => 100));
$class->setColumn('discounted_price', 'decimal', 2);
$class->check('price > discounted_price');
}
}

View file

@ -1,62 +1,47 @@
<?php
class ClientModel extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->setTableName('clients');
$class->setTableName('clients');
$this->hasColumn('id', 'integer', 4, array('notnull' => true,
$class->setColumn('id', 'integer', 4, array('notnull' => true,
'primary' => true,
'autoincrement' => true,
'unsigned' => true));
$this->hasColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true));
}
public function setUp()
{
$this->hasMany('AddressModel', array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ClientToAddressModel'));
$class->setColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true));
$class->hasMany('AddressModel', array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ClientToAddressModel'));
}
}
class ClientToAddressModel extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->setTableName('clients_to_addresses');
$class->setTableName('clients_to_addresses');
$this->hasColumn('client_id', 'integer', 11, array('primary' => true));
$this->hasColumn('address_id', 'integer', 11, array('primary' => true));
}
public function construct()
{
}
public function setUp()
{
$this->hasOne('ClientModel', array('local' => 'client_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
$this->hasOne('AddressModel', array('local' => 'address_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
$class->setColumn('client_id', 'integer', 11, array('primary' => true));
$class->setColumn('address_id', 'integer', 11, array('primary' => true));
$class->hasOne('ClientModel', array('local' => 'client_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
$class->hasOne('AddressModel', array('local' => 'address_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
}
}
class AddressModel extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->setTableName('addresses');
$class->setTableName('addresses');
$this->hasColumn('id', 'integer', 11, array('autoincrement' => true,
$class->setColumn('id', 'integer', 11, array('autoincrement' => true,
'primary' => true
));
$this->hasColumn('address1', 'string', 255, array('notnull' => true, 'notblank'));
$this->hasColumn('address2', 'string', 255, array('notnull' => true));
$this->hasColumn('city', 'string', 255, array('notnull' => true, 'notblank'));
$this->hasColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate'));
$this->hasColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/'));
}
public function setUp()
{
$this->hasMany('ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ClientToAddressModel'));
$class->setColumn('address1', 'string', 255, array('notnull' => true, 'notblank'));
$class->setColumn('address2', 'string', 255, array('notnull' => true));
$class->setColumn('city', 'string', 255, array('notnull' => true, 'notblank'));
$class->setColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate'));
$class->setColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/'));
$class->hasMany('ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ClientToAddressModel'));
}
}

View file

@ -1,15 +1,12 @@
<?php
class ColumnAliasTest extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('column1 as alias1', 'string', 200);
$this->hasColumn('column2 as alias2', 'integer', 4);
$this->hasColumn('another_column as anotherField', 'string', 50);
$this->hasColumn('book_id as bookId', 'integer', 4);
}
public function setUp()
{
$this->hasOne('Book as book', array('local' => 'book_id', 'foreign' => 'id'));
$class->setColumn('column1 as alias1', 'string', 200);
$class->setColumn('column2 as alias2', 'integer', 4);
$class->setColumn('another_column as anotherField', 'string', 50);
$class->setColumn('book_id as bookId', 'integer', 4);
$class->hasOne('Book as book', array('local' => 'book_id', 'foreign' => 'id'));
}
}

View file

@ -1,8 +1,8 @@
<?php
class ConcreteEmail extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->loadTemplate('EmailTemplate');
$class->loadTemplate('EmailTemplate');
}
}

View file

@ -1,8 +1,8 @@
<?php
class ConcreteGroup extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->loadTemplate('GroupTemplate');
$class->loadTemplate('GroupTemplate');
}
}

View file

@ -1,8 +1,8 @@
<?php
class ConcreteGroupUser extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->loadTemplate('GroupUserTemplate');
$class->loadTemplate('GroupUserTemplate');
}
}

View file

@ -1,18 +1,16 @@
<?php
class ConcreteInheritanceTestParent extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string');
$class->setColumn('name', 'string');
}
}
class ConcreteInheritanceTestChild extends ConcreteInheritanceTestParent
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('age', 'integer');
parent::setTableDefinition();
$class->setColumn('age', 'integer');
}
}

View file

@ -1,9 +1,9 @@
<?php
class ConcreteUser extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->loadTemplate('UserTemplate');
$class->loadTemplate('UserTemplate');
}
}

View file

@ -1,14 +1,10 @@
<?php
class CoverageCodeN extends Doctrine_Record {
public function setTableDefinition(){
$this->setTableName('coverage_codes');
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
public static function initMetadata($class) {
$class->setTableName('coverage_codes');
$class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
$class->setColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$class->setColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
}
public function setUp(){
# $this->index('code', array('fields' => 'code'));
}
}

View file

@ -1,7 +1,7 @@
<?php
class CustomPK extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('uid', 'integer',11, 'autoincrement|primary');
$this->hasColumn('name', 'string',255);
public static function initMetadata($class) {
$class->setColumn('uid', 'integer',11, 'autoincrement|primary');
$class->setColumn('name', 'string',255);
}
}

View file

@ -1,9 +1,9 @@
<?php
class CustomSequenceRecord extends Doctrine_Record {
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('id', 'integer', null, array('primary', 'sequence' => 'custom_seq'));
$this->hasColumn('name', 'string');
$class->setColumn('id', 'integer', null, array('primary', 'sequence' => 'custom_seq'));
$class->setColumn('name', 'string');
}
}

View file

@ -1,10 +1,8 @@
<?php
class Data_File extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('filename', 'string');
$this->hasColumn('file_owner_id', 'integer');
}
public function setUp() {
$this->hasOne('File_Owner', 'Data_File.file_owner_id');
public static function initMetadata($class) {
$class->setColumn('filename', 'string');
$class->setColumn('file_owner_id', 'integer');
$class->hasOne('File_Owner', array('local' => 'file_owner_id', 'foreign' => 'id'));
}
}

View file

@ -1,7 +1,7 @@
<?php
class DateTest extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('date', 'date', 20);
public static function initMetadata($class) {
$class->setColumn('date', 'date', 20);
}
}

View file

@ -1,8 +1,8 @@
<?php
class Description extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('description', 'string',3000);
$this->hasColumn('file_md5', 'string',32);
public static function initMetadata($class) {
$class->setColumn('description', 'string',3000);
$class->setColumn('file_md5', 'string',32);
}
}

View file

@ -1,12 +1,10 @@
<?php
class Element extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 100);
$this->hasColumn('parent_id', 'integer');
}
public function setUp() {
$this->hasMany('Element as Child', 'Child.parent_id');
$this->hasOne('Element as Parent', 'Element.parent_id');
public static function initMetadata($class) {
$class->setColumn('name', 'string', 100);
$class->setColumn('parent_id', 'integer');
$class->hasMany('Element as Child', array('local' => 'id', 'foreign' => 'parent_id'));
$class->hasOne('Element as Parent', array('local' => 'parent_id', 'foreign' => 'id'));
}
}

View file

@ -1,9 +1,9 @@
<?php
class Email extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('address', 'string', 150, 'email|unique');
$class->setColumn('address', 'string', 150, 'email|unique');
}

View file

@ -1,26 +1,29 @@
<?php
class Entity extends Doctrine_Record
{
public function setUp()
public static function initMetadata($class)
{
$this->hasOne('Email', array('local' => 'email_id'));
$this->hasMany('Phonenumber', array('local' => 'id', 'foreign' => 'entity_id'));
$this->hasOne('Account', array('foreign' => 'entity_id'));
$this->hasMany('Entity', array('local' => 'entity1',
$class->setColumn('id', 'integer',20, array('autoincrement' => true, 'primary' => true));
$class->setColumn('name', 'string',50);
$class->setColumn('loginname', 'string',20, array('unique' => true));
$class->setColumn('password', 'string',16);
$class->setColumn('type', 'integer');
$class->setColumn('created', 'integer',11);
$class->setColumn('updated', 'integer',11);
$class->setColumn('email_id', 'integer');
$class->setSubclasses(array('Group', 'User'));
$class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array(
'discriminatorColumn' => 'type',
'discriminatorMap' => array(0 => 'User', 1 => 'Group', 2 => 'Entity')
));
$class->hasOne('Email', array('local' => 'email_id'));
$class->hasMany('Phonenumber', array('local' => 'id', 'foreign' => 'entity_id'));
$class->hasOne('Account', array('foreign' => 'entity_id'));
$class->hasMany('Entity', array('local' => 'entity1',
'refClass' => 'EntityReference',
'foreign' => 'entity2',
'equal' => true));
}
public function setTableDefinition()
{
$this->hasColumn('id', 'integer',20, 'autoincrement|primary');
$this->hasColumn('name', 'string',50);
$this->hasColumn('loginname', 'string',20, array('unique'));
$this->hasColumn('password', 'string',16);
$this->hasColumn('type', 'integer',1);
$this->hasColumn('created', 'integer',11);
$this->hasColumn('updated', 'integer',11);
$this->hasColumn('email_id', 'integer');
$this->setSubclasses(array("User" => array("type" => 0), "Group" => array("type" => 1)));
}
}

View file

@ -1,9 +1,9 @@
<?php
class EntityAddress extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('user_id', 'integer', null, array('primary' => true));
$this->hasColumn('address_id', 'integer', null, array('primary' => true));
$class->setColumn('user_id', 'integer', null, array('primary' => true));
$class->setColumn('address_id', 'integer', null, array('primary' => true));
}
}

View file

@ -1,11 +1,10 @@
<?php
class EntityReference extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('entity1', 'integer', null, 'primary');
$this->hasColumn('entity2', 'integer', null, 'primary');
//$this->setPrimaryKey(array('entity1', 'entity2'));
$class->setColumn('entity1', 'integer', null, 'primary');
$class->setColumn('entity2', 'integer', null, 'primary');
}
}

View file

@ -1,12 +1,10 @@
<?php
class EnumTest extends Doctrine_Record
{
public function setTableDefinition() {
$this->hasColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed')));
$this->hasColumn('text', 'string');
}
public function setUp() {
$this->hasMany('EnumTest2 as Enum2', array('local' => 'id', 'foreign' => 'enum_test_id'));
$this->hasMany('EnumTest3 as Enum3', array('local' => 'text', 'foreign' => 'text'));
public static function initMetadata($class) {
$class->setColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed')));
$class->setColumn('text', 'string');
$class->hasMany('EnumTest2 as Enum2', array('local' => 'id', 'foreign' => 'enum_test_id'));
$class->hasMany('EnumTest3 as Enum3', array('local' => 'text', 'foreign' => 'text'));
}
}

View file

@ -1,8 +1,8 @@
<?php
class EnumTest2 extends Doctrine_Record
{
public function setTableDefinition() {
$this->hasColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed')));
$this->hasColumn('enum_test_id', 'integer');
public static function initMetadata($class) {
$class->setColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed')));
$class->setColumn('enum_test_id', 'integer');
}
}

View file

@ -1,7 +1,7 @@
<?php
class EnumTest3 extends Doctrine_Record
{
public function setTableDefinition() {
$this->hasColumn('text', 'string', 10, array('primary' => true));
public static function initMetadata($class) {
$class->setColumn('text', 'string', 10, array('primary' => true));
}
}

View file

@ -1,12 +1,10 @@
<?php
class Error extends Doctrine_Record {
public function setUp() {
$this->hasMany('Description', 'Description.file_md5', 'file_md5');
}
public function setTableDefinition() {
$this->hasColumn('message', 'string',200);
$this->hasColumn('code', 'integer',11);
$this->hasColumn('file_md5', 'string',32, 'primary');
public static function initMetadata($class) {
$class->setColumn('message', 'string',200);
$class->setColumn('code', 'integer',11);
$class->setColumn('file_md5', 'string',32, 'primary');
$class->hasMany('Description', array('local' => 'file_md5', 'foreign' => 'file_md5'));
}
}

View file

@ -1,10 +1,8 @@
<?php
class EventListenerChainTest extends Doctrine_Record
{
public function setTableDefinition() {
$this->hasColumn('name', 'string', 100);
}
public function setUp() {
public static function initMetadata($class) {
$class->setColumn('name', 'string', 100);
$chain = new Doctrine_EventListener_Chain();
$chain->add(new Doctrine_EventListener_TestA());
$chain->add(new Doctrine_EventListener_TestB());

View file

@ -1,11 +1,8 @@
<?php
class EventListenerTest extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name", "string", 100);
$this->hasColumn("password", "string", 8);
}
public function setUp() {
//$this->attribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker());
public static function initMetadata($class) {
$class->setColumn("name", "string", 100);
$class->setColumn("password", "string", 8);
}
public function getName($name) {
return strtoupper($name);

View file

@ -1,12 +1,12 @@
<?php
class FieldNameTest extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('someColumn', 'string', 200, array('default' => 'some string'));
$this->hasColumn('someEnum', 'enum', 4, array('default' => 'php', 'values' => array('php', 'java', 'python')));
$this->hasColumn('someArray', 'array', 100, array('default' => array()));
$this->hasColumn('someObject', 'object', 200, array('default' => new stdClass));
$this->hasColumn('someInt', 'integer', 20, array('default' => 11));
$class->setColumn('someColumn', 'string', 200, array('default' => 'some string'));
$class->setColumn('someEnum', 'enum', 4, array('default' => 'php', 'values' => array('php', 'java', 'python')));
$class->setColumn('someArray', 'array', 100, array('default' => array()));
$class->setColumn('someObject', 'object', 200, array('default' => new stdClass));
$class->setColumn('someInt', 'integer', 20, array('default' => 11));
}
}

View file

@ -1,9 +1,7 @@
<?php
class File_Owner extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 255);
}
public function setUp() {
$this->hasOne('Data_File', 'Data_File.file_owner_id');
public static function initMetadata($class) {
$class->setColumn('name', 'string', 255);
$class->hasOne('Data_File', array('local' => 'id', 'foreign' => 'file_owner_id'));
}
}

View file

@ -1,9 +1,7 @@
<?php
class FilterTest extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string',100);
}
public function setUp() {
$this->hasMany('FilterTest2 as filtered', 'FilterTest2.test1_id');
public static function initMetadata($class) {
$class->setColumn('name', 'string',100);
$class->hasMany('FilterTest2 as filtered', array('local' => 'id', 'foreign' => 'test1_id'));
}
}

View file

@ -1,7 +1,7 @@
<?php
class FilterTest2 extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string',100);
$this->hasColumn('test1_id', 'integer');
public static function initMetadata($class) {
$class->setColumn('name', 'string',100);
$class->setColumn('test1_id', 'integer');
}
}

View file

@ -1,9 +1,9 @@
<?php
class FooBarRecord extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('fooId', 'integer', null, array('primary' => true));
$this->hasColumn('barId', 'integer', null, array('primary' => true));
$class->setColumn('fooId', 'integer', null, array('primary' => true));
$class->setColumn('barId', 'integer', null, array('primary' => true));
}
}

View file

@ -1,9 +1,9 @@
<?php
class FooForeignlyOwned extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string', 200);
$this->hasColumn('fooId', 'integer');
$class->setColumn('name', 'string', 200);
$class->setColumn('fooId', 'integer');
}
}

View file

@ -1,12 +1,8 @@
<?php
class FooForeignlyOwnedWithPk extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string', 200);
}
public function setUp()
{
//$this->hasOne('FooRecord', array('local' => 'id', 'foreign' => 'id'));
$class->setColumn('name', 'string', 200);
}
}

View file

@ -1,9 +1,9 @@
<?php
class FooLocallyOwned extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string', 200);
$class->setColumn('name', 'string', 200);
}
}

View file

@ -1,43 +1,38 @@
<?php
class FooRecord extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->setTableName('foo');
$class->setTableName('foo');
$class->setColumn('name', 'string', 200, array('notnull' => true));
$class->setColumn('parent_id', 'integer');
$class->setColumn('local_foo', 'integer');
$this->hasColumn('name', 'string', 200, array('notnull' => true));
$this->hasColumn('parent_id', 'integer');
$this->hasColumn('local_foo', 'integer');
}
public function setUp()
{
$this->hasMany('FooRecord as FooFriend', array('local' => 'foo1',
$class->hasMany('FooRecord as FooFriend', array('local' => 'foo1',
'foreign' => 'foo2',
'equal' => true,
'refClass' => 'FooReferenceRecord',
));
$this->hasMany('FooRecord as FooParents', array('local' => 'foo1',
$class->hasMany('FooRecord as FooParents', array('local' => 'foo1',
'foreign' => 'foo2',
'refClass' => 'FooReferenceRecord',
'onDelete' => 'RESTRICT',
));
$this->hasMany('FooRecord as FooChildren', array('local' => 'foo2',
$class->hasMany('FooRecord as FooChildren', array('local' => 'foo2',
'foreign' => 'foo1',
'refClass' => 'FooReferenceRecord',
));
$this->hasMany('FooRecord as Children', array('local' => 'id', 'foreign' => 'parent_id'));
$class->hasMany('FooRecord as Children', array('local' => 'id', 'foreign' => 'parent_id'));
$this->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
//$this->hasOne('FooForeignlyOwnedWithPk', array('local' => 'id', 'foreign' => 'id', 'constraint' => true));
$this->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT'));
$class->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
$class->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT'));
$this->hasMany('BarRecord as Bar', array('local' => 'fooId',
$class->hasMany('BarRecord as Bar', array('local' => 'fooId',
'foreign' => 'barId',
'refClass' => 'FooBarRecord',
'onUpdate' => 'RESTRICT'));
}
}

View file

@ -1,11 +1,10 @@
<?php
class FooReferenceRecord extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->setTableName('foo_reference');
$this->hasColumn('foo1', 'integer', null, array('primary' => true));
$this->hasColumn('foo2', 'integer', null, array('primary' => true));
$class->setTableName('foo_reference');
$class->setColumn('foo1', 'integer', null, array('primary' => true));
$class->setColumn('foo2', 'integer', null, array('primary' => true));
}
}

View file

@ -1,24 +1,22 @@
<?php
class ForeignKeyTest extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string', null);
$this->hasColumn('code', 'integer', 4);
$this->hasColumn('content', 'string', 4000);
$this->hasColumn('parent_id', 'integer');
$class->setColumn('name', 'string', null);
$class->setColumn('code', 'integer', 4);
$class->setColumn('content', 'string', 4000);
$class->setColumn('parent_id', 'integer');
$this->hasOne('ForeignKeyTest as Parent',
$class->hasOne('ForeignKeyTest as Parent',
array('local' => 'parent_id',
'foreign' => 'id',
'onDelete' => 'CASCADE',
'onUpdate' => 'RESTRICT')
);
$this->hasMany('ForeignKeyTest as Children',
'ForeignKeyTest.parent_id');
$this->option('type', 'INNODB');
$class->hasMany('ForeignKeyTest as Children', array('local' => 'id', 'foreign' => 'parent_id'));
$class->setTableOption('type', 'INNODB');
}
}

View file

@ -1,11 +1,10 @@
<?php
class ForeignKeyTest2 extends Doctrine_Record
{
public function setTableDefinition()
public static function initMetadata($class)
{
$this->hasColumn('name', 'string', null);
$this->hasColumn('foreignkey', 'integer');
$this->hasOne('ForeignKeyTest', 'ForeignKeyTest2.foreignkey');
$class->setColumn('name', 'string', null);
$class->setColumn('foreignkey', 'integer');
$class->hasOne('ForeignKeyTest', array('local' => 'foreignkey', 'foreign' => 'id'));
}
}

View file

@ -1,13 +1,11 @@
<?php
class Forum_Board extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('category_id', 'integer', 10);
$this->hasColumn('name', 'string', 100);
$this->hasColumn('description', 'string', 5000);
public static function initMetadata($class) {
$class->setColumn('category_id', 'integer', 10);
$class->setColumn('name', 'string', 100);
$class->setColumn('description', 'string', 5000);
$class->hasOne('Forum_Category as Category', array('local' => 'category_id', 'foreign' => 'id'));
$class->hasMany('Forum_Thread as Threads', array('local' => 'id', 'foreign' => 'board_id'));
}
public function setUp() {
$this->hasOne('Forum_Category as Category', array('local' => 'category_id', 'foreign' => 'id'));
$this->hasMany('Forum_Thread as Threads', array('local' => 'id', 'foreign' => 'board_id'));
}
}

View file

@ -1,14 +1,12 @@
<?php
class Forum_Category extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('root_category_id', 'integer', 10);
$this->hasColumn('parent_category_id', 'integer', 10);
$this->hasColumn('name', 'string', 50);
$this->hasColumn('description', 'string', 99999);
}
public function setUp() {
$this->hasMany('Forum_Category as Subcategory', 'Subcategory.parent_category_id');
$this->hasOne('Forum_Category as Parent', 'Forum_Category.parent_category_id');
$this->hasOne('Forum_Category as Rootcategory', 'Forum_Category.root_category_id');
public static function initMetadata($class) {
$class->setColumn('root_category_id', 'integer', 10);
$class->setColumn('parent_category_id', 'integer', 10);
$class->setColumn('name', 'string', 50);
$class->setColumn('description', 'string', 99999);
$class->hasMany('Forum_Category as Subcategory', array('local' => 'id', 'foreign' => 'parent_category_id'));
$class->hasOne('Forum_Category as Parent', array('local' => 'parent_category_id', 'foreign' => 'id'));
$class->hasOne('Forum_Category as Rootcategory', array('local' => 'root_category_id', 'foreign' => 'id'));
}
}

Some files were not shown because too many files have changed in this diff Show more