- Timestamp:
- 09/18/09 00:50:58 (10 months ago)
- Files:
-
- fActiveRecord.php (modified) (3 diffs)
- fEmail.php (modified) (2 diffs)
- fValidation.php (modified) (3 diffs)
- fValidationException.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fActiveRecord.php
r700 r701 Hide Line Numbers 16 16 * @link http://flourishlib.com/fActiveRecord 17 17 * 18 * @version 1.0.0b43 18 * @version 1.0.0b44 19 * @changes 1.0.0b44 Updated code for new fValidationException API [wb, 2009-09-18] 19 20 * @changes 1.0.0b43 Updated code for new fRecordSet API [wb, 2009-09-16] 20 21 * @changes 1.0.0b42 Corrected a grammar bug in ::hash() [wb, 2009-09-09] … … 1132 1133 if ($restriction_messages) { 1133 1134 throw new fValidationException( 1134 sprintf( 1135 "<p>%1\$s</p>\n<ul>\n<li>%2\$s</li>\n</ul>", 1136 self::compose('This %s can not be deleted because:', fORM::getRecordName($class)), 1137 join("</li>\n<li>", $restriction_messages) 1138 ) 1135 self::compose('This %s can not be deleted because:', fORM::getRecordName($class)), 1136 $restriction_messages 1139 1137 ); 1140 1138 } … … 2419 2417 if (!empty($validation_messages)) { 2420 2418 throw new fValidationException( 2421 sprintf( 2422 "<p>%1\$s</p>\n<ul>\n<li>%2\$s</li>\n</ul>", 2423 self::compose("The following problems were found:"), 2424 join("</li>\n<li>", $validation_messages) 2425 ) 2419 'The following problems were found:', 2420 $validation_messages 2426 2421 ); 2427 2422 } fEmail.php
r609 r701 Hide Line Numbers 17 17 * @link http://flourishlib.com/fEmail 18 18 * 19 * @version 1.0.0b10 19 * @version 1.0.0b11 20 * @changes 1.0.0b11 Updated to use the new fValidationException API [wb, 2009-09-17] 20 21 * @changes 1.0.0b10 Fixed a bug with sending both an HTML and a plaintext body [bb-imarc, 2009-06-18] 21 22 * @changes 1.0.0b9 Fixed a bug where the MIME headers were not being set for all emails [wb, 2009-06-12] … … 1299 1300 if ($validation_messages) { 1300 1301 throw new fValidationException( 1301 sprintf( 1302 "<p>%1\$s</p>\n<ul>\n<li>%2\$s</li>\n</ul>", 1303 self::compose("The email could not be sent because:"), 1304 join("</li>\n<li>", $validation_messages) 1305 ) 1302 'The email could not be sent because:', 1303 $validation_messages 1306 1304 ); 1307 1305 } fValidation.php
r670 r701 Hide Line Numbers 10 10 * @link http://flourishlib.com/fValidation 11 11 * 12 * @version 1.0.0b4 12 * @version 1.0.0b5 13 * @changes 1.0.0b5 Added the `$return_messages` parameter to ::validate() and updated code for new fValidationException API [wb, 2009-09-17] 13 14 * @changes 1.0.0b4 Changed date checking from `strtotime()` to fTimestamp for better localization support [wb, 2009-06-01] 14 15 * @changes 1.0.0b3 Updated for new fCore API [wb, 2009-02-16] … … 420 421 * @throws fValidationException When one of the options set for the object is violated 421 422 * 422 * @return void 423 */ 424 public function validate() 423 * @param boolean $return_messages If an array of validation messages should be returned instead of an exception being thrown 424 * @return void|array If $return_messages is TRUE, an array of validation messages will be returned 425 */ 426 public function validate($return_messages=FALSE) 425 427 { 426 428 if (!$this->email_header_fields && … … 442 444 $this->checkURLFields($messages); 443 445 446 if ($return_messages) { 447 return $messages; 448 } 449 444 450 if ($messages) { 445 451 throw new fValidationException( 446 sprintf( 447 "<p>%1\$s</p>\n<ul>\n<li>%2\$s</li>\n</ul>", 448 self::compose("The following problems were found:"), 449 join("</li>\n<li>", $messages) 450 ) 452 'The following problems were found:', 453 $messages 451 454 ); 452 455 } fValidationException.php
r598 r701 Hide Line Numbers 10 10 * @link http://flourishlib.com/fValidationException 11 11 * 12 * @version 1.0.0b 13 * @changes 1.0.0b The initial implementation [wb, 2007-06-14] 12 * @version 1.0.0b2 13 * @changes 1.0.0b2 Added a custom ::__construct() to handle arrays of messages [wb, 2009-09-17] 14 * @changes 1.0.0b The initial implementation [wb, 2007-06-14] 14 15 */ 15 16 class fValidationException extends fExpectedException … … 59 60 self::$field_format = $format; 60 61 } 62 63 64 /** 65 * Sets the message for the exception, allowing for custom formatting beyond fException 66 * 67 * If this method receives exactly two parameters, a string and an array, 68 * the string will be used as a message in a HTML `<p>` tag and the array 69 * will be turned into an unorder list `<ul>` tag with each element in the 70 * array being an `<li>` tag. It is possible to pass an optional exception 71 * code as a third parameter. 72 * 73 * The following PHP: 74 * 75 * {{{ 76 * #!php 77 * throw new fValidationException( 78 * 'The following problems were found:', 79 * array( 80 * 'Please provide your name', 81 * 'Please provide your email address' 82 * ) 83 * ); 84 * }}} 85 * 86 * Would create the message: 87 * 88 * {{{ 89 * #!text/html 90 * <p>The following problems were found:</p> 91 * <ul> 92 * <li>Please provide your name</li> 93 * <li>Please provide your email address</li> 94 * </ul> 95 * }}} 96 * 97 * If the parameters are anything else, they will be passed to 98 * fException::__construct(). 99 * 100 * @param string $message The beginning message for the exception. This will be placed in a `<p>` tag. 101 * @param array $sub_messages An array of strings to place in a `<ul>` tag 102 * @param mixed $code The optional exception code 103 * @return fException 104 */ 105 public function __construct($message='') 106 { 107 $params = func_get_args(); 108 109 if ((count($params) == 2 || count($params) == 3) && is_string($params[0]) && is_array($params[1])) { 110 $message = sprintf( 111 "<p>%1\$s</p>\n<ul>\n<li>%2\$s</li>\n</ul>", 112 self::compose($params[0]), 113 join("</li>\n<li>", $params[1]) 114 ); 115 $params = array_merge( 116 // This escapes % signs since fException is going to look for sprintf formatting codes 117 array(str_replace('%', '%%', $message)), 118 // This grabs the exception code if one is defined 119 array_slice($params, 2) 120 ); 121 } 122 123 call_user_func_array( 124 array($this, 'fException::__construct'), 125 $params 126 ); 127 } 61 128 } 62 129
