Doctrine 1.2.4
Doctrine_Validator_Creditcard Class Reference

Inherits Doctrine_Validator_Driver.

Public Member Functions

 __get ($arg)
 
 __isset ($arg)
 
 __set ($arg, $value)
 
 getArg ($arg)
 
 getArgs ()
 
 setArg ($arg, $value)
 
 validate ($value)
 

Detailed Description

Definition at line 33 of file Creditcard.php.

Member Function Documentation

Doctrine_Validator_Driver::__get (   $arg)
inherited

__get an alias for getOption

Parameters
string$arg

Definition at line 48 of file Driver.php.

{
if (isset($this->args[$arg])) {
return $this->args[$arg];
}
return null;
}
Doctrine_Validator_Driver::__isset (   $arg)
inherited

__isset

Parameters
string$arg

Definition at line 61 of file Driver.php.

{
return isset($this->args[$arg]);
}
Doctrine_Validator_Driver::__set (   $arg,
  $value 
)
inherited

sets given value to an argument

Parameters
$argthe name of the option to be changed
$valuethe value of the option
Returns
Doctrine_Validator_Driver this object

Definition at line 73 of file Driver.php.

{
$this->args[$arg] = $value;
return $this;
}
Doctrine_Validator_Driver::getArg (   $arg)
inherited

returns the value of an argument

Parameters
$argthe name of the option to retrieve
Returns
mixed the value of the option

Definition at line 86 of file Driver.php.

{
if ( ! isset($this->args[$arg])) {
throw new Doctrine_Validator_Exception('Unknown option ' . $arg);
}
return $this->args[$arg];
}
Doctrine_Validator_Driver::getArgs ( )
inherited

returns all args and their associated values

Returns
array all args as an associative array

Definition at line 114 of file Driver.php.

{
return $this->args;
}
Doctrine_Validator_Driver::setArg (   $arg,
  $value 
)
inherited

sets given value to an argument

Parameters
$argthe name of the option to be changed
$valuethe value of the option
Returns
Doctrine_Validator_Driver this object

Definition at line 102 of file Driver.php.

{
$this->args[$arg] = $value;
return $this;
}
Doctrine_Validator_Creditcard::validate (   $value)

checks if given value is a valid credit card number

mixed $value boolean

Definition at line 42 of file Creditcard.php.

{
if (is_null($value)) {
return true;
}
$cardType = "";
$card_regexes = array(
"/^4\d{12}(\d\d\d){0,1}$/" => 'visa',
"/^5[12345]\d{14}$/" => 'mastercard',
"/^3[47]\d{13}$/" => 'amex',
"/^6011\d{12}$/" => 'discover',
"/^30[012345]\d{11}$/" => 'diners',
"/^3[68]\d{12}$/" => 'diners',
);
foreach ($card_regexes as $regex => $type) {
if (preg_match($regex, $value)) {
$cardType = $type;
break;
}
}
if ( ! $cardType) {
return false;
}
/* mod 10 checksum algorithm */
$revcode = strrev($value);
$checksum = 0;
for ($i = 0; $i < strlen($revcode); $i++) {
$currentNum = intval($revcode[$i]);
if ($i & 1) { /* Odd position */
$currentNum *= 2;
}
/* Split digits and add. */
$checksum += $currentNum % 10;
if ($currentNum > 9) {
$checksum += 1;
}
}
if ($checksum % 10 == 0) {
return true;
} else {
return false;
}
}

The documentation for this class was generated from the following file: