Commit c1c3f489 authored by romanb's avatar romanb

validator refactorings and others

parent 514e17ea
This diff is collapsed.
......@@ -1047,9 +1047,9 @@ 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')) {
if (strstr($e->getMessage(), 'may not be NULL')) {
echo $e->getMessage() . "<br />" . $e->getTraceAsString() . "<br />";
}*/
}
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
......
......@@ -29,15 +29,61 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @todo package:orm. Figure out a useful implementation.
*/
class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
{
/**
* A map of all currently managed entities.
*
* @var array
*/
protected $_managedEntities = array();
/**
* The identity map that holds references to all managed entities that have
* an identity.
*/
protected $_identityMap = array();
/**
* Boolean flag that indicates whether the unit of work immediately executes any
* database operations or whether these operations are postponed until the
* unit of work is flushed/committed.
*
* @var boolean
*/
protected $_autoflush = true;
/**
* A list of all postponed inserts.
*/
protected $_inserts = array();
/**
* A list of all postponed updates.
*/
protected $_updates = array();
/**
* A list of all postponed deletes.
*/
protected $_deletes = array();
/**
* The dbal connection used by the unit of work.
*
* @var Doctrine_Connection
* @todo Allow multiple connections for transparent master-slave replication.
*/
protected $_conn;
/**
* Flushes the unit of work, executing all operations that have been postponed
* up to this point.
*
*/
public function flush()
{
// get the flush tree
......@@ -47,7 +93,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
foreach ($tree as $name) {
$mapper = $this->conn->getMapper($name);
foreach ($mapper->getRepository() as $record) {
//echo $record->getOid() . "<br />";
$mapper->saveSingleRecord($record);
}
}
......@@ -95,7 +140,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if ( ! ($mapper instanceof Doctrine_Mapper)) {
$mapper = $this->conn->getMapper($mapper);
}
$nm = $mapper->getComponentName();
$nm = $mapper->getComponentName();
$index = array_search($nm, $tree);
......@@ -172,6 +217,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
}
}
return array_values($tree);
}
......
......@@ -497,6 +497,21 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return $query;
}
/**
* Creates a new native query (instance of Doctrine_RawSql).
*
* @return Doctrine_RawSql
*/
public function createNativeQuery($sql = "")
{
$nativeQuery = new Doctrine_RawSql($this->getCurrentConnection());
if ( ! empty($sql)) {
$nativeQuery->parseQuery($sql);
}
return $nativeQuery;
}
/**
* Creates a query object out of a registered, named query.
*
......
......@@ -317,6 +317,17 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
return true;
}
/**
* Tells the mapper to manage the entity if it's not already managed.
*
* @return boolean TRUE if the entity was previously not managed and is now managed,
* FALSE otherwise (the entity is already managed).
*/
public function manage(Doctrine_Record $record)
{
return $this->getRepository()->add($record);
}
/**
* removeRecord
......
This diff is collapsed.
......@@ -67,6 +67,7 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
*/
public function validateRecord(Doctrine_Record $record)
{
$classMetadata = $record->getTable();
$columns = $record->getTable()->getColumns();
$component = $record->getTable()->getComponentName();
......@@ -74,90 +75,49 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
// if record is transient all fields will be validated
// if record is persistent only the modified fields will be validated
$data = ($record->exists()) ? $record->getModified() : $record->getData();
$err = array();
foreach ($data as $key => $value) {
$fields = ($record->exists()) ? $record->getModified() : $record->getData();
$err = array();
foreach ($fields as $fieldName => $value) {
if ($value === self::$_null) {
$value = null;
} else if ($value instanceof Doctrine_Record) {
$value = $value->getIncremented();
}
$dataType = $classMetadata->getTypeOf($fieldName);
$column = $columns[$record->getTable()->getColumnName($key)];
if ($column['type'] == 'enum') {
$value = $record->getTable()->enumIndex($key, $value);
if ($value === false) {
$errorStack->add($key, 'enum');
continue;
// Validate field type, if type validation is enabled
if ($classMetadata->getAttribute(Doctrine::ATTR_VALIDATE) & Doctrine::VALIDATE_TYPES) {
if ( ! self::isValidType($value, $dataType)) {
$errorStack->add($fieldName, 'type');
}
if ($dataType == 'enum') {
$enumIndex = $classMetadata->enumIndex($fieldName, $value);
if ($enumIndex === false) {
$errorStack->add($fieldName, 'enum');
}
}
}
// Validate field length, if length validation is enabled
if ($record->getTable()->getAttribute(Doctrine::ATTR_VALIDATE) & Doctrine::VALIDATE_LENGTHS) {
if ( ! $this->validateLength($column, $key, $value)) {
$errorStack->add($key, 'length');
continue;
if ( ! $this->validateLength($value, $dataType, $classMetadata->getFieldLength($fieldName))) {
$errorStack->add($fieldName, 'length');
}
}
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 == 'inherited') {
continue;
// Run all custom validators
foreach ($classMetadata->getFieldValidators($fieldName) as $validatorName => $args) {
if ( ! is_string($validatorName)) {
$validatorName = $args;
$args = array();
}
if (strtolower($name) === 'notnull' && isset($column['autoincrement'])) {
continue;
}
if (strtolower($name) == 'length') {
if ( ! ($record->getTable()->getAttribute(Doctrine::ATTR_VALIDATE) & Doctrine::VALIDATE_LENGTHS)) {
if ( ! $this->validateLength($column, $key, $value)) {
$errorStack->add($key, 'length');
}
}
continue;
}
if (strtolower($name) == 'type') {
if ( ! ($record->getTable()->getAttribute(Doctrine::ATTR_VALIDATE) & Doctrine::VALIDATE_TYPES)) {
if ( ! self::isValidType($value, $column['type'])) {
$errorStack->add($key, 'type');
}
}
continue;
}
$validator = self::getValidator($name);
$validator = self::getValidator($validatorName);
$validator->invoker = $record;
$validator->field = $key;
$validator->args = $args;
$validator->field = $fieldName;
$validator->args = $args;
if ( ! $validator->validate($value)) {
$errorStack->add($key, $name);
//$err[$key] = 'not valid';
// errors found quit validation looping for this column
//break;
}
}
if ($record->getTable()->getAttribute(Doctrine::ATTR_VALIDATE) & Doctrine::VALIDATE_TYPES) {
if ( ! self::isValidType($value, $column['type'])) {
$errorStack->add($key, 'type');
continue;
$errorStack->add($fieldName, $validatorName);
}
}
}
......@@ -166,18 +126,16 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
/**
* Validates the length of a field.
*/
private function validateLength($column, $key, $value)
private function validateLength($value, $type, $maximumLength)
{
if ($column['type'] == 'timestamp' || $column['type'] == 'integer' ||
$column['type'] == 'enum') {
if ($type == 'timestamp' || $type == 'integer' || $type == 'enum') {
return true;
} else if ($column['type'] == 'array' || $column['type'] == 'object') {
} else if ($type == 'array' || $type == 'object') {
$length = strlen(serialize($value));
} else {
$length = strlen($value);
}
if ($length > $column['length']) {
if ($length > $maximumLength) {
return false;
}
return true;
......@@ -191,68 +149,7 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
public function hasErrors()
{
return (count($this->stack) > 0);
}
/**
* phpType
* converts a doctrine type to native php type
*
* @param $portableType portable doctrine type
* @return string
*//*
public static function phpType($portableType)
{
switch ($portableType) {
case 'enum':
return 'integer';
case 'blob':
case 'clob':
case 'mbstring':
case 'timestamp':
case 'date':
case 'gzip':
return 'string';
break;
default:
return $portableType;
}
}*/
/**
* returns whether or not the given variable is
* valid type
*
* @param mixed $var
* @param string $type
* @return boolean
*/
/*
public static function isValidType($var, $type)
{
if ($type == 'boolean') {
return true;
}
$looseType = self::gettype($var);
$type = self::phpType($type);
switch ($looseType) {
case 'float':
case 'double':
case 'integer':
if ($type == 'string' || $type == 'float') {
return true;
}
case 'string':
case 'array':
case 'object':
return ($type === $looseType);
break;
case 'NULL':
return true;
break;
}
}*/
}
/**
* returns whether or not the given variable is
......@@ -300,29 +197,4 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
return false;
}
}
/**
* returns the type of loosely typed variable
*
* @param mixed $var
* @return string
*//*
public static function gettype($var)
{
$type = gettype($var);
switch ($type) {
case 'string':
if (preg_match("/^[0-9]+$/",$var)) {
return 'integer';
} elseif (is_numeric($var)) {
return 'float';
} else {
return $type;
}
break;
default:
return $type;
}
}*/
}
......@@ -44,6 +44,16 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
$this->user = new ForumUser();
}
public function testAccessorOverridePerformance() {
$this->user->username;
$start = microtime(true);
for ($i = 0; $i < 1; $i++) {
$this->user->username;
}
$end = microtime(true);
echo ($end - $start) . " seconds" . PHP_EOL;
}
/**
* @test
*/
......
......@@ -119,24 +119,4 @@ class Doctrine_OrmTestCase extends Doctrine_TestCase
$conn->exec("DELETE FROM " . $conn->getClassMetadata($model)->getTableName());
}
}
/*
public function loadFixturesPackage($package, $models = array())
{
$packagePath = 'fixtures' . DIRECTORY_SEPARATOR . $package;
if ( ! file_exists($packagePath)) {
throw new Exception("Could not find fixtures package: $package.");
}
$modelsPath = $packagePath . DIRECTORY_SEPARATOR . 'models';
$dataPath = $packagePath . DIRECTORY_SEPARATOR . 'data';
Doctrine::loadModels($modelsPath);
Doctrine::createTablesFromModels($modelsPath);
$data = new Doctrine_Data();
$data->importData($dataPath, 'yml', $models);
}
*/
}
\ No newline at end of file
......@@ -16,11 +16,17 @@ class ForumUser extends Doctrine_Record
// the discriminator column
$class->mapColumn('dtype', 'string', 50);
// property mapping
// column mapping
$class->mapColumn('id', 'integer', 4, array(
'primary' => true,
'autoincrement' => true));
$class->mapColumn('username', 'string', 50);
}
/*
public function getUsername()
{
return $this->rawGet('username') . "!";
}
*/
}
\ No newline at end of file
......@@ -300,4 +300,13 @@ class Doctrine_UnitTestCase extends UnitTestCase
$this->init = true;
}
public function tearDown()
{
/*foreach ($this->tables as $table) {
foreach ($this->conn->getMapper($table)->getRepository() as $obj) {
$obj->free();
}
}*/
}
}
......@@ -116,11 +116,15 @@ class UnitTestCase
foreach (get_class_methods($this) as $method) {
if (substr($method, 0, 4) === 'test') {
$this->setUp();
$this->$method();
$this->tearDown();
}
}
}
public function setUp() {}
public function tearDown() {}
public function getMessages()
{
return $this->_messages;
......
......@@ -17,20 +17,20 @@ class Doctrine_Inheritance_SingleTable_TestCase extends Doctrine_UnitTestCase
public function testMetadataSetup()
{
$userTable = $this->conn->getMetadata('STI_User');
$superManagerTable = $this->conn->getMetadata('STI_SuperManager');
$managerTable = $this->conn->getMetadata('STI_Manager');
$customerTable = $this->conn->getMetadata('STI_Customer');
$userClass = $this->conn->getClassMetadata('STI_User');
$superManagerClass = $this->conn->getClassMetadata('STI_SuperManager');
$managerClass = $this->conn->getClassMetadata('STI_Manager');
$customerClass = $this->conn->getClassMetadata('STI_Customer');
$this->assertEqual(4, count($userTable->getFields()));
$this->assertEqual('sti_entity', $userTable->getTableName());
$this->assertEqual('sti_entity', $managerTable->getTableName());
$this->assertEqual(4, count($userClass->getMappedColumns()));
$this->assertEqual('sti_entity', $userClass->getTableName());
$this->assertEqual('sti_entity', $managerClass->getTableName());
// check inheritance map
$this->assertEqual(array(1 => 'STI_User',
2 => 'STI_Manager',
3 => 'STI_Customer',
4 => 'STI_SuperManager'), $userTable->getInheritanceOption('discriminatorMap'));
4 => 'STI_SuperManager'), $userClass->getInheritanceOption('discriminatorMap'));
//var_dump($superManagerTable->getComponentName());
}
......
......@@ -25,8 +25,8 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$userClass = $this->conn->getClassMetadata('Metadata_User');
$this->assertTrue($userClass instanceof Doctrine_ClassMetadata);
$this->assertEqual('cti_user', $userClass->getTableName());
$this->assertEqual(4, count($userClass->getFields()));
$this->assertIdentical(array(), $userClass->getOption('parents'));
$this->assertEqual(4, count($userClass->getMappedColumns()));
$this->assertIdentical(array(), $userClass->getParentClasses());
$this->assertEqual('type', $userClass->getInheritanceOption('discriminatorColumn'));
$this->assertIdentical(array(
1 => 'CTI_User',
......@@ -37,9 +37,9 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$managerClass = $this->conn->getMetadata('Metadata_Manager');
$this->assertTrue($managerClass instanceof Doctrine_ClassMetadata);
$this->assertIdentical(array('Metadata_User'), $managerClass->getOption('parents'));
$this->assertIdentical(array('Metadata_User'), $managerClass->getParentClasses());
$this->assertEqual('cti_manager', $managerClass->getTableName());
$this->assertEqual(5, count($managerClass->getFields()));
$this->assertEqual(5, count($managerClass->getMappedColumns()));
$this->assertEqual('type', $managerClass->getInheritanceOption('discriminatorColumn'));
$this->assertIdentical(array(
1 => 'CTI_User',
......@@ -50,9 +50,9 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$suManagerClass = $this->conn->getMetadata('Metadata_SuperManager');
$this->assertTrue($suManagerClass instanceof Doctrine_ClassMetadata);
$this->assertIdentical(array('Metadata_Manager', 'Metadata_User'), $suManagerClass->getOption('parents'));
$this->assertIdentical(array('Metadata_Manager', 'Metadata_User'), $suManagerClass->getParentClasses());
$this->assertEqual('cti_supermanager', $suManagerClass->getTableName());
$this->assertEqual(6, count($suManagerClass->getFields()));
$this->assertEqual(6, count($suManagerClass->getMappedColumns()));
$this->assertEqual('type', $suManagerClass->getInheritanceOption('discriminatorColumn'));
$this->assertIdentical(array(
1 => 'CTI_User',
......@@ -65,7 +65,7 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
public function testExportableFormatOfClassInClassTableInheritanceHierarchy()
{
$userClass = $this->conn->getMetadata('Metadata_User');
$userClass = $this->conn->getClassMetadata('Metadata_User');
$userClassExportableFormat = $userClass->getExportableFormat();
$this->assertEqual(4, count($userClassExportableFormat['columns']));
$this->assertTrue(isset($userClassExportableFormat['columns']['cti_id']));
......@@ -75,21 +75,21 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$this->assertTrue(isset($userClassExportableFormat['columns']['cti_name']));
$this->assertTrue(isset($userClassExportableFormat['columns']['type']));
$managerClass = $this->conn->getMetadata('Metadata_Manager');
$managerClass = $this->conn->getClassMetadata('Metadata_Manager');
$managerClassExportableFormat = $managerClass->getExportableFormat();
$this->assertEqual(2, count($managerClassExportableFormat['columns']));
$this->assertTrue(isset($managerClassExportableFormat['columns']['cti_id']));
$this->assertTrue(isset($managerClassExportableFormat['columns']['cti_id']['primary']));
$this->assertFalse(isset($managerClassExportableFormat['columns']['cti_id']['autoincrement']));
$customerClass = $this->conn->getMetadata('Metadata_Customer');
$customerClass = $this->conn->getClassMetadata('Metadata_Customer');
$customerClassExportableFormat = $customerClass->getExportableFormat();
$this->assertEqual(2, count($customerClassExportableFormat['columns']));
$this->assertTrue(isset($customerClassExportableFormat['columns']['cti_id']));
$this->assertTrue(isset($customerClassExportableFormat['columns']['cti_id']['primary']));
$this->assertFalse(isset($customerClassExportableFormat['columns']['cti_id']['autoincrement']));
$superManagerClass = $this->conn->getMetadata('Metadata_SuperManager');
$superManagerClass = $this->conn->getClassMetadata('Metadata_SuperManager');
$superManagerClassExportableFormat = $superManagerClass->getExportableFormat();
$this->assertEqual(2, count($superManagerClassExportableFormat['columns']));
$this->assertTrue(isset($superManagerClassExportableFormat['columns']['cti_id']));
......@@ -99,11 +99,11 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
public function testMetadataSetupOnSingleTableInheritanceHierarchy()
{
$userClass = $this->conn->getMetadata('Metadata_STI_User');
$userClass = $this->conn->getClassMetadata('Metadata_STI_User');
$this->assertTrue($userClass instanceof Doctrine_ClassMetadata);
$this->assertEqual('cti_user', $userClass->getTableName());
$this->assertEqual(4, count($userClass->getFields()));
$this->assertIdentical(array(), $userClass->getOption('parents'));
$this->assertEqual(4, count($userClass->getMappedColumns()));
$this->assertIdentical(array(), $userClass->getParentClasses());
$this->assertEqual('type', $userClass->getInheritanceOption('discriminatorColumn'));
$this->assertIdentical(array(
1 => 'CTI_User',
......@@ -111,11 +111,11 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
3 => 'CTI_Customer',
4 => 'CTI_SuperManager'), $userClass->getInheritanceOption('discriminatorMap'));
$managerClass = $this->conn->getMetadata('Metadata_STI_Manager');
$managerClass = $this->conn->getClassMetadata('Metadata_STI_Manager');
$this->assertTrue($managerClass instanceof Doctrine_ClassMetadata);
$this->assertIdentical(array('Metadata_STI_User'), $managerClass->getOption('parents'));
$this->assertIdentical(array('Metadata_STI_User'), $managerClass->getParentClasses());
$this->assertEqual('cti_user', $managerClass->getTableName());
$this->assertEqual(5, count($managerClass->getFields()));
$this->assertEqual(5, count($managerClass->getMappedColumns()));
$this->assertEqual('type', $managerClass->getInheritanceOption('discriminatorColumn'));
$this->assertIdentical(array(
1 => 'CTI_User',
......@@ -124,11 +124,11 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
4 => 'CTI_SuperManager'), $managerClass->getInheritanceOption('discriminatorMap'));
$suManagerClass = $this->conn->getMetadata('Metadata_STI_SuperManager');
$suManagerClass = $this->conn->getClassMetadata('Metadata_STI_SuperManager');
$this->assertTrue($suManagerClass instanceof Doctrine_ClassMetadata);
$this->assertIdentical(array('Metadata_STI_Manager', 'Metadata_STI_User'), $suManagerClass->getOption('parents'));
$this->assertIdentical(array('Metadata_STI_Manager', 'Metadata_STI_User'), $suManagerClass->getParentClasses());
$this->assertEqual('cti_user', $suManagerClass->getTableName());
$this->assertEqual(6, count($suManagerClass->getFields()));
$this->assertEqual(6, count($suManagerClass->getMappedColumns()));
$this->assertEqual('type', $suManagerClass->getInheritanceOption('discriminatorColumn'));
$this->assertIdentical(array(
1 => 'CTI_User',
......
......@@ -56,4 +56,5 @@ class Doctrine_Ticket_381_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($obj->get('name'), 'yes2');
$obj->save();
}
}
......@@ -139,6 +139,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
public function testValidate()
{
$this->manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
$user = $this->connection->getMapper('User')->find(4);
$set = array('password' => 'this is an example of too long password',
......@@ -152,11 +153,11 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($user->getModified() == $set);
$validator = new Doctrine_Validator();
$validator->validateRecord($user);
$validator->validateRecord($user);
$stack = $user->errorStack();
$this->assertTrue($stack instanceof Doctrine_Validator_ErrorStack);
$this->assertTrue(in_array('length', $stack['loginname']));
$this->assertTrue(in_array('length', $stack['password']));
......@@ -171,6 +172,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
$stack = $email->errorStack();
$this->assertTrue(in_array('unique', $stack['address']));
$this->manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_NONE);
}
/**
......
......@@ -3,7 +3,8 @@ class Email extends Doctrine_Record
{
public static function initMetadata($class)
{
$class->setColumn('address', 'string', 150, array('email', 'unique' => true));
$class->setColumn('address', 'string', 150,
array('email', 'unique' => true, 'validators' => array('email', 'unique')));
}
......
......@@ -5,7 +5,7 @@ class Entity extends Doctrine_Record
{
$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('loginname', 'string',20, array('unique' => true, 'validators' => array('unique')));
$class->setColumn('password', 'string',16);
$class->setColumn('type', 'integer');
$class->setColumn('created', 'integer',11);
......
......@@ -2,14 +2,23 @@
class ValidatorTest extends Doctrine_Record {
public static function initMetadata($class) {
$class->setColumn('mymixed', 'string', 100);
$class->setColumn('mystring', 'string', 100, array('notnull', 'unique'));
$class->setColumn('mystring', 'string', 100,
array('validators' => array('notnull', 'unique'))
);
$class->setColumn('myarray', 'array', 1000);
$class->setColumn('myobject', 'object', 1000);
$class->setColumn('myinteger', 'integer', 11);
$class->setColumn('myrange', 'integer', 11, array('range' => array(4,123)));
$class->setColumn('myregexp', 'string', 5, array('regexp' => '/^[0-9]+$/'));
$class->setColumn('myemail', 'string', 100, array('email'));
$class->setColumn('myemail2', 'string', 100, array('email', 'notblank'));
$class->setColumn('myrange', 'integer', 11,
array('validators' => array('range' => array(4,123)))
);
$class->setColumn('myregexp', 'string', 5,
array('validators' => array('regexp' => '/^[0-9]+$/'))
);
$class->setColumn('myemail', 'string', 100,
array('validators' => array('email'))
);
$class->setColumn('myemail2', 'string', 100,
array('validators' => array('email', 'notblank'))
);
}
}
......@@ -4,11 +4,16 @@ class ValidatorTest_AddressModel extends Doctrine_Record {
$class->setColumn("id", "integer", 11, array('autoincrement' => true,
'primary' => true
));
$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->setColumn('address1', 'string', 255, array('notnull' => true,
'validators' => array('notnull', 'notblank')));
$class->setColumn('address2', 'string', 255, array('notnull' => true,
'validators' => array('notnull')));
$class->setColumn('city', 'string', 255, array('notnull' => true,
'validators' => array('notnull', 'notblank')));
$class->setColumn('state', 'string', 10, array('notnull' => true,
'validators' => array('notnull', 'notblank', 'usstate')));
$class->setColumn('zip', 'string', 15, array('notnull' => true,
'validators' => array('notnull', 'notblank', 'regexp' => '/^[0-9-]*$/')));
$class->hasMany('ValidatorTest_ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ValidatorTest_ClientToAddressModel'));
}
}
<?php
class ValidatorTest_DateModel extends Doctrine_Record {
public static function initMetadata($class) {
$class->setColumn('birthday', 'date', null, array('past'));
$class->setColumn('death', 'date', null, array('future'));
$class->setColumn('birthday', 'date', null,
array('validators' => array('past')));
$class->setColumn('death', 'date', null,
array('validators' => array('future')));
}
}
<?php
class ValidatorTest_Person extends Doctrine_Record {
public static function initMetadata($class) {
$class->setColumn('identifier', 'integer', 4, array('notblank', 'unique'));
$class->setColumn('identifier', 'integer', 4,
array('validators' => array('notblank', 'unique')));
$class->setColumn('is_football_player', 'boolean');
$class->hasOne('ValidatorTest_FootballPlayer', array('local' => 'id', 'foreign' => 'person_id'));
$class->hasOne('ValidatorTest_FootballPlayer',
array('local' => 'id', 'foreign' => 'person_id'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment