Ignore:
Timestamp:
Dec 13, 2013 11:24:08 PM (11 years ago)
Author:
anonymous
Message:

Changed some global constants to class constants (in cases where backwards compatability wouldn't break).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eli_branch/lib/Validator.inc.php

    r439 r447  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2424 * Validator.inc.php
    2525 *
    26  * The Validator class provides a methods for validating input against different criteria. 
     26 * The Validator class provides a methods for validating input against different criteria.
    2727 * All functions return true if the input passes the test.
    2828 *
     
    3131 */
    3232
    33 // Known credit card types.
    34 define('CC_TYPE_VISA', 1);
    35 define('CC_TYPE_MASTERCARD', 2);
    36 define('CC_TYPE_AMEX', 3);
    37 define('CC_TYPE_DISCOVER', 4);
    38 define('CC_TYPE_DINERS', 5);
    39 define('CC_TYPE_JCB', 6);
    40 
    41 // validateEmail return types.
    42 define('VALIDATE_EMAIL_SUCCESS', 0);
    43 define('VALIDATE_EMAIL_REGEX_FAIL', 1);
    44 define('VALIDATE_EMAIL_LENGTH_FAIL', 2);
    45 define('VALIDATE_EMAIL_MX_FAIL', 3);
    46 
    4733class Validator {
     34
     35    // Known credit card types.
     36    const CC_TYPE_VISA = 1;
     37    const CC_TYPE_MASTERCARD = 2;
     38    const CC_TYPE_AMEX = 3;
     39    const CC_TYPE_DISCOVER = 4;
     40    const CC_TYPE_DINERS = 5;
     41    const CC_TYPE_JCB = 6;
     42
     43    // Validator::validateEmail() return types.
     44    const EMAIL_SUCCESS = 0;
     45    const EMAIL_REGEX_FAIL = 1;
     46    const EMAIL_LENGTH_FAIL = 2;
     47    const EMAIL_MX_FAIL = 3;
    4848
    4949    /**
     
    180180     * @access  public
    181181     * @param   string  $val    The input data to validate..
    182      * @return  const           One of the constant values: VALIDATE_EMAIL_SUCCESS|VALIDATE_EMAIL_REGEX_FAIL|VALIDATE_EMAIL_LENGTH_FAIL|VALIDATE_EMAIL_MX_FAIL
     182     * @return  const           One of the constant values: Validate::EMAIL_SUCCESS|Validate::EMAIL_REGEX_FAIL|Validate::EMAIL_LENGTH_FAIL|Validate::EMAIL_MX_FAIL
    183183     * @author  Quinn Comendant <quinn@strangecode.com>
    184184     */
     
    190190        // Test email address format.
    191191        if (!preg_match($e->getParam('regex'), $val, $e_parts)) {
    192             return VALIDATE_EMAIL_REGEX_FAIL;
    193         }
    194        
     192            return self::EMAIL_REGEX_FAIL;
     193        }
     194
    195195        // We have a match! Here are the captured subpatterns, on which further tests are run.
    196         // The part before the @. 
     196        // The part before the @.
    197197        $local = $e_parts[2];
    198198
    199         // The part after the @. 
     199        // The part after the @.
    200200        // If domain is an IP [XXX.XXX.XXX.XXX] strip off the brackets.
    201201        $domain = $e_parts[3]{0} == '[' ? mb_substr($e_parts[3], 1, -1) : $e_parts[3];
     
    203203        // Test length.
    204204        if (mb_strlen($local) > 64 || mb_strlen($domain) > 191) {
    205             return VALIDATE_EMAIL_LENGTH_FAIL;
     205            return self::EMAIL_LENGTH_FAIL;
    206206        }
    207207
     
    210210        if ((ip2long($domain) == '-1' || ip2long($domain) === false) && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) {
    211211            // FIXME: Do we care?
    212             // return VALIDATE_EMAIL_MX_FAIL;
    213         }
    214 
    215         return VALIDATE_EMAIL_SUCCESS;
     212            // return self::EMAIL_MX_FAIL;
     213        }
     214
     215        return self::EMAIL_SUCCESS;
    216216    }
    217217
     
    225225    {
    226226        $app =& App::getInstance();
    227        
     227
    228228        if ('' == trim($val)) {
    229229            // Don't be too bothered about empty strings.
     
    257257         // Perform card-specific checks, if applicable
    258258         switch ($cc_type) {
    259              case CC_TYPE_VISA :
     259             case self::CC_TYPE_VISA :
    260260                 $regex = '/^4\d{15}$|^4\d{12}$/';
    261261                 break;
    262              case CC_TYPE_MASTERCARD :
     262             case self::CC_TYPE_MASTERCARD :
    263263                 $regex = '/^5[1-5]\d{14}$/';
    264264                 break;
    265              case CC_TYPE_AMEX :
     265             case self::CC_TYPE_AMEX :
    266266                 $regex = '/^3[47]\d{13}$/';
    267267                 break;
    268              case CC_TYPE_DISCOVER :
     268             case self::CC_TYPE_DISCOVER :
    269269                 $regex = '/^6011\d{12}$/';
    270270                 break;
    271              case CC_TYPE_DINERS :
     271             case self::CC_TYPE_DINERS :
    272272                 $regex = '/^30[0-5]\d{11}$|^3[68]\d{12}$/';
    273273                 break;
    274              case CC_TYPE_JCB :
     274             case self::CC_TYPE_JCB :
    275275                 $regex = '/^3\d{15}$|^2131|1800\d{11}$/';
    276276                 break;
     
    279279                 break;
    280280         }
    281          
     281
    282282         if ('' != $regex && !preg_match($regex, $cc_num)) {
    283283             // Invalid format.
     
    324324            return false;
    325325        }
    326        
     326
    327327        if (is_array($_FILES[$form_name]['name'])) {
    328328            foreach($_FILES[$form_name]['name'] as $f) {
     
    336336            }
    337337        }
    338        
     338
    339339        return true;
    340340    }
Note: See TracChangeset for help on using the changeset viewer.