CreditCard
extends AbstractValidator
in package
Table of Contents
Constants
- ALL = 'All'
- Detected CCI list
- AMERICAN_EXPRESS = 'American_Express'
- CHECKSUM = 'creditcardChecksum'
- CONTENT = 'creditcardContent'
- DINERS_CLUB = 'Diners_Club'
- DINERS_CLUB_US = 'Diners_Club_US'
- DISCOVER = 'Discover'
- INVALID = 'creditcardInvalid'
- JCB = 'JCB'
- LASER = 'Laser'
- LENGTH = 'creditcardLength'
- MAESTRO = 'Maestro'
- MASTERCARD = 'Mastercard'
- MIR = 'Mir'
- PREFIX = 'creditcardPrefix'
- SERVICE = 'creditcardService'
- SERVICEFAILURE = 'creditcardServiceFailure'
- SOLO = 'Solo'
- UNIONPAY = 'Unionpay'
- VISA = 'Visa'
Properties
- $messageTemplates : array<string, string>
- $messageVariables : array<string, mixed>
- $options : array<string, mixed>
- $abstractOptions : AbstractOptions|array<string, mixed>
- $cardLength : array<string|int, mixed>
- List of allowed CCV lengths
- $cardName : array<string|int, mixed>
- List of CCV names
- $cardType : array<string|int, mixed>
- List of accepted CCV provider tags
- $defaultTranslator : TranslatorInterface
- Default translation object for all validate objects
- $defaultTranslatorTextDomain : string
- Default text domain to be used with translator
- $messageLength : int
- Limits the maximum returned length of an error message
- $messageTemplates : array<string|int, mixed>
- Validation failure message template definitions
- $options : array<string|int, mixed>
- Options for this validator
- $value : mixed
- The value to be validated
Methods
- __construct() : mixed
- Constructor
- __get() : mixed
- Magic function returns the value of the requested property, if and only if it is the value or a message variable.
- __invoke() : bool
- Invoke as command
- addType() : $this
- Adds a CCI to be accepted by validation
- getDefaultTranslator() : TranslatorInterface|null
- Get default translation object for all validate objects
- getDefaultTranslatorTextDomain() : string
- Get default translation text domain for all validate objects
- getMessageLength() : int
- Returns the maximum allowed message length
- getMessages() : array<string, string>
- Returns array of validation failure messages
- getMessageTemplates() : array<string, string>
- Returns the message templates from the validator
- getMessageVariables() : array<int, string>
- Returns an array of the names of variables that are used in constructing validation failure messages
- getOption() : mixed
- Returns an option
- getOptions() : array<string, mixed>
- Returns all available options
- getService() : callable
- Returns the actual set service
- getTranslator() : TranslatorInterface|null
- Return translation object
- getTranslatorTextDomain() : string
- Return the translation text domain
- getType() : array<string|int, mixed>
- Returns a list of accepted CCIs
- hasDefaultTranslator() : bool
- Is there a default translation object set?
- hasTranslator() : bool
- Does this validator have its own specific translator?
- isTranslatorEnabled() : bool
- Is translation enabled?
- isValid() : bool
- Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
- isValueObscured() : bool
- Retrieve flag indicating whether or not value should be obfuscated in messages
- setDefaultTranslator() : void
- Set default translation object for all validate objects
- setDefaultTranslatorTextDomain() : void
- Set default translation text domain for all validate objects
- setMessage() : $this
- Sets the validation failure message template for a particular key
- setMessageLength() : void
- Sets the maximum allowed message length
- setMessages() : $this
- Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
- setOptions() : $this
- Sets one or multiple options
- setService() : $this
- Sets a new callback for service validation
- setTranslator() : $this
- Set translation object
- setTranslatorEnabled() : $this
- Indicate whether or not translation should be enabled
- setTranslatorTextDomain() : $this
- Set translation text domain
- setType() : CreditCard
- Sets CCIs which are accepted by validation
- setValueObscured() : $this
- Set flag indicating whether or not value should be obfuscated in messages
- createMessage() : null|string
- Constructs and returns a validation failure message with the given message key and value.
- error() : void
- getValue() : mixed
- Returns the validation value
- setValue() : void
- Sets the value to be validated and clears the messages and errors arrays
- translateMessage() : string
- Translate a validation message
Constants
ALL
Detected CCI list
public
string
ALL
= 'All'
AMERICAN_EXPRESS
public
mixed
AMERICAN_EXPRESS
= 'American_Express'
CHECKSUM
public
mixed
CHECKSUM
= 'creditcardChecksum'
CONTENT
public
mixed
CONTENT
= 'creditcardContent'
DINERS_CLUB
public
mixed
DINERS_CLUB
= 'Diners_Club'
DINERS_CLUB_US
public
mixed
DINERS_CLUB_US
= 'Diners_Club_US'
DISCOVER
public
mixed
DISCOVER
= 'Discover'
INVALID
public
mixed
INVALID
= 'creditcardInvalid'
JCB
public
mixed
JCB
= 'JCB'
LASER
public
mixed
LASER
= 'Laser'
LENGTH
public
mixed
LENGTH
= 'creditcardLength'
MAESTRO
public
mixed
MAESTRO
= 'Maestro'
MASTERCARD
public
mixed
MASTERCARD
= 'Mastercard'
MIR
public
mixed
MIR
= 'Mir'
PREFIX
public
mixed
PREFIX
= 'creditcardPrefix'
SERVICE
public
mixed
SERVICE
= 'creditcardService'
SERVICEFAILURE
public
mixed
SERVICEFAILURE
= 'creditcardServiceFailure'
SOLO
public
mixed
SOLO
= 'Solo'
UNIONPAY
public
mixed
UNIONPAY
= 'Unionpay'
VISA
public
mixed
VISA
= 'Visa'
Properties
$messageTemplates
public
array<string, string>
$messageTemplates
$messageVariables
public
array<string, mixed>
$messageVariables
$options
public
array<string, mixed>
$options
$abstractOptions
protected
AbstractOptions|array<string, mixed>
$abstractOptions
= [
'messages' => [],
// Array of validation failure messages
'messageTemplates' => [],
// Array of validation failure message templates
'messageVariables' => [],
// Array of additional variables available for validation failure messages
'translator' => null,
// Translation object to used -> Translator\TranslatorInterface
'translatorTextDomain' => null,
// Translation text domain
'translatorEnabled' => true,
// Is translation enabled?
'valueObscured' => false,
]
$cardLength
List of allowed CCV lengths
protected
array<string|int, mixed>
$cardLength
= [self::AMERICAN_EXPRESS => [15], self::DINERS_CLUB => [14], self::DINERS_CLUB_US => [16], self::DISCOVER => [16, 19], self::JCB => [15, 16], self::LASER => [16, 17, 18, 19], self::MAESTRO => [12, 13, 14, 15, 16, 17, 18, 19], self::MASTERCARD => [16], self::SOLO => [16, 18, 19], self::UNIONPAY => [16, 17, 18, 19], self::VISA => [13, 16, 19], self::MIR => [13, 16]]
$cardName
List of CCV names
protected
array<string|int, mixed>
$cardName
= [0 => self::AMERICAN_EXPRESS, 1 => self::DINERS_CLUB, 2 => self::DINERS_CLUB_US, 3 => self::DISCOVER, 4 => self::JCB, 5 => self::LASER, 6 => self::MAESTRO, 7 => self::MASTERCARD, 8 => self::SOLO, 9 => self::UNIONPAY, 10 => self::VISA, 11 => self::MIR]
$cardType
List of accepted CCV provider tags
protected
array<string|int, mixed>
$cardType
= [self::AMERICAN_EXPRESS => ['34', '37'], self::DINERS_CLUB => ['300', '301', '302', '303', '304', '305', '36'], self::DINERS_CLUB_US => ['54', '55'], self::DISCOVER => ['6011', '622126', '622127', '622128', '622129', '62213', '62214', '62215', '62216', '62217', '62218', '62219', '6222', '6223', '6224', '6225', '6226', '6227', '6228', '62290', '62291', '622920', '622921', '622922', '622923', '622924', '622925', '644', '645', '646', '647', '648', '649', '65'], self::JCB => ['1800', '2131', '3528', '3529', '353', '354', '355', '356', '357', '358'], self::LASER => ['6304', '6706', '6771', '6709'], self::MAESTRO => ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766', '6772'], self::MASTERCARD => ['2221', '2222', '2223', '2224', '2225', '2226', '2227', '2228', '2229', '223', '224', '225', '226', '227', '228', '229', '23', '24', '25', '26', '271', '2720', '51', '52', '53', '54', '55'], self::SOLO => ['6334', '6767'], self::UNIONPAY => ['622126', '622127', '622128', '622129', '62213', '62214', '62215', '62216', '62217', '62218', '62219', '6222', '6223', '6224', '6225', '6226', '6227', '6228', '62290', '62291', '622920', '622921', '622922', '622923', '622924', '622925'], self::VISA => ['4'], self::MIR => ['2200', '2201', '2202', '2203', '2204']]
$defaultTranslator
Default translation object for all validate objects
protected
static TranslatorInterface
$defaultTranslator
$defaultTranslatorTextDomain
Default text domain to be used with translator
protected
static string
$defaultTranslatorTextDomain
= 'default'
$messageLength
Limits the maximum returned length of an error message
protected
static int
$messageLength
= -1
$messageTemplates
Validation failure message template definitions
protected
array<string|int, mixed>
$messageTemplates
= [self::CHECKSUM => 'The input seems to contain an invalid checksum', self::CONTENT => 'The input must contain only digits', self::INVALID => 'Invalid type given. String expected', self::LENGTH => 'The input contains an invalid amount of digits', self::PREFIX => 'The input is not from an allowed institute', self::SERVICE => 'The input seems to be an invalid credit card number', self::SERVICEFAILURE => 'An exception has been raised while validating the input']
$options
Options for this validator
protected
array<string|int, mixed>
$options
= [
'service' => null,
// Service callback for additional validation
'type' => [],
]
$value
The value to be validated
protected
mixed
$value
Methods
__construct()
Constructor
public
__construct([string|array<string|int, mixed>|Traversable $options = [] ]) : mixed
Parameters
- $options : string|array<string|int, mixed>|Traversable = []
-
OPTIONAL Type of CCI to allow
__get()
Magic function returns the value of the requested property, if and only if it is the value or a message variable.
public
__get(string $property) : mixed
Parameters
- $property : string
Tags
__invoke()
Invoke as command
public
__invoke(mixed $value) : bool
Parameters
- $value : mixed
Return values
booladdType()
Adds a CCI to be accepted by validation
public
addType(string|array<string|int, mixed> $type) : $this
Parameters
- $type : string|array<string|int, mixed>
-
Type to allow for validation
Return values
$this —Provides a fluid interface
getDefaultTranslator()
Get default translation object for all validate objects
public
static getDefaultTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetDefaultTranslatorTextDomain()
Get default translation text domain for all validate objects
public
static getDefaultTranslatorTextDomain() : string
Return values
stringgetMessageLength()
Returns the maximum allowed message length
public
static getMessageLength() : int
Return values
intgetMessages()
Returns array of validation failure messages
public
getMessages() : array<string, string>
Return values
array<string, string>getMessageTemplates()
Returns the message templates from the validator
public
getMessageTemplates() : array<string, string>
Return values
array<string, string>getMessageVariables()
Returns an array of the names of variables that are used in constructing validation failure messages
public
getMessageVariables() : array<int, string>
Return values
array<int, string>getOption()
Returns an option
public
getOption(string $option) : mixed
Parameters
- $option : string
-
Option to be returned
Tags
Return values
mixed —Returned option
getOptions()
Returns all available options
public
getOptions() : array<string, mixed>
Return values
array<string, mixed> —Array with all available options
getService()
Returns the actual set service
public
getService() : callable
Return values
callablegetTranslator()
Return translation object
public
getTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetTranslatorTextDomain()
Return the translation text domain
public
getTranslatorTextDomain() : string
Return values
stringgetType()
Returns a list of accepted CCIs
public
getType() : array<string|int, mixed>
Return values
array<string|int, mixed>hasDefaultTranslator()
Is there a default translation object set?
public
static hasDefaultTranslator() : bool
Return values
boolhasTranslator()
Does this validator have its own specific translator?
public
hasTranslator() : bool
Return values
boolisTranslatorEnabled()
Is translation enabled?
public
isTranslatorEnabled() : bool
Return values
boolisValid()
Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
public
isValid(string $value) : bool
Parameters
- $value : string
Return values
boolisValueObscured()
Retrieve flag indicating whether or not value should be obfuscated in messages
public
isValueObscured() : bool
Return values
boolsetDefaultTranslator()
Set default translation object for all validate objects
public
static setDefaultTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : void
Parameters
- $translator : TranslatorInterface|null = null
- $textDomain : string = null
-
(optional)
Tags
setDefaultTranslatorTextDomain()
Set default translation text domain for all validate objects
public
static setDefaultTranslatorTextDomain([string $textDomain = 'default' ]) : void
Parameters
- $textDomain : string = 'default'
setMessage()
Sets the validation failure message template for a particular key
public
setMessage(string $messageString[, string|null $messageKey = null ]) : $this
Parameters
- $messageString : string
- $messageKey : string|null = null
-
OPTIONAL
Tags
Return values
$this —Provides a fluent interface
setMessageLength()
Sets the maximum allowed message length
public
static setMessageLength([int $length = -1 ]) : void
Parameters
- $length : int = -1
setMessages()
Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
public
setMessages(array<string, string> $messages) : $this
Parameters
- $messages : array<string, string>
Return values
$thissetOptions()
Sets one or multiple options
public
setOptions([array<string, mixed>|Traversable<string, mixed> $options = [] ]) : $this
Parameters
- $options : array<string, mixed>|Traversable<string, mixed> = []
-
Options to set
Tags
Return values
$this —Provides fluid interface
setService()
Sets a new callback for service validation
public
setService(callable $service) : $this
Parameters
- $service : callable
Tags
Return values
$thissetTranslator()
Set translation object
public
setTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : $this
Parameters
- $translator : TranslatorInterface|null = null
-
[optional] translator. Default is null, which sets no translator.
- $textDomain : string = null
-
(optional)
Tags
Return values
$thissetTranslatorEnabled()
Indicate whether or not translation should be enabled
public
setTranslatorEnabled([bool $enabled = true ]) : $this
Parameters
- $enabled : bool = true
Return values
$thissetTranslatorTextDomain()
Set translation text domain
public
setTranslatorTextDomain([string $textDomain = 'default' ]) : $this
Parameters
- $textDomain : string = 'default'
Return values
$thissetType()
Sets CCIs which are accepted by validation
public
setType(string|array<string|int, mixed> $type) : CreditCard
Parameters
- $type : string|array<string|int, mixed>
-
Type to allow for validation
Return values
CreditCard —Provides a fluid interface
setValueObscured()
Set flag indicating whether or not value should be obfuscated in messages
public
setValueObscured(bool $flag) : $this
Parameters
- $flag : bool
Return values
$thiscreateMessage()
Constructs and returns a validation failure message with the given message key and value.
protected
createMessage(string $messageKey, string|array<string|int, mixed>|object $value) : null|string
Returns null if and only if $messageKey does not correspond to an existing template.
If a translator is available and a translation exists for $messageKey, the translation will be used.
Parameters
- $messageKey : string
- $value : string|array<string|int, mixed>|object
Return values
null|stringerror()
protected
error(string|null $messageKey[, null|string|array<string|int, mixed>|object $value = null ]) : void
Parameters
- $messageKey : string|null
- $value : null|string|array<string|int, mixed>|object = null
-
OPTIONAL
getValue()
Returns the validation value
protected
getValue() : mixed
Return values
mixed —Value to be validated
setValue()
Sets the value to be validated and clears the messages and errors arrays
protected
setValue(mixed $value) : void
Parameters
- $value : mixed
translateMessage()
Translate a validation message
protected
translateMessage(string $messageKey, string $message) : string
Parameters
- $messageKey : string
- $message : string