Verifier
in package
implements
ArrayAccess
Uses
BackwardCompatibility, ArrayAccessHelper
Sets up the anti-spam control that tries to verify the user's humanity.
Supports old-fashioned CAPTCHA, reCAPTCHA, and verification questions.
Table of Contents
Interfaces
- ArrayAccess
Constants
- MAX_ATTEMPTS = 3
Properties
- $can_recaptcha : bool
- $empty_field : bool
- $errors : array<string|int, mixed>
- $id : string
- $image_href : string
- $loaded : array<string|int, mixed>
- $max_errors : int
- $number_questions : int
- $questions : array<string|int, mixed>
- $recaptcha_site_key : string
- $recaptcha_theme : string
- $result : bool
- $show_visual : bool
- $text_value : string
- $tracking : int
- $vid : string
- $question_ids : array<string|int, mixed>
- $backcompat : array<string|int, mixed>
Methods
- __construct() : bool|array<string|int, mixed>
- Constructor.
- create() : bool|array<string|int, mixed>
- Static wrapper for constructor that returns result (or error indicators).
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- offsetExists() : bool
- Checks whether a property has been set when object is accessed as an array.
- offsetGet() : mixed
- Gets properties when object is accessed as an array.
- offsetSet() : void
- Sets properties when object is accessed as an array.
- offsetUnset() : void
- Unsets properties when object is accessed as an array.
- addCaptchaJavaScript() : void
- Adds JavaScript for the visual captcha.
- init() : void
- Initializes some required template stuff.
- loadQuestionCache() : void
- Loads the cache of verification questions and answers.
- refresh() : void
- Refresh this verification.
- sanitizeReCaptcha() : void
- Sanitizes ReCaptcha fields.
- setQuestions() : void
- Sets the verification questions and answers for this instance.
- shouldRefresh() : bool
- Do we need to refresh this verification?
- test() : void
Constants
MAX_ATTEMPTS
public
mixed
MAX_ATTEMPTS
= 3
Properties
$can_recaptcha
public
bool
$can_recaptcha
$empty_field
public
bool
$empty_field
$errors
public
array<string|int, mixed>
$errors
= []
Error messages about any problems encountered during setup.
$id
public
string
$id
This editor's ID string.
$image_href
public
string
$image_href
$loaded
public
static array<string|int, mixed>
$loaded
= []
All loaded instances of this class.
$max_errors
public
int
$max_errors
$number_questions
public
int
$number_questions
$questions
public
array<string|int, mixed>
$questions
$recaptcha_site_key
public
string
$recaptcha_site_key
= ''
$recaptcha_theme
public
string
$recaptcha_theme
= 'light'
$result
public
bool
$result
= true
Whether there is anything to show. Assume true until proven otherwise.
$show_visual
public
bool
$show_visual
$text_value
public
string
$text_value
$tracking
public
int
$tracking
= 0
$vid
public
static string
$vid
= ''
ID of the most recently loaded instance of this class.
Normally this is the one that we want to show.
$question_ids
protected
array<string|int, mixed>
$question_ids
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['func_names' => ['create' => 'create_control_verification']]
BackwardCompatibility settings for this class.
Methods
__construct()
Constructor.
public
__construct(array<string|int, mixed> $options[, bool $do_test = false ]) : bool|array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
-
Options for the verification control.
- $do_test : bool = false
-
Whether to check to see if the user entered the code correctly.
Tags
Return values
bool|array<string|int, mixed> —False if there's nothing to show, true if everything went well or an array containing error indicators if the test failed.
create()
Static wrapper for constructor that returns result (or error indicators).
public
static create(array<string|int, mixed> &$options[, bool $do_test = false ]) : bool|array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
-
Options for the verification control.
- $do_test : bool = false
-
Whether to check to see if the user entered the code correctly.
Return values
bool|array<string|int, mixed> —False if there's nothing to show, true if everything went well, or an array containing error indicators if the test failed.
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- At the END of the class's file, call its exportStatic() method.
Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.
Regarding the $backcompat items:
A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].
$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.
$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.
Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.
offsetExists()
Checks whether a property has been set when object is accessed as an array.
public
offsetExists(mixed $prop) : bool
Parameters
- $prop : mixed
-
The property name.
Return values
booloffsetGet()
Gets properties when object is accessed as an array.
public
offsetGet(mixed $prop) : mixed
Parameters
- $prop : mixed
-
The property name.
offsetSet()
Sets properties when object is accessed as an array.
public
offsetSet(mixed $prop, mixed $value) : void
Parameters
- $prop : mixed
-
The property name.
- $value : mixed
-
The value to set.
offsetUnset()
Unsets properties when object is accessed as an array.
public
offsetUnset(mixed $prop) : void
Parameters
- $prop : mixed
-
The property name.
addCaptchaJavaScript()
Adds JavaScript for the visual captcha.
protected
addCaptchaJavaScript() : void
init()
Initializes some required template stuff.
protected
init() : void
loadQuestionCache()
Loads the cache of verification questions and answers.
protected
loadQuestionCache() : void
refresh()
Refresh this verification.
protected
refresh() : void
sanitizeReCaptcha()
Sanitizes ReCaptcha fields.
protected
sanitizeReCaptcha() : void
setQuestions()
Sets the verification questions and answers for this instance.
protected
setQuestions() : void
shouldRefresh()
Do we need to refresh this verification?
protected
shouldRefresh(bool $only_if_necessary, bool $do_test) : bool
Parameters
- $only_if_necessary : bool
-
If true, only refresh if we absolutely must.
- $do_test : bool
-
Whether we are checking their answers.
Return values
bool —Whether we should refresh this verification.
test()
protected
test() : void