Changeset 6962
- Timestamp:
- 01/06/08 05:11:43 (11 months ago)
- Files:
-
- branches/dwhittle/1.0/LICENSE (modified) (1 diff)
- branches/dwhittle/1.1/lib/form/sfForm.class.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/sql/pgsql/PgsqlDDLBuilder.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crudBrowser.class.php (modified) (11 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/task/configure (copied) (copied from branches/1.1/lib/task/configure)
- branches/dwhittle/1.1/lib/task/configure/sfConfigureDatabaseTask.class.php (copied) (copied from branches/1.1/lib/task/configure/sfConfigureDatabaseTask.class.php)
- branches/dwhittle/1.1/lib/validator/sfValidator.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/validator/sfValidatorAll.class.php (deleted)
- branches/dwhittle/1.1/lib/validator/sfValidatorAnd.class.php (copied) (copied from branches/1.1/lib/validator/sfValidatorAnd.class.php)
- branches/dwhittle/1.1/lib/validator/sfValidatorAny.class.php (deleted)
- branches/dwhittle/1.1/lib/validator/sfValidatorErrorSchema.class.php (modified) (4 diffs)
- branches/dwhittle/1.1/lib/validator/sfValidatorFromDescription.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/validator/sfValidatorOr.class.php (copied) (copied from branches/1.1/lib/validator/sfValidatorOr.class.php)
- branches/dwhittle/1.1/lib/validator/sfValidatorSchema.class.php (modified) (7 diffs)
- branches/dwhittle/1.1/lib/validator/sfValidatorSchemaCompare.class.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/validator/sfValidatorSchemaForEach.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/validator/sfValidatorUrl.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/widget/sfWidgetFormDate.class.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/widget/sfWidgetFormTime.class.php (modified) (3 diffs)
- branches/dwhittle/1.1/test/bin/prove.php (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/form/sfFormTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorAllTest.php (deleted)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorAndTest.php (copied) (copied from branches/1.1/test/unit/validator/sfValidatorAndTest.php)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorAnyTest.php (deleted)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorBooleanTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorCSRFTokenTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorCallbackTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorChoiceManyTest.php (modified) (3 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorChoiceTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorDateTest.php (modified) (6 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorDecoratorTest.php (modified) (4 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorEmailTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorErrorSchemaTest.php (modified) (4 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorFileTest.php (modified) (3 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorIntegerTest.php (modified) (5 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorNumberTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorOrTest.php (copied) (copied from branches/1.1/test/unit/validator/sfValidatorOrTest.php)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorRegexTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorSchemaCompareTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorSchemaFilterTest.php (modified) (3 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorSchemaForEachTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorSchemaTest.php (modified) (5 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorStringTest.php (modified) (3 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorUrlTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/widget/sfWidgetFormDateTest.php (modified) (4 diffs)
- branches/dwhittle/1.1/test/unit/widget/sfWidgetFormDateTimeTest.php (modified) (5 diffs)
- branches/dwhittle/1.1/test/unit/widget/sfWidgetFormTimeTest.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.0/LICENSE
r6598 r6962 1 Copyright (c) 2004-200 6Fabien Potencier1 Copyright (c) 2004-2008 Fabien Potencier 2 2 3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 3 Permission is hereby granted, free of charge, to any person obtaining a copy 4 of this software and associated documentation files (the "Software"), to deal 5 in the Software without restriction, including without limitation the rights 6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 copies of the Software, and to permit persons to whom the Software is furnished 8 to do so, subject to the following conditions: 4 9 5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 The above copyright notice and this permission notice shall be included in all 11 copies or substantial portions of the Software. 6 12 7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 THE SOFTWARE. branches/dwhittle/1.1/lib/form/sfForm.class.php
r6772 r6962 275 275 276 276 /** 277 * Sets the validators associated with this form. 278 * 279 * @param array An array of named validators 280 */ 281 public function setValidators(array $validators) 282 { 283 $this->setValidatorSchema(new sfValidatorSchema($validators)); 284 } 285 286 /** 277 287 * Sets the validator schema associated with this form. 278 288 * … … 294 304 { 295 305 return $this->validatorSchema; 306 } 307 308 /** 309 * Sets the widgets associated with this form. 310 * 311 * @param array An array of named widgets 312 */ 313 public function setWidgets(array $widgets) 314 { 315 $this->setWidgetSchema(new sfWidgetFormSchema($widgets)); 296 316 } 297 317 branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php
r6874 r6962 13 13 public function setup() 14 14 { 15 $this->setWidget Schema(new sfWidgetFormSchema(array(15 $this->setWidgets(array( 16 16 <?php foreach ($this->table->getColumns() as $column): ?> 17 17 '<?php echo strtolower($column->getColumnName()) ?>'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($column->getColumnName())) ?> => new <?php echo $this->getWidgetClassForColumn($column) ?>(<?php echo $this->getWidgetOptionsForColumn($column) ?>), … … 20 20 '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfWidgetFormSelectMany(array('choices' => new sfCallable(array($this, 'get<?php echo $tables['relatedTable']->getPhpName() ?>Choices')))), 21 21 <?php endforeach; ?> 22 )) );22 )); 23 23 24 $this->setValidator Schema(new sfValidatorSchema(array(24 $this->setValidators(array( 25 25 <?php foreach ($this->table->getColumns() as $column): ?> 26 26 '<?php echo strtolower($column->getColumnName()) ?>'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($column->getColumnName())) ?> => new <?php echo $this->getValidatorClassForColumn($column) ?>(<?php echo $this->getValidatorOptionsForColumn($column) ?>), … … 29 29 '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfValidatorChoiceMany(array('choices' => new sfCallable(array($this, 'get<?php echo $tables['relatedTable']->getPhpName() ?>IdentifierChoices')))), 30 30 <?php endforeach; ?> 31 )) );31 )); 32 32 33 33 $this->widgetSchema->setNameFormat('<?php echo $this->table->getName() ?>[%s]'); branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/sql/pgsql/PgsqlDDLBuilder.php
r6294 r6962 173 173 $colDDL = $this->getColumnDDL($col); 174 174 if ($col->isAutoIncrement() && $table->getIdMethodParameters() == null) { 175 $colDDL = str_replace($col->getType(),'serial',$colDDL); 175 if($col->getType() === PropelTypes::BIGINT) { 176 $colDDL = str_replace($col->getType(),'bigserial',$colDDL); 177 } else { 178 $colDDL = str_replace($col->getType(),'serial',$colDDL); 179 } 176 180 } 177 181 $lines[] = $colDDL; branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crudBrowser.class.php
r6884 r6962 45 45 46 46 // list page 47 $this->test()->diag('list page'); 47 48 $this-> 48 49 get('/article')-> … … 76 77 77 78 // create page 79 $this->test()->diag('create page'); 78 80 $this-> 79 81 click('Create')-> … … 96 98 97 99 // save 100 $this->test()->diag('save'); 98 101 $this->saveValues($options, array( 99 102 'title' => 'my real title', … … 106 109 107 110 // go back to the list 111 $this->test()->diag('go back to the list'); 108 112 $this-> 109 113 click('Cancel')-> … … 114 118 115 119 // edit page 120 $this->test()->diag('edit page'); 116 121 $this-> 117 122 click('3')-> … … 142 147 143 148 // save / validation 149 $this->test()->diag('save / validation'); 144 150 $values = array( 145 151 'title' => '', … … 156 162 isRequestParameter('action', in_array('non-atomic-actions', $options) ? 'edit' : 'update')-> 157 163 checkFormValues(array_merge($values, array( 158 'end_date' => array('year' => null, 'month' => 12, 'day' => 15, 'hour' => '10', 'minute' => '20')))164 'end_date' => array('year' => null, 'month' => null, 'day' => 15, 'hour' => '10', 'minute' => '20'))) 159 165 )-> 160 166 checkResponseElement('ul[class="error_list"] li:contains("Required.")', 2)-> … … 163 169 164 170 // save 171 $this->test()->diag('save'); 165 172 $this->saveValues($options, array( 166 173 'title' => 'my title', … … 173 180 174 181 // go back to the list 182 $this->test()->diag('go back to the list'); 175 183 $this-> 176 184 click('Cancel')-> … … 181 189 182 190 // delete 191 $this->test()->diag('delete'); 183 192 $this-> 184 193 get('/article/edit/id/3')-> … … 204 213 { 205 214 // show page 215 $this->test()->diag('show page'); 206 216 $this-> 207 217 get('/article/show/id/2')-> branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php
r6884 r6962 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'title' => new sfWidgetFormInput(), … … 21 21 'end_date' => new sfWidgetFormDateTime(), 22 22 'book_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getBookChoices')))), 23 )) );23 )); 24 24 25 $this->setValidator Schema(new sfValidatorSchema(array(25 $this->setValidators(array( 26 26 'id' => new sfValidatorInteger(array('required' => false)), 27 27 'title' => new sfValidatorString(), … … 32 32 'end_date' => new sfValidatorDateTime(array('required' => false)), 33 33 'book_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getBookIdentifierChoices')), 'required' => false)), 34 )) );34 )); 35 35 36 36 $this->widgetSchema->setNameFormat('article[%s]'); branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php
r6884 r6962 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'author_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getAuthorChoices')))), 16 16 'article_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getArticleChoices')))), 17 17 'id' => new sfWidgetFormInputHidden(), 18 )) );18 )); 19 19 20 $this->setValidator Schema(new sfValidatorSchema(array(20 $this->setValidators(array( 21 21 'author_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getAuthorIdentifierChoices')), 'required' => false)), 22 22 'article_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getArticleIdentifierChoices')), 'required' => false)), 23 23 'id' => new sfValidatorInteger(array('required' => false)), 24 )) );24 )); 25 25 26 26 $this->widgetSchema->setNameFormat('author_article[%s]'); branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php
r6884 r6962 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'name' => new sfWidgetFormInput(), 17 )) );17 )); 18 18 19 $this->setValidator Schema(new sfValidatorSchema(array(19 $this->setValidators(array( 20 20 'id' => new sfValidatorInteger(array('required' => false)), 21 21 'name' => new sfValidatorString(array('required' => false)), 22 )) );22 )); 23 23 24 24 $this->widgetSchema->setNameFormat('author[%s]'); branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php
r6884 r6962 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'name' => new sfWidgetFormInput(), 17 )) );17 )); 18 18 19 $this->setValidator Schema(new sfValidatorSchema(array(19 $this->setValidators(array( 20 20 'id' => new sfValidatorInteger(array('required' => false)), 21 21 'name' => new sfValidatorString(array('required' => false)), 22 )) );22 )); 23 23 24 24 $this->widgetSchema->setNameFormat('book[%s]'); branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php
r6884 r6962 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'name' => new sfWidgetFormInput(), 17 )) );17 )); 18 18 19 $this->setValidator Schema(new sfValidatorSchema(array(19 $this->setValidators(array( 20 20 'id' => new sfValidatorInteger(array('required' => false)), 21 21 'name' => new sfValidatorString(array('required' => false)), 22 )) );22 )); 23 23 24 24 $this->widgetSchema->setNameFormat('category[%s]'); branches/dwhittle/1.1/lib/validator/sfValidator.class.php
r6198 r6962 296 296 * @throws sfValidatorError 297 297 */ 298 abstract protected function doClean($value);298 abstract protected function doClean($value); 299 299 300 300 /** branches/dwhittle/1.1/lib/validator/sfValidatorErrorSchema.class.php
r6198 r6962 46 46 * Adds an error. 47 47 * 48 * This method merges sfValidatorErrorSchema errors with the current instance. 49 * 48 50 * @param sfValidatorError A sfValidatorError instance 49 51 * @param string The error name … … 51 53 public function addError(sfValidatorError $error, $name = null) 52 54 { 53 if (is_null($name) )55 if (is_null($name) || is_integer($name)) 54 56 { 57 if ($error instanceof sfValidatorErrorSchema) 58 { 59 throw new LogicException('Unable to merge a sfValidatorErrorSchema to global errors.'); 60 } 61 55 62 $this->globalErrors[] = $error; 56 63 $this->errors[] = $error; 57 64 } 58 else if (is_integer($name))59 {60 $this->namedErrors[$name] = $error;61 $this->errors[$name] = $error;62 }63 65 else 64 66 { 65 $this->namedErrors[$name] = $error; 66 $this->errors[$name] = $error; 67 if (!isset($this->namedErrors[$name]) && !$error instanceof sfValidatorErrorSchema) 68 { 69 $this->namedErrors[$name] = $error; 70 $this->errors[$name] = $error; 71 } 72 else 73 { 74 if (!isset($this->namedErrors[$name])) 75 { 76 $this->namedErrors[$name] = new sfValidatorErrorSchema($error->getValidator()); 77 $this->errors[$name] = new sfValidatorErrorSchema($error->getValidator()); 78 } 79 else if (!$this->namedErrors[$name] instanceof sfValidatorErrorSchema) 80 { 81 $current = $this->namedErrors[$name]; 82 $this->namedErrors[$name] = new sfValidatorErrorSchema($current->getValidator()); 83 $this->errors[$name] = new sfValidatorErrorSchema($current->getValidator()); 84 85 $method = $current instanceof sfValidatorErrorSchema ? 'addErrors' : 'addError'; 86 $this->namedErrors[$name]->$method($current); 87 $this->errors[$name]->$method($current); 88 } 89 90 $method = $error instanceof sfValidatorErrorSchema ? 'addErrors' : 'addError'; 91 $this->namedErrors[$name]->$method($error); 92 $this->errors[$name]->$method($error); 93 } 67 94 } 68 95 … … 249 276 protected function updateCode() 250 277 { 251 $this->code = implode( " ", array_merge(278 $this->code = implode(' ', array_merge( 252 279 array_map(create_function('$e', 'return $e->getCode();'), $this->globalErrors), 253 280 array_map(create_function('$n,$e', 'return $n.\' [\'.$e->getCode().\']\';'), array_keys($this->namedErrors), array_values($this->namedErrors)) … … 260 287 protected function updateMessage() 261 288 { 262 $this->message = implode( " ", array_merge(289 $this->message = implode(' ', array_merge( 263 290 array_map(create_function('$e', 'return $e->getMessage();'), $this->globalErrors), 264 291 array_map(create_function('$n,$e', 'return $n.\' [\'.$e->getMessage().\']\';'), array_keys($this->namedErrors), array_values($this->namedErrors)) branches/dwhittle/1.1/lib/validator/sfValidatorFromDescription.class.php
r6198 r6962 340 340 $this->operator = $operator; 341 341 $this->arguments = $arguments; 342 $this->class = 'or' == $operator ? 'sfValidator Any' : 'sfValidatorAll';342 $this->class = 'or' == $operator ? 'sfValidatorOr' : 'sfValidatorAnd'; 343 343 } 344 344 branches/dwhittle/1.1/lib/validator/sfValidatorSchema.class.php
r6198 r6962 22 22 { 23 23 protected 24 $fields = array(); 24 $fields = array(), 25 $preValidator = null, 26 $postValidator = null; 25 27 26 28 /** … … 72 74 * @see sfValidator 73 75 */ 74 p ublicfunction configure($options = array(), $messages = array())76 protected function configure($options = array(), $messages = array()) 75 77 { 76 78 $this->addOption('allow_extra_fields', false); … … 103 105 } 104 106 105 $clean = array();107 $clean = array(); 106 108 $unused = array_keys($this->fields); 107 $error s = array();109 $errorSchema = new sfValidatorErrorSchema($this); 108 110 109 111 // pre validator 110 if (isset($this->fields['_pre_validator'])) 111 { 112 try 113 { 114 $this->fields['_pre_validator']->clean($values); 115 } 116 catch (sfValidatorError $e) 117 { 118 $errors[] = $e; 119 } 112 try 113 { 114 $this->preClean($values); 115 } 116 catch (sfValidatorErrorSchema $e) 117 { 118 $errorSchema->addErrors($e); 119 } 120 catch (sfValidatorError $e) 121 { 122 $errorSchema->addError($e); 120 123 } 121 124 … … 128 131 if (!$this->options['allow_extra_fields']) 129 132 { 130 $error s[] = new sfValidatorError($this, 'extra_fields', array('field' => $name));133 $errorSchema->addError(new sfValidatorError($this, 'extra_fields', array('field' => $name))); 131 134 } 132 135 else if (!$this->options['filter_extra_fields']) … … 149 152 $clean[$name] = null; 150 153 151 $error s[$name] = $e;154 $errorSchema->addError($e, (string) $name); 152 155 } 153 156 } … … 156 159 foreach ($unused as $name) 157 160 { 158 if (in_array($name, array('_pre_validator', '_post_validator')))159 {160 continue;161 }162 163 161 // validate value 164 162 try … … 168 166 catch (sfValidatorError $e) 169 167 { 170 $error s[$name] = $e;168 $errorSchema->addError($e, (string) $name); 171 169 } 172 170 } 173 171 174 172 // post validator 175 if (isset($this->fields['_post_validator'])) 176 { 177 try 178 { 179 $clean = $this->fields['_post_validator']->clean($clean); 180 } 181 catch (sfValidatorError $e) 182 { 183 $errors[] = $e; 184 } 185 } 186 187 if (count($errors)) 188 { 189 throw new sfValidatorErrorSchema($this, $errors); 173 try 174 { 175 $clean = $this->postClean($clean); 176 } 177 catch (sfValidatorErrorSchema $e) 178 { 179 $errorSchema->addErrors($e); 180 } 181 catch (sfValidatorError $e) 182 { 183 $errorSchema->addError($e); 184 } 185 186 if (count($errorSchema)) 187 { 188 throw $errorSchema; 190 189 } 191 190 192 191 return $clean; 192 } 193 194 /** 195 * Cleans the input values. 196 * 197 * This method is the first validator executed by doClean(). 198 * 199 * It executes the validator returned by getPreValidator() 200 * on the global array of values. 201 * 202 * @param array The input values 203 * 204 * @throws sfValidatorError 205 */ 206 public function preClean($values) 207 { 208 if (is_null($validator = $this->getPreValidator())) 209 { 210 return; 211 } 212 213 $validator->clean($values); 214 } 215 216 /** 217 * Cleans the input values. 218 * 219 * This method is the last validator executed by doClean(). 220 * 221 * It executes the validator returned by getPostValidator() 222 * on the global array of cleaned values. 223 * 224 * @param array The input values 225 * 226 * @throws sfValidatorError 227 */ 228 public function postClean($values) 229 { 230 if (is_null($validator = $this->getPostValidator())) 231 { 232 return $values; 233 } 234 235 return $validator->clean($values); 236 } 237 238 /** 239 * Sets the pre validator. 240 * 241 * @param sfValidator A sfValidator instance 242 */ 243 public function setPreValidator(sfValidator $validator) 244 { 245 $this->preValidator = $validator; 246 } 247 248 /** 249 * Returns the pre validator. 250 * 251 * @return sfValidator A sfValidator instance 252 */ 253 public function getPreValidator() 254 { 255 return $this->preValidator; 256 } 257 258 /** 259 * Sets the post validator. 260 * 261 * @param sfValidator A sfValidator instance 262 */ 263 public function setPostValidator(sfValidator $validator) 264 { 265 $this->postValidator = $validator; 266 } 267 268 /** 269 * Returns the post validator. 270 * 271 * @return sfValidator A sfValidator instance 272 */ 273 public function getPostValidator() 274 { 275 return $this->postValidator; 193 276 } 194 277 branches/dwhittle/1.1/lib/validator/sfValidatorSchemaCompare.class.php
r6198 r6962 29 29 * Constructor. 30 30 * 31 * Available op erator:31 * Available options: 32 32 * 33 * * self::EQUAL 34 * * self::NOT_EQUAL 35 * * self::LESS_THAN 36 * * self::LESS_THAN_EQUAL 37 * * self::GREATER_THAN 38 * * self::GREATER_THAN_EQUAL 33 * * left_field: The left field name 34 * * operator: The comparison operator 35 * * self::EQUAL 36 * * self::NOT_EQUAL 37 * * self::LESS_THAN 38 * * self::LESS_THAN_EQUAL 39 * * self::GREATER_THAN 40 * * self::GREATER_THAN_EQUAL 41 * * right_field: The right field name 42 * * throw_global_error: Whether to throw a global error (false by default) or an error tied to the left field 39 43 * 40 44 * @param string The left field name … … 51 55 $this->addOption('operator', $operator); 52 56 $this->addOption('right_field', $rightField); 57 58 $this->addOption('throw_global_error', false); 53 59 54 60 parent::__construct(null, $options, $messages); … … 97 103 if (!$valid) 98 104 { 99 thrownew sfValidatorError($this, 'invalid', array(105 $error = new sfValidatorError($this, 'invalid', array( 100 106 'left_field' => $leftValue, 101 107 'right_field' => $rightValue, 102 108 'operator' => $this->getOption('operator'), 103 109 )); 110 if ($this->getOption('throw_global_error')) 111 { 112 throw $error; 113 } 114 115 throw new sfValidatorErrorSchema($this, array($this->getOption('left_field') => $error)); 104 116 } 105 117 branches/dwhittle/1.1/lib/validator/sfValidatorSchemaForEach.class.php
r6198 r6962 10 10 11 11 /** 12 * 12 * sfValidatorSchemaForEach wraps a validator multiple times in a single validator. 13 13 * 14 14 * @package symfony branches/dwhittle/1.1/lib/validator/sfValidatorUrl.class.php
r5895 r6962 22 22 * @see sfValidatorRegex 23 23 */ 24 p ublicfunction configure($options = array(), $messages = array())24 protected function configure($options = array(), $messages = array()) 25 25 { 26 26 parent::configure($options, $messages); branches/dwhittle/1.1/lib/widget/sfWidgetFormDate.class.php
r6419 r6962 50 50 public function render($name, $value = null, $attributes = array(), $errors = array()) 51 51 { 52 // convert value to a timestamp 52 // convert value to an array 53 $default = array('year' => null, 'month' => null, 'day' => null); 53 54 if (is_array($value)) 54 55 { 55 $value = $this->convertDateArrayToTimestamp($value);56 $value = array_merge($default, $value); 56 57 } 57 58 else 58 59 { 59 60 $value = ctype_digit($value) ? (integer) $value : strtotime($value); 61 if (false === $value) 62 { 63 $value = $default; 64 } 65 else 66 { 67 $value = array('year' => date('Y', $value), 'month' => date('n', $value), 'day' => date('j', $value)); 68 } 60 69 } 61 70 … … 65 74 // days 66 75 $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days'))); 67 $date['%day%'] = $widget->render($name.'[day]', $value ? date('j', $value) : '');76 $date['%day%'] = $widget->render($name.'[day]', $value['day']); 68 77 69 78 // months 70 79 $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months'))); 71 $date['%month%'] = $widget->render($name.'[month]', $value ? date('n', $value) : '');80 $date['%month%'] = $widget->render($name.'[month]', $value['month']); 72 81 73 82 // years 74 83 $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years'))); 75 $date['%year%'] = $widget->render($name.'[year]', $value ? date('Y', $value) : '');84 $date['%year%'] = $widget->render($name.'[year]', $value['year']); 76 85 77 86 return strtr($this->getOption('format'), $date); 78 87 } 79 80 /**81 * Converts an array representing a date to a timestamp.82 *83 * The array can contains the following keys: year, month, day, hour, minute, second84 *85 * @param array An array of date elements86 *87 * @return integer A timestamp88 */89 protected function convertDateArrayToTimestamp($value)90 {91 $clean = mktime(isset($value['hour']) ? $value['hour'] : 0, isset($value['minute']) ? $value['minute'] : 0, isset($value['second']) ? $value['second'] : 0, $value['month'], $value['day'], $value['year']);92 93 return false === $clean ? null : $clean;94 }95 88 } branches/dwhittle/1.1/lib/widget/sfWidgetFormTime.class.php
r6419 r6962 53 53 public function render($name, $value = null, $attributes = array(), $errors = array()) 54 54 { 55 // convert value to a timestamp 55 // convert value to an array 56 $default = array('hour' => null, 'minute' => null, 'second' => null); 56 57 if (is_array($value)) 57 58 { 58 $value = $this->convertDateArrayToTimestamp($value);59 $value = array_merge($default, $value); 59 60 } 60 61 else 61 62 { 62 63 $value = ctype_digit($value) ? (integer) $value : strtotime($value); 64 if (false === $value) 65 { 66 $value = $default; 67 } 68 else 69 { 70 $value = array('hour' => date('G', $value), 'minute' => date('i', $value), 'second' => date('s', $value)); 71 } 63 72 } 64 73 … … 68 77 // hours 69 78 $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['hour']) + $this->getOption('hours') : $this->getOption('hours'))); 70 $time['%hour%'] = $widget->render($name.'[hour]', $value ? date('G', $value) : '');79 $time['%hour%'] = $widget->render($name.'[hour]', $value['hour']); 71 80 72 81 // minutes 73 82 $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['minute']) + $this->getOption('minutes') : $this->getOption('minutes'))); 74 $time['%minute%'] = $widget->render($name.'[