1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Possibility to pass the hasColumn constraint/validator arg as an array

This commit is contained in:
zYne 2006-08-31 10:00:09 +00:00
parent c929174385
commit f11fe0ca34
5 changed files with 42 additions and 27 deletions

View File

@ -32,7 +32,10 @@ class Doctrine_DataDict {
*/ */
public function createTable($tablename, array $columns) { public function createTable($tablename, array $columns) {
foreach($columns as $name => $args) { foreach($columns as $name => $args) {
$r[] = $name." ".$this->getADOType($args[0],$args[1])." ".str_replace("|"," ",$args[2]); if( ! is_array($args[2]))
$args[2] = array();
$r[] = $name." ".$this->getADOType($args[0],$args[1])." ".implode(' ',$args[2]);
} }

View File

@ -1,9 +1,5 @@
<?php <?php
class Doctrine_Identifier { class Doctrine_Identifier {
/**
* constant for unique identifier
*/
const UNIQUE = 0;
/** /**
* constant for auto_increment identifier * constant for auto_increment identifier
*/ */

View File

@ -37,10 +37,10 @@ class Doctrine_Locking_Manager_Pessimistic
if($this->_dataSource->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) if($this->_dataSource->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true)
{ {
$columns = array(); $columns = array();
$columns['object_type'] = array('string', 50, 'notnull|primary'); $columns['object_type'] = array('string', 50, array('notnull','primary'));
$columns['object_key'] = array('string', 250, 'notnull|primary'); $columns['object_key'] = array('string', 250, array('notnull','primary'));
$columns['user_ident'] = array('string', 50, 'notnull'); $columns['user_ident'] = array('string', 50, array('notnull'));
$columns['timestamp_obtained'] = array('integer', 10, 'notnull'); $columns['timestamp_obtained'] = array('integer', 10, array('notnull'));
$dataDict = new Doctrine_DataDict($this->_dataSource->getDBH()); $dataDict = new Doctrine_DataDict($this->_dataSource->getDBH());
$dataDict->createTable($this->_lockTable, $columns); $dataDict->createTable($this->_lockTable, $columns);

View File

@ -274,7 +274,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$value = unserialize($tmp[$name]); $value = unserialize($tmp[$name]);
if($value === false) if($value === false)
throw new Doctrine_Exception("Unserialization of $name failed. ".var_dump($tmp[$name],true)); throw new Doctrine_Record_Exception("Unserialization of $name failed. ".var_dump($tmp[$name],true));
} else } else
$value = $tmp[$name]; $value = $tmp[$name];

View File

@ -1,4 +1,23 @@
<?php <?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
require_once("Exception/Find.class.php"); require_once("Exception/Find.class.php");
require_once("Exception/Mapping.class.php"); require_once("Exception/Mapping.class.php");
require_once("Exception/PrimaryKey.class.php"); require_once("Exception/PrimaryKey.class.php");
@ -158,7 +177,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
switch(count($this->primaryKeys)): switch(count($this->primaryKeys)):
case 0: case 0:
$this->columns = array_merge(array("id" => array("integer",11,"autoincrement|primary")), $this->columns); $this->columns = array_merge(array("id" => array("integer",11, array("autoincrement", "primary"))), $this->columns);
$this->primaryKeys[] = "id"; $this->primaryKeys[] = "id";
$this->identifier = "id"; $this->identifier = "id";
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT; $this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
@ -171,10 +190,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
} else { } else {
foreach($this->primaryKeys as $pk) { foreach($this->primaryKeys as $pk) {
$o = $this->columns[$pk][2]; $e = $this->columns[$pk][2];
$e = explode("|",$o);
$found = false;
$found = false;
foreach($e as $option) { foreach($e as $option) {
if($found) if($found)
@ -183,10 +201,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$e2 = explode(":",$option); $e2 = explode(":",$option);
switch(strtolower($e2[0])): switch(strtolower($e2[0])):
case "unique":
$this->identifierType = Doctrine_Identifier::UNIQUE;
$found = true;
break;
case "autoincrement": case "autoincrement":
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT; $this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
$found = true; $found = true;
@ -261,11 +275,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @param mixed $options * @param mixed $options
* @return void * @return void
*/ */
final public function setColumn($name, $type, $length, $options = "") { final public function setColumn($name, $type, $length, $options = array()) {
if(is_string($options))
$options = explode('|', $options);
$this->columns[$name] = array($type,$length,$options); $this->columns[$name] = array($type,$length,$options);
$e = explode("|",$options); if(in_array("primary",$options)) {
if(in_array("primary",$e)) {
$this->primaryKeys[] = $name; $this->primaryKeys[] = $name;
} }
} }
@ -525,7 +541,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @param string $name component name of which a foreign key object is bound * @param string $name component name of which a foreign key object is bound
* @return boolean * @return boolean
*/ */
final public function hasForeignKey($name) { final public function hasRelation($name) {
if(isset($this->bound[$name])) if(isset($this->bound[$name]))
return true; return true;
@ -565,7 +581,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$relation = new Doctrine_LocalKey($table,$foreign,$local,$type, $alias); $relation = new Doctrine_LocalKey($table,$foreign,$local,$type, $alias);
} else } else
throw new Doctrine_Mapping_Exception("Only one-to-one relations are possible when local reference key is used."); throw new Doctrine_Table_Exception("Only one-to-one relations are possible when local reference key is used.");
} elseif($component == $name || ($component == $alias && $name == $this->name)) { } elseif($component == $name || ($component == $alias && $name == $this->name)) {
if( ! isset($local)) if( ! isset($local))
@ -579,7 +595,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
// only aggregate relations allowed // only aggregate relations allowed
if($type != Doctrine_Relation::MANY_AGGREGATE) if($type != Doctrine_Relation::MANY_AGGREGATE)
throw new Doctrine_Mapping_Exception("Only aggregate relations are allowed for many-to-many relations"); throw new Doctrine_Table_Exception("Only aggregate relations are allowed for many-to-many relations");
$classes = array_merge($this->parents, array($this->name)); $classes = array_merge($this->parents, array($this->name));
@ -597,7 +613,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$fields = explode("-",$e2[1]); $fields = explode("-",$e2[1]);
if($e2[0] != $component) if($e2[0] != $component)
throw new Doctrine_Mapping_Exception($e2[0]." doesn't match ".$component); throw new Doctrine_Table_Exception($e2[0]." doesn't match ".$component);
$associationTable = $this->connection->getTable($e2[0]); $associationTable = $this->connection->getTable($e2[0]);
@ -617,7 +633,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$this->relations[$alias] = $relation; $this->relations[$alias] = $relation;
return $this->relations[$alias]; return $this->relations[$alias];
} }
throw new InvalidKeyException('Unknown relation '.$original); throw new Doctrine_Table_Exception('Unknown relation '.$original);
} }
/** /**
* returns an array containing all foreign key objects * returns an array containing all foreign key objects
@ -795,7 +811,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$this->data = $this->connection->execute($query,$params)->fetch(PDO::FETCH_ASSOC); $this->data = $this->connection->execute($query,$params)->fetch(PDO::FETCH_ASSOC);
if($this->data === false) if($this->data === false)
throw new Doctrine_Find_Exception(); return false;
} }
return $this->getRecord(); return $this->getRecord();
} }