MediaWiki fundraising/REL1_35
|
DataValidator This class is responsible for performing all kinds of data validation, wherever we may need it. More...
Static Public Member Functions | |
static | cc_number_exists_in_str (string $str) |
Analyzes a string to see if any credit card numbers are hiding out in it. | |
static | expandIPBlockToArray ( $ip) |
Takes either an IP address, or an IP address with a CIDR block, and expands it to an array containing all the relevant addresses so we can do things like save the expanded list to memcache, and use in_array(). | |
static | getCardType ( $card_num) |
Calculates and returns the card type for a given credit card number. | |
static | getEmptyErrorArray () |
getEmptyErrorArray | |
static | getError ( $field, $type) |
getError - returns the error object appropriate for a validation error on the specified field, of the specified type. | |
static | getErrorToken ( $field) |
getErrorToken, intended to be used by classes that exist relatively close to the form classes, returns the error token (defined on the forms) that specifies where the error will appear within the form output. | |
static | getZeroPaddedValue ( $value, $total_length) |
Okay, so this isn't all validation, but there's a validation component in there so I'm calling it close enough. | |
static | guessLanguage ( $data) |
Returns a valid mediawiki language code to use for all the DonationInterface translations. | |
static | ip_is_listed ( $ip, $ip_list) |
Check whether IP matches a block list. | |
static | luhn_check ( $str) |
Performs a Luhn algorithm check on a string. | |
static | obviousXssInString ( $value) |
static | special_characters_in_wrong_locations ( $str) |
Analyzes a string to see if there are special characters at the beginning/end of a string or right before the @symbol. | |
static | validate (GatewayType $gateway, $data, $check_not_empty=[]) |
validate Run all the validation rules we have defined against a (hopefully normalized) DonationInterface data set. | |
static | validate_address ( $value) |
Gets rid of numbers that pass luhn in address fields -. | |
static | validate_name ( $value) |
Some people are silly and enter their CC numbers as their name. | |
static | validate_not_just_punctuation ( $value) |
Validates that somebody didn't just punch in a bunch of punctuation, and nothing else. | |
static | value_appears_in ( $needle, $haystack) |
Test to determine if a value appears in a haystack. | |
Static Protected Member Functions | |
static | checkValidationPassed ( $fields, $results) |
checkValidationPassed is a validate helper function. | |
static | validate_alphanumeric ( $value) |
validate_alphanumeric Checks to make sure the value is populated with an alphanumeric value... ...which would be great, if it made sense at all. | |
static | validate_boolean ( $value) |
validate_boolean Determines if the $value passed in is a valid boolean. | |
static | validate_credit_card ( $value) |
validate_credit_card Determines if the $value passed in is (possibly) a valid credit card number. | |
static | validate_currency_code ( $value, $acceptedCurrencies) |
static | validate_email ( $value) |
validate_email Determines if the $value passed in is a valid email address. | |
static | validate_gateway ( $value) |
validate_gateway Checks to make sure the gateway is populated with a valid and enabled gateway. | |
static | validate_not_empty ( $value) |
validate_not_empty Checks to make sure that the $value is present in the $data array, and not null or an empty string. | |
static | validate_numeric ( $value) |
validate_numeric Determines if the $value passed in is numeric. | |
DataValidator This class is responsible for performing all kinds of data validation, wherever we may need it.
All functions should be static, so we don't have to construct anything in order to use it any/everywhere.
Definition at line 16 of file DataValidator.php.
|
static |
Analyzes a string to see if any credit card numbers are hiding out in it.
string | $str |
Definition at line 450 of file DataValidator.php.
Referenced by EmployerFieldValidation\validate(), validate_address(), validate_email(), validate_name(), and WmfFramework_Drupal\validateEmail().
|
staticprotected |
checkValidationPassed is a validate helper function.
In order to determine that we are ready to do the third stage of data validation (calculated) for any given field, we need to determine that all fields required to validate the original have, themselves, passed validation.
array | $fields | An array of field names to check. |
array | $results | Intermediate result of validation. |
Definition at line 255 of file DataValidator.php.
|
static |
Takes either an IP address, or an IP address with a CIDR block, and expands it to an array containing all the relevant addresses so we can do things like save the expanded list to memcache, and use in_array().
string | $ip | Either a single address, or a block. |
Definition at line 579 of file DataValidator.php.
|
static |
Calculates and returns the card type for a given credit card number.
int | $card_num | A credit card number. |
Definition at line 539 of file DataValidator.php.
Referenced by validate_credit_card().
|
static |
getEmptyErrorArray
Definition at line 60 of file DataValidator.php.
|
static |
getError - returns the error object appropriate for a validation error on the specified field, of the specified type.
string | $field | - The common name of the field containing the data that is causing the error. |
string | $type | - The type of error being caused, from a set. Possible values are: 'not_empty' - the value is required and not currently present 'valid_type' - in general, the wrong format 'calculated' - fields that failed some kind of multiple-field data integrity check. |
Definition at line 93 of file DataValidator.php.
References $type, and getErrorToken().
Referenced by FiscalNumber\getError(), Amount\validate(), validate(), and EmployerFieldValidation\validate().
|
static |
getErrorToken, intended to be used by classes that exist relatively close to the form classes, returns the error token (defined on the forms) that specifies where the error will appear within the form output.
string | $field | The field that ostensibly has an error that needs to be displayed to the user. |
Definition at line 26 of file DataValidator.php.
Referenced by getError(), and validate().
|
static |
Okay, so this isn't all validation, but there's a validation component in there so I'm calling it close enough.
string | $value | the value that should be zero-padded out to $total_length |
int | $total_length | The fixed number of characters that $value should be padded out to |
Definition at line 676 of file DataValidator.php.
Referenced by IngenicoFinancialNumber\stage().
|
static |
Returns a valid mediawiki language code to use for all the DonationInterface translations.
Will only look at the currently configured language if the 'language' key doesn't exist in the data set: Users may not have a language preference set if we're bouncing between mediawiki instances for payments.
array | $data | A normalized DonationInterface data set. |
Definition at line 563 of file DataValidator.php.
|
static |
Check whether IP matches a block list.
TODO: We might want to store the expanded list in memcache.
Definition at line 606 of file DataValidator.php.
Referenced by Gateway_Extras_CustomFilters_IP_Velocity\filter(), and Gateway_Extras_SessionVelocityFilter\filter().
|
static |
Performs a Luhn algorithm check on a string.
string | $str |
Definition at line 513 of file DataValidator.php.
|
static |
Definition at line 414 of file DataValidator.php.
Referenced by validate_address(), and validate_name().
|
static |
Analyzes a string to see if there are special characters at the beginning/end of a string or right before the @symbol.
string | $str |
Definition at line 427 of file DataValidator.php.
Referenced by validate_email().
|
static |
validate Run all the validation rules we have defined against a (hopefully normalized) DonationInterface data set.
GatewayType | $gateway | |
array | $data | Normalized donation data. |
array | $check_not_empty | An array of fields to do empty validation on. If this is not populated, no fields will throw errors for being empty, UNLESS they are required for a field that uses them for more complex validation (the 'calculated' phase). |
BadMethodCallException |
Definition at line 129 of file DataValidator.php.
References GatewayType\getCurrencies(), getError(), and getErrorToken().
Referenced by GatewayAdapter\validate().
|
static |
Gets rid of numbers that pass luhn in address fields -.
string | $value |
Definition at line 409 of file DataValidator.php.
References cc_number_exists_in_str(), and obviousXssInString().
|
staticprotected |
validate_alphanumeric Checks to make sure the value is populated with an alphanumeric value... ...which would be great, if it made sense at all.
TODO: This is duuuuumb. Make it do something good, or get rid of it. If we can think of a way to make this useful, we should do something here.
string | $value | The value that is meant to be alphanumeric |
Definition at line 371 of file DataValidator.php.
|
staticprotected |
validate_boolean Determines if the $value passed in is a valid boolean.
string | $value | The piece of data that is supposed to be a boolean. |
Definition at line 309 of file DataValidator.php.
|
staticprotected |
validate_credit_card Determines if the $value passed in is (possibly) a valid credit card number.
string | $value | The piece of data that is supposed to be a credit card number. |
Definition at line 295 of file DataValidator.php.
References getCardType().
|
staticprotected |
Definition at line 281 of file DataValidator.php.
|
staticprotected |
validate_email Determines if the $value passed in is a valid email address.
string | $value | The piece of data that is supposed to be an email address. |
Definition at line 275 of file DataValidator.php.
References cc_number_exists_in_str(), and special_characters_in_wrong_locations().
|
staticprotected |
validate_gateway Checks to make sure the gateway is populated with a valid and enabled gateway.
string | $value | The value that is meant to be a gateway. |
Definition at line 344 of file DataValidator.php.
|
static |
Some people are silly and enter their CC numbers as their name.
This performs a luhn check on the name to make sure it's not actually a potentially valid CC number.
string | $value | Ze name! |
Definition at line 399 of file DataValidator.php.
References cc_number_exists_in_str(), and obviousXssInString().
|
staticprotected |
validate_not_empty Checks to make sure that the $value is present in the $data array, and not null or an empty string.
Anything else that is 'falseish' is still perfectly valid to have as a data point. TODO: Consider doing this in a batch.
string | $value | The value to check for non-emptiness. |
Definition at line 358 of file DataValidator.php.
|
static |
Validates that somebody didn't just punch in a bunch of punctuation, and nothing else.
Doing so for certain fields can short-circuit AVS checking at some banks, and so we want to treat data like this as empty in the adapter staging phase.
string | $value | The value to check |
Definition at line 383 of file DataValidator.php.
Referenced by StreetAddress\stage_street().
|
staticprotected |
validate_numeric Determines if the $value passed in is numeric.
string | $value | The piece of data that is supposed to be numeric. |
Definition at line 329 of file DataValidator.php.
|
static |
Test to determine if a value appears in a haystack.
The haystack may have explicit +/- rules (a - will take precedence over a +; if there is no
mixed | $needle | Value, or array of values, to match |
mixed | $haystack | Value, or array of values, that are acceptable |
Definition at line 628 of file DataValidator.php.