Ignore:
Timestamp:
Feb 20, 2014 3:03:59 AM (10 years ago)
Author:
anonymous
Message:

Completed integrating /branches/eli_branch into /trunk. Changes include:

  • Removed closing ?> from end of files
  • Upgrade old-style contructor methods to use construct() instead.
  • Class properties and methods defined as public, private, static or protected
  • Ensure code runs under E_ALL with only mysql_* deprecated warnings
  • Search for the '@' symbol anywhere it might be used to supress runtime errors, then replace with proper error recovery.
  • Run the php cli -l option to check files for syntax errors.
  • Bring tests up-to-date with latest version and methods of PHPUnit
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/lib/FormValidator.inc.php

    r459 r468  
    5858require_once 'codebase/lib/Validator.inc.php';
    5959
    60 class FormValidator extends Validator {
     60class FormValidator {
    6161
    6262    // Class parameters.
    63     var $_params = array(
     63    private $_params = array(
    6464        'error' => ' sc-msg-error ',
    6565        'warning' => ' sc-msg-warning ',
     
    6969
    7070    // Array filling with error messages.
    71     var $errors = array();
     71    public $errors = array();
    7272
    7373    /**
     
    7777     * @param  array    $params     Array of parameters (key => val pairs).
    7878     */
    79     function setParam($params)
     79    public function setParam($params)
    8080    {
    8181        $app =& App::getInstance();
     
    9696     * @return mixed               Configured parameter value.
    9797     */
    98     function getParam($param)
     98    public function getParam($param)
    9999    {
    100100        $app =& App::getInstance();
     
    115115     *                  vals: the message to display for that error
    116116     */
    117     function getErrorList()
     117    public function getErrorList()
    118118    {
    119119        return $this->errors;
     
    130130     * @param   string $line        __LINE__.
    131131     */
    132     function addError($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
     132    public function addError($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
    133133    {
    134134        $this->errors[] = array(
     
    149149     *                a variable of $form_name, false otherwise
    150150     */
    151     function anyErrors($form_name=null)
     151    public function anyErrors($form_name=null)
    152152    {
    153153        if (isset($form_name)) {
     
    166166     * Reset the error list.
    167167     */
    168     function resetErrorList()
     168    public function resetErrorList()
    169169    {
    170170        $this->errors = array();
     
    182182     * @since   15 Jul 2005 01:39:14
    183183     */
    184     function printErrorMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg-formvalidator')
     184    public function printErrorMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg-formvalidator')
    185185    {
    186186        $app =& App::getInstance();
     
    238238     *                           not provided, use default.
    239239     */
    240     function err($form_name, $marker=null)
     240    public function err($form_name, $marker=null)
    241241    {
    242242        if (false !== ($type = $this->anyErrors($form_name))) {
     
    274274     * @return bool   true if form is not empty, false otherwise.
    275275     */
    276     function notEmpty($form_name, $msg='')
    277     {
    278         if (parent::notEmpty(getFormData($form_name))) {
     276    public function notEmpty($form_name, $msg='')
     277    {
     278        if (Validator::notEmpty(getFormData($form_name))) {
    279279            return true;
    280280        } else {
     
    290290    * @since    03 Jun 2006 22:56:46
    291291    */
    292     function isEmpty($form_name, $msg='')
     292    public function isEmpty($form_name, $msg='')
    293293    {
    294294        $this->notEmpty($form_name, $msg);
     
    303303     * @return bool   true if form is a string, false otherwise.
    304304     */
    305     function isString($form_name, $msg='')
    306     {
    307         if (parent::isString(getFormData($form_name))) {
     305    public function isString($form_name, $msg='')
     306    {
     307        if (Validator::isString(getFormData($form_name))) {
    308308            return true;
    309309        } else {
     
    321321     * @return bool   true if no errors found, false otherwise
    322322     */
    323     function isNumber($form_name, $msg='')
    324     {
    325         if (parent::isNumber(getFormData($form_name))) {
     323    public function isNumber($form_name, $msg='')
     324    {
     325        if (Validator::isNumber(getFormData($form_name))) {
    326326            return true;
    327327        } else {
     
    340340     * @return bool   true if value is an integer
    341341     */
    342     function isInteger($form_name, $msg='', $negative_ok=false)
    343     {
    344         if (parent::isInteger(getFormData($form_name), $negative_ok)) {
     342    public function isInteger($form_name, $msg='', $negative_ok=false)
     343    {
     344        if (Validator::isInteger(getFormData($form_name), $negative_ok)) {
    345345            return true;
    346346        } else {
     
    360360     * @return bool   true if value is a float
    361361     */
    362     function isFloat($form_name, $msg='', $negative_ok=false)
    363     {
    364         if (parent::isFloat(getFormData($form_name), $negative_ok)) {
     362    public function isFloat($form_name, $msg='', $negative_ok=false)
     363    {
     364        if (Validator::isFloat(getFormData($form_name), $negative_ok)) {
    365365            return true;
    366366        } else {
     
    378378     * @return bool   true if value is a float
    379379     */
    380     function isArray($form_name, $msg='')
    381     {
    382         if (parent::isArray(getFormData($form_name))) {
     380    public function isArray($form_name, $msg='')
     381    {
     382        if (Validator::isArray(getFormData($form_name))) {
    383383            return true;
    384384        } else {
     
    399399     * @return bool   true if value passes regex test
    400400     */
    401     function checkRegex($form_name, $regex, $valid_on_match, $msg='')
    402     {
    403         if (parent::checkRegex(getFormData($form_name), $regex, $valid_on_match)) {
     401    public function checkRegex($form_name, $regex, $valid_on_match=true, $msg='')
     402    {
     403        if (Validator::checkRegex(getFormData($form_name), $regex, $valid_on_match)) {
    404404            return true;
    405405        } else {
     
    419419     * @return bool   true if string length is within given boundaries
    420420     */
    421     function stringLength($form_name, $min, $max, $msg='')
    422     {
    423         if (parent::stringLength(getFormData($form_name), $min, $max)) {
     421    public function stringLength($form_name, $min, $max, $msg='')
     422    {
     423        if (Validator::stringLength(getFormData($form_name), $min, $max)) {
    424424            return true;
    425425        } else {
     
    439439     * @return bool   true if no errors found, false otherwise
    440440     */
    441     function numericRange($form_name, $min, $max, $msg='')
    442     {
    443         if (parent::numericRange(getFormData($form_name), $min, $max)) {
     441    public function numericRange($form_name, $min, $max, $msg='')
     442    {
     443        if (Validator::numericRange(getFormData($form_name), $min, $max)) {
    444444            return true;
    445445        } else {
     
    463463     * @author  Quinn Comendant <quinn@strangecode.com>
    464464     */
    465     function validateEmail($form_name)
     465    public function validateEmail($form_name, $strict=false)
    466466    {
    467467        $app =& App::getInstance();
     
    474474        }
    475475
    476         // Validator::validateEmail() returns a value that relates to the VALIDATE_EMAIL_* constants (defined in Validator.inc.php).
    477         switch (parent::validateEmail($email)) {
    478         case VALIDATE_EMAIL_REGEX_FAIL:
     476        // Validator::validateEmail() returns a value that relates to the Validate::EMAIL_* constants (defined in Validator.inc.php).
     477        switch (Validator::validateEmail($email, $strict)) {
     478        case Validator::EMAIL_REGEX_FAIL:
    479479            // Failed regex match.
    480480            $this->addError($form_name, sprintf(_("The email address <em>%s</em> is formatted incorrectly."), oTxt($email)));
    481481            $app->logMsg(sprintf('The email address %s is not valid.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
    482482            return false;
    483             break;
    484 
    485         case VALIDATE_EMAIL_LENGTH_FAIL :
     483
     484        case Validator::EMAIL_LENGTH_FAIL :
    486485            // Failed length requirements.
    487486            $this->addError($form_name, sprintf(_("The email address <em>%s</em> is too long (email addresses must have fewer than 256 characters)."), oTxt($email)));
    488487            $app->logMsg(sprintf('The email address %s must contain less than 256 characters.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
    489488            return false;
    490             break;
    491 
    492         case VALIDATE_EMAIL_MX_FAIL :
     489
     490        case Validator::EMAIL_MX_FAIL :
    493491            // Failed MX record test.
    494492            $this->addError($form_name, sprintf(_("The email address <em>%s</em> does not have a valid domain name"), oTxt($email)));
    495493            $app->logMsg(sprintf('The email address %s does not have a valid domain name.', oTxt($email)), LOG_INFO, __FILE__, __LINE__);
    496494            return false;
    497             break;
    498 
    499         case VALIDATE_EMAIL_SUCCESS :
     495
     496        case Validator::EMAIL_SUCCESS :
    500497        default :
    501498            return true;
    502             break;
    503499        }
    504500    }
     
    513509     * @return bool    true if no errors found, false otherwise
    514510     */
    515     function validatePhone($form_name)
    516     {
     511    public function validatePhone($form_name)
     512    {
     513        $app =& App::getInstance();
     514
    517515        $phone = getFormData($form_name);
    518516
    519         return (
    520             $this->checkRegex($form_name, '/^[0-9 +().-]*$/', true, sprintf(_("The phone number <em>%s</em> is not valid."), $phone))
    521             && $this->stringLength($form_name, 0, 25, sprintf(_("The phone number <em>%s</em> is too long"), $phone))
    522         );
     517        // Validator::validateEmail() returns a value that relates to the Validate::PHONE_* constants (defined in Validator.inc.php).
     518        switch (Validator::validatePhone($phone)) {
     519        case Validator::PHONE_REGEX_FAIL:
     520            // Failed regex match.
     521            $this->addError($form_name, sprintf(_("The phone number <em>%s</em> is not valid."), oTxt($phone)));
     522            $app->logMsg(sprintf('The phone number %s is not valid.', oTxt($phone)), LOG_DEBUG, __FILE__, __LINE__);
     523            return false;
     524
     525        case Validator::PHONE_LENGTH_FAIL :
     526            // Failed length requirements.
     527            $this->addError($form_name, sprintf(_("The phone number <em>%s</em> is too long (phone number must have fewer than 25 characters)."), oTxt($phone)));
     528            $app->logMsg(sprintf('The phone number %s must contain less than 256 characters.', oTxt($phone)), LOG_DEBUG, __FILE__, __LINE__);
     529            return false;
     530
     531        case Validator::PHONE_SUCCESS :
     532        default :
     533            return true;
     534        }
    523535    }
    524536
     
    531543     * @return bool    true if no errors found, false otherwise
    532544     */
    533     function validateStrDate($form_name, $msg='')
     545    public function validateStrDate($form_name, $msg='')
    534546    {
    535547        $app =& App::getInstance();
    536548
    537         if (parent::validateStrDate(getFormData($form_name, ''))) {
     549        if (Validator::validateStrDate(getFormData($form_name, ''))) {
    538550            return true;
    539551        } else {
     
    550562     *
    551563     * @param  string  $form_name   The name of the incoming form variable.
    552      * @param  string  $cc_type     Optional, card type to do specific checks. One of the CC_TYPE_* constants.
     564     * @param  string  $cc_type     Optional, card type to do specific checks. One of the Validator::CC_TYPE_* constants.
    553565     *
    554566     * @return bool    true if no errors found, false otherwise
    555567     */
    556     function validateCCNumber($form_name, $cc_type=null)
     568    public function validateCCNumber($form_name, $cc_type=null)
    557569    {
    558570        $cc_num = getFormData($form_name);
    559571
    560         if (parent::validateCCNumber($cc_num, $cc_type)) {
     572        if (Validator::validateCCNumber($cc_num, $cc_type)) {
    561573            return true;
    562574        } else {
     
    574586     * @return bool   true if no errors found, false otherwise
    575587     */
    576     function fileUploaded($form_name, $msg='')
    577     {
    578         if (parent::fileUploaded($form_name)) {
     588    public function fileUploaded($form_name, $msg='')
     589    {
     590        if (Validator::fileUploaded($form_name)) {
    579591            return true;
    580592        } else {
     
    586598} // THE END
    587599
    588 ?>
Note: See TracChangeset for help on using the changeset viewer.