Image-based captcha element

Generates image displaying random word

package Default
inherited_from \Zend\Captcha\AbstractWord

 Methods

Constructor

__construct(array|\Traversable $options = null

Parameters

$options

array\Traversable

Exceptions

\Zend\Captcha\Exception\ExtensionNotLoadedException

Abstract constructor for all validators A validator should accept following parameters: - nothing f.e. Validator() - one or multiple scalar values f.e. Validator($first, $second, $third) - an array f.e. Validator(array($first => 'first', $second => 'second', $third => 'third')) - an instance of Traversable f.e. Validator($config_instance)

__construct(array|\Traversable $options = null
Inherited

Parameters

$options

array\Traversable

Magic function returns the value of the requested property, if and only if it is the value or a message variable.

__get(string $property) : mixed
Inherited

Parameters

$property

string

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixed

Invoke as command

__invoke(mixed $value) : boolean
Inherited

Parameters

$value

mixed

Returns

boolean

Generate captcha

generate() : string
inherited_from \Zend\Captcha\AbstractWord::generate()

Returns

stringcaptcha ID

Generate new session ID and new word

generate() : string
Inherited

Returns

stringsession ID

Get default translation object for all validate objects

getDefaultTranslator() : \Zend\Validator\Translator\TranslatorInterface | null
InheritedStatic

Returns

\Zend\Validator\Translator\TranslatorInterfacenull

Get default translation text domain for all validate objects

getDefaultTranslatorTextDomain() : string
InheritedStatic

Returns

string

getDotNoiseLevel()

getDotNoiseLevel() : integer

Returns

integer

Get captcha expiration

getExpiration() : integer

Returns

integer

Get font to use when generating captcha

getFont() : string

Returns

string

Get font size

getFontSize() : integer

Returns

integer

Get garbage collection frequency

getGcFreq() : integer

Returns

integer

Get captcha image height

getHeight() : integer

Returns

integer

Get helper name used to render captcha

getHelperName() : string

By default, return empty string, indicating no helper needed.

inherited_from \Zend\Captcha\AbstractWord::getHelperName()

Returns

string

Get helper name used to render captcha

getHelperName() : string
Inherited

By default, return empty string, indicating no helper needed.

inherited_from \Zend\Captcha\AdapterInterface::getHelperName()

Returns

string

Retrieve captcha ID

getId() : string
Inherited

Returns

string

getImgAlt()

getImgAlt() : string

Returns

string

Get captcha image directory

getImgDir() : string

Returns

string

Get captcha image base URL

getImgUrl() : string

Returns

string

getLineNoiseLevel()

getLineNoiseLevel() : integer

Returns

integer

Returns the maximum allowed message length

getMessageLength() : integer
InheritedStatic

Returns

integer

Returns the message templates from the validator

getMessageTemplates() : array
Inherited

Returns

array

Returns an array of the names of variables that are used in constructing validation failure messages

getMessageVariables() : array
Inherited

Returns

array

Returns array of validation failure messages

getMessages() : array
Inherited

If isValid() was never called or if the most recent isValid() call returned true, then this method returns an empty array.

inherited_from \Zend\Validator\ValidatorInterface::getMessages()

Returns

array

Get name

getName() : string
Inherited
inherited_from \Zend\Captcha\AdapterInterface::getName()

Returns

string

Returns an option

getOption(string $option) : mixed
Inherited

Parameters

$option

string

Option to be returned

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixedReturned option

Returns all available options

getOptions() : array
Inherited

Returns

arrayArray with all available options

Get session object

getSession() : \Zend\Session\Container
Inherited

Exceptions

\Zend\Captcha\Exception\InvalidArgumentException

Returns

\Zend\Session\Container

Retrieve session class to utilize

getSessionClass() : string
Inherited

Returns

string

getStartImage()

getStartImage() : string

Returns

string

Get captcha image file suffix

getSuffix() : string

Returns

string

Get session token timeout

getTimeout() : integer
Inherited

Returns

integer

Return translation object

getTranslator() : \Zend\Validator\Translator\TranslatorInterface | null
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::getTranslator()

Returns

\Zend\Validator\Translator\TranslatorInterfacenull

Return the translation text domain

getTranslatorTextDomain() : string
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::getTranslatorTextDomain()

Returns

string

Numbers should be included in the pattern?

getUseNumbers() : boolean
Inherited

Returns

boolean

Get captcha image width

getWidth() : integer

Returns

integer

Get captcha word

getWord() : string
Inherited

Returns

string

Retrieve word length to use when generating captcha

getWordlen() : integer
Inherited

Returns

integer

Is there a default translation object set?

hasDefaultTranslator() : boolean
InheritedStatic

Returns

boolean

Does this validator have its own specific translator?

hasTranslator() : boolean
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::hasTranslator()

Returns

boolean

Is translation enabled?

isTranslatorEnabled() : boolean
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::isTranslatorEnabled()

Returns

boolean

Validate the word

isValid(mixed $value, mixed $context = null) : boolean
Inherited
see

Parameters

$value

mixed

$context

mixed

Returns

boolean

Retrieve flag indicating whether or not value should be obfuscated in messages

isValueObscured() : boolean
Inherited

Returns

boolean

Set default translation object for all validate objects

setDefaultTranslator(\Zend\Validator\Translator\TranslatorInterface|null $translator = null, string $textDomain = null) : void
InheritedStatic

Parameters

$translator

\Zend\Validator\Translator\TranslatorInterfacenull

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Set default translation text domain for all validate objects

setDefaultTranslatorTextDomain(string $textDomain = 'default') : void
InheritedStatic

Parameters

$textDomain

string

setDotNoiseLevel()

setDotNoiseLevel(integer $dotNoiseLevel) : \Zend\Captcha\Image

Parameters

$dotNoiseLevel

integer

Returns

\Zend\Captcha\Image

Set captcha expiration

setExpiration(integer $expiration) : \Zend\Captcha\Image

Parameters

$expiration

integer

Returns

\Zend\Captcha\Image

Set captcha font

setFont(string $font) : \Zend\Captcha\Image

Parameters

$font

string

Returns

\Zend\Captcha\Image

Set captcha font size

setFontSize(integer $fsize) : \Zend\Captcha\Image

Parameters

$fsize

integer

Returns

\Zend\Captcha\Image

Set garbage collection frequency

setGcFreq(integer $gcFreq) : \Zend\Captcha\Image

Parameters

$gcFreq

integer

Returns

\Zend\Captcha\Image

Set captcha image height

setHeight(integer $height) : \Zend\Captcha\Image

Parameters

$height

integer

Returns

\Zend\Captcha\Image

setImgAlt()

setImgAlt(string $imgAlt) : \Zend\Captcha\Image

Parameters

$imgAlt

string

Returns

\Zend\Captcha\Image

Set captcha image storage directory

setImgDir(string $imgDir) : \Zend\Captcha\Image

Parameters

$imgDir

string

Returns

\Zend\Captcha\Image

Set captcha image base URL

setImgUrl(string $imgUrl) : \Zend\Captcha\Image

Parameters

$imgUrl

string

Returns

\Zend\Captcha\Image

Sets if session should be preserved on generate()

setKeepSession(boolean $keepSession) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$keepSession

boolean

Should session be kept on generate()?

Returns

\Zend\Captcha\AbstractWord

setLineNoiseLevel()

setLineNoiseLevel(integer $lineNoiseLevel) : \Zend\Captcha\Image

Parameters

$lineNoiseLevel

integer

Returns

\Zend\Captcha\Image

Sets the validation failure message template for a particular key

setMessage(string $messageString, string $messageKey = null) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$messageString

string

$messageKey

string

OPTIONAL

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

\Zend\Validator\AbstractValidatorProvides a fluent interface

Sets the maximum allowed message length

setMessageLength(integer $length = -1
InheritedStatic

Parameters

$length

integer

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.

setMessages(array $messages) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$messages

array

Returns

\Zend\Validator\AbstractValidator

Set name

setName(string $name) : \Zend\Captcha\AbstractAdapter
Inherited
inherited_from \Zend\Captcha\AdapterInterface::setName()

Parameters

$name

string

Returns

\Zend\Captcha\AbstractAdapter

Set single option for the object

setOption(string $key, string $value) : \Zend\Captcha\AbstractAdapter
Inherited

Parameters

$key

string

$value

string

Returns

\Zend\Captcha\AbstractAdapter

Sets one or multiple options

setOptions(array|\Traversable $options = array()) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$options

array\Traversable

Options to set

Exceptions

\Zend\Validator\Exception\InvalidArgumentException If $options is not an array or Traversable

Returns

\Zend\Validator\AbstractValidatorProvides fluid interface

Set session namespace object

setSession(\Zend\Session\Container $session) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$session

\Zend\Session\Container

Returns

\Zend\Captcha\AbstractWord

Set session class for persistence

setSessionClass(string $sessionClass) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$sessionClass

string

Returns

\Zend\Captcha\AbstractWord

setStartImage()

setStartImage(string $startImage) : \Zend\Captcha\Image

Parameters

$startImage

string

Returns

\Zend\Captcha\Image

Set captcha image filename suffix

setSuffix(string $suffix) : \Zend\Captcha\Image

Parameters

$suffix

string

Returns

\Zend\Captcha\Image

Set timeout for session token

setTimeout(integer $ttl) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$ttl

integer

Returns

\Zend\Captcha\AbstractWord

Set translation object

setTranslator(\Zend\Validator\Translator\TranslatorInterface|null $translator = null, string $textDomain = null) : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslator()

Parameters

$translator

\Zend\Validator\Translator\TranslatorInterfacenull

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

\Zend\Validator\AbstractValidator

Indicate whether or not translation should be enabled

setTranslatorEnabled(boolean $flag = true) : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslatorEnabled()

Parameters

$flag

boolean

Returns

\Zend\Validator\AbstractValidator

Set translation text domain

setTranslatorTextDomain(string $textDomain = 'default') : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslatorTextDomain()

Parameters

$textDomain

string

Returns

\Zend\Validator\AbstractValidator

Set if numbers should be included in the pattern

setUseNumbers(boolean $useNumbers) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$useNumbers

boolean

numbers should be included in the pattern?

Returns

\Zend\Captcha\AbstractWord

Set flag indicating whether or not value should be obfuscated in messages

setValueObscured(boolean $flag) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$flag

boolean

Returns

\Zend\Validator\AbstractValidator

Set captcha image width

setWidth(integer $width) : \Zend\Captcha\Image

Parameters

$width

integer

Returns

\Zend\Captcha\Image

Set word length of captcha

setWordlen(integer $wordlen) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$wordlen

integer

Returns

\Zend\Captcha\AbstractWord

Constructs and returns a validation failure message with the given message key and value.

createMessage(string $messageKey, string|array|object $value) : string
Inherited

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

stringarrayobject

Returns

string

error()

error(string $messageKey, string $value = null) : void
Inherited

Parameters

$messageKey

string

$value

string

OPTIONAL

Remove old files from image directory

gc() 

Generate image captcha

generateImage(string $id, string $word) 

Override this function if you want different image generator Wave transform from http://www.captcha.ru/captchas/multiwave/

Parameters

$id

string

Captcha ID

$word

string

Captcha word

Exceptions

\Zend\Captcha\Exception\NoFontProvidedException if no font was set
\Zend\Captcha\Exception\ImageNotLoadableException if start image cannot be loaded

Generate a random identifier

generateRandomId() : string
Inherited

Returns

string

Generate new random word

generateWord() : string
Inherited

Returns

string

Returns the validation value

getValue() : mixed
Inherited

Returns

mixedValue to be validated

Generate random frequency

randomFreq() : float

Returns

float

Generate random phase

randomPhase() : float

Returns

float

Generate random character size

randomSize() : integer

Returns

integer

Set captcha identifier

setId(string $id) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$id

string

Returns

\Zend\Captcha\AbstractWord

Sets the value to be validated and clears the messages and errors arrays

setValue(mixed $value) : void
Inherited

Parameters

$value

mixed

Set captcha word

setWord(string $word) : \Zend\Captcha\AbstractWord
Inherited

Parameters

$word

string

Returns

\Zend\Captcha\AbstractWord

Translate a validation message

translateMessage(string $messageKey, string $message) : string
Inherited

Parameters

$messageKey

string

$message

string

Returns

string

 Properties

 

$C

$C 

Default

array("b", "c", "d", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "z")
Static
 

$CN

$CN 

Default

array("b", "c", "d", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "z", "2", "3", "4", "5", "6", "7", "8", "9")
Static
 

$V

$V 

Default

array("a", "e", "i", "o", "u", "y")
Static
 

$VN

$VN 

Default

array("a", "e", "i", "o", "u", "y", "2", "3", "4", "5", "6", "7", "8", "9")
Static
 

$abstractOptions

$abstractOptions 

Default

array('messages' => array(), 'messageTemplates' => array(), 'messageVariables' => array(), 'translator' => null, 'translatorTextDomain' => null, 'translatorEnabled' => true, 'valueObscured' => false)
 

Default translation object for all validate objects

$defaultTranslator : \Zend\Validator\Translator\TranslatorInterface

Default

Static
 

Default text domain to be used with translator

$defaultTranslatorTextDomain : string

Default

'default'
Static
 

Number of noise dots on image Used twice - before and after transform

$dotNoiseLevel : integer

Default

100
 

How long to keep generated images

$expiration : integer

Default

600
 

Image font file

$font : string

Default

 

Font size

$fsize : integer

Default

24
 

How frequently to execute garbage collection

$gcFreq : integer

Default

10
 

Image height

$height : integer

Default

50
 

Random session ID

$id : string

Default

 

Image's alt tag content

$imgAlt : string

Default

""
 

Directory for generated images

$imgDir : string

Default

"public/images/captcha/"
 

URL for accessing images

$imgUrl : string

Default

"/images/captcha/"
 

Should generate() keep session or create a new one?

$keepSession : boolean

Default

false
 

Number of noise lines on image Used twice - before and after transform

$lineNoiseLevel : integer

Default

5
 

Limits the maximum returned length of an error message

$messageLength : integer

Default

-1
Static
 

Error messages

$messageTemplates : array

Default

array(self::MISSING_VALUE => 'Empty captcha value', self::MISSING_ID => 'Captcha ID field is missing', self::BAD_CAPTCHA => 'Captcha value is wrong')
 

Captcha name

$name : string

Default

Useful to generate/check form fields

 

Captcha options

$options : array

Default

array()
 

Session

$session : \Zend\Session\Container

Default

 

Class name for sessions

$sessionClass : string

Default

'Zend\Session\Container'
 

Options to skip when processing options

$skipOptions : array

Default

array('options', 'config')
 

Image to use as starting point Default is blank image. If provided, should be PNG image.

$startImage : string

Default

 

Image suffix (including dot)

$suffix : string

Default

".png"
 

Session lifetime for the captcha data

$timeout : integer

Default

300
 

Should the numbers be used or only letters

$useNumbers : boolean

Default

true
 

The value to be validated

$value : mixed

Default

 

Image width

$width : integer

Default

200
 

Generated word

$word : string

Default

 

Length of the word to generate

$wordlen : integer

Default

8

 Constants

 

BAD_CAPTCHA

BAD_CAPTCHA = 'badCaptcha' 
 

MISSING_ID

MISSING_ID = 'missingID' 
 

MISSING_VALUE

MISSING_VALUE = 'missingValue'