Wikimedia SlimApp
Common classes to help with creating an application using the Slim micro framework and Twig template engine.
Loading...
Searching...
No Matches
Wikimedia\Slimapp\Form Class Reference

Collect and validate user input. More...

Public Member Functions

 __construct ( $logger=null)
 
 expect ( $name, $filter, $options=null)
 Add an input expectation.
 
 expectBool ( $name, $options=null)
 
 requireBool ( $name, $options=null)
 
 expectBoolArray ( $name, $options=null)
 
 requireBoolArray ( $name, $options=null)
 
 expectTrue ( $name, $options=null)
 
 requireTrue ( $name, $options=null)
 
 expectTrueArray ( $name, $options=null)
 
 requireTrueArray ( $name, $options=null)
 
 expectEmail ( $name, $options=null)
 
 requireEmail ( $name, $options=null)
 
 expectEmailArray ( $name, $options=null)
 
 requireEmailArray ( $name, $options=null)
 
 expectFloat ( $name, $options=null)
 
 requireFloat ( $name, $options=null)
 
 expectFloatArray ( $name, $options=null)
 
 requireFloatArray ( $name, $options=null)
 
 expectInt ( $name, $options=null)
 
 requireInt ( $name, $options=null)
 
 expectIntArray ( $name, $options=null)
 
 requireIntArray ( $name, $options=null)
 
 expectIp ( $name, $options=null)
 
 requireIp ( $name, $options=null)
 
 expectIpArray ( $name, $options=null)
 
 requireIpArray ( $name, $options=null)
 
 expectRegex ( $name, $re, $options=null)
 
 requireRegex ( $name, $re, $options=null)
 
 expectRegexArray ( $name, $re, $options=null)
 
 requireRegexArray ( $name, $re, $options=null)
 
 expectUrl ( $name, $options=null)
 
 requireUrl ( $name, $options=null)
 
 expectUrlArray ( $name, $options=null)
 
 requireUrlArray ( $name, $options=null)
 
 expectString ( $name, $options=null)
 
 requireString ( $name, $options=null)
 
 expectStringArray ( $name, $options=null)
 
 requireStringArray ( $name, $options=null)
 
 expectAnything ( $name, $options=null)
 
 requireAnything ( $name, $options=null)
 
 expectAnythingArray ( $name, $options=null)
 
 requireAnythingArray ( $name, $options=null)
 
 expectInArray ( $name, $valids, $options=null)
 
 requireInArray ( $name, $valids, $options=null)
 
 expectInArrayArray ( $name, $valids, $options=null)
 
 requireInArrayArray ( $name, $valids, $options=null)
 
 expectDateTime ( $name, $format, $options=null)
 Add an input expectation for a DateTime object.
 
 requireDateTime ( $name, $format, $options=null)
 
 validate ( $vars=null)
 Validate the provided input data using this form's expectations.
 
 get ( $name)
 
 getValues ()
 
 getErrors ()
 
 hasErrors ()
 

Static Public Member Functions

static urlEncode ( $parms)
 Make a URL-encoded string from a key=>value array.
 
static qsMerge ( $params=[])
 Merge parameters into current query string.
 
static qsRemove ( $params=[])
 Remove parameters from current query string.
 

Protected Member Functions

 customValidationHook ()
 Stub method that can be extended by subclasses to add additional validation logic.
 

Static Protected Member Functions

static required ( $options)
 Ensure that the given options collection contains a 'required' key.
 
static wantArray ( $options)
 Ensure that the given options collection contains a 'flags' key that requires the input to be an array.
 

Protected Attributes

 $logger
 
 $params = []
 
 $values = []
 
 $errors = []
 

Detailed Description

Collect and validate user input.

Wraps PHP's built-in filter_var_array function to collect GET or POST input as a collection of sanitized data.

Author
Bryan Davis bd808.nosp@m.@wik.nosp@m.imedi.nosp@m.a.or.nosp@m.g

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Slimapp\Form::__construct ( $logger = null)
Parameters
LoggerInterface$loggerLog channel

Member Function Documentation

◆ expect()

Wikimedia\Slimapp\Form::expect ( $name,
$filter,
$options = null )

Add an input expectation.

Allowed options:

  • default: Default value for missing input
  • flags: Flags to pass to filter_var_array
  • required: Is this input required?
  • validate: Callable to perform additional validation
  • callback: Callable for \FILTER_CALLBACK validation
Parameters
string$nameParameter to expect
int$filterValidation filter(s) to apply
array$optionsValidation options
Returns
Form Self, for message chaining

◆ expectAnything()

Wikimedia\Slimapp\Form::expectAnything ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectAnythingArray()

Wikimedia\Slimapp\Form::expectAnythingArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectBool()

Wikimedia\Slimapp\Form::expectBool ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectBoolArray()

Wikimedia\Slimapp\Form::expectBoolArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectDateTime()

Wikimedia\Slimapp\Form::expectDateTime ( $name,
$format,
$options = null )

Add an input expectation for a DateTime object.

Parameters
string$nameParameter to expect
string$formatExpected date/time format
array$optionsAdditional options
Returns
Form Self, for message chaining
See also
DateTime::createFromFormat

◆ expectEmail()

Wikimedia\Slimapp\Form::expectEmail ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectEmailArray()

Wikimedia\Slimapp\Form::expectEmailArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectFloat()

Wikimedia\Slimapp\Form::expectFloat ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectFloatArray()

Wikimedia\Slimapp\Form::expectFloatArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectInArray()

Wikimedia\Slimapp\Form::expectInArray ( $name,
$valids,
$options = null )
Parameters
string$nameParameter to expect
array$validsValid values
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectInArrayArray()

Wikimedia\Slimapp\Form::expectInArrayArray ( $name,
$valids,
$options = null )
Parameters
string$nameParameter to expect
array$validsValid values
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectInt()

Wikimedia\Slimapp\Form::expectInt ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectIntArray()

Wikimedia\Slimapp\Form::expectIntArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectIp()

Wikimedia\Slimapp\Form::expectIp ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectIpArray()

Wikimedia\Slimapp\Form::expectIpArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectRegex()

Wikimedia\Slimapp\Form::expectRegex ( $name,
$re,
$options = null )
Parameters
string$nameParameter to expect
string$reRegular expression
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectRegexArray()

Wikimedia\Slimapp\Form::expectRegexArray ( $name,
$re,
$options = null )
Parameters
string$nameParameter to expect
string$reRegular expression
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectString()

Wikimedia\Slimapp\Form::expectString ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectStringArray()

Wikimedia\Slimapp\Form::expectStringArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectTrue()

Wikimedia\Slimapp\Form::expectTrue ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectTrueArray()

Wikimedia\Slimapp\Form::expectTrueArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectUrl()

Wikimedia\Slimapp\Form::expectUrl ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ expectUrlArray()

Wikimedia\Slimapp\Form::expectUrlArray ( $name,
$options = null )
Parameters
string$nameParameter to expect
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ get()

Wikimedia\Slimapp\Form::get ( $name)
Parameters
string$nameParameter name
Returns
mixed Parameter value

◆ getErrors()

Wikimedia\Slimapp\Form::getErrors ( )
Returns
array Form errors

◆ getValues()

Wikimedia\Slimapp\Form::getValues ( )
Returns
array Form values

◆ hasErrors()

Wikimedia\Slimapp\Form::hasErrors ( )
Returns
bool True if form has errors, false otherwise.

◆ qsMerge()

static Wikimedia\Slimapp\Form::qsMerge ( $params = [])
static

Merge parameters into current query string.

Parameters
array$paramsParameter array
Returns
string URL-encoded message body

◆ qsRemove()

static Wikimedia\Slimapp\Form::qsRemove ( $params = [])
static

Remove parameters from current query string.

Parameters
array$paramsParameters to remove
Returns
string URL-encoded message body

◆ requireAnything()

Wikimedia\Slimapp\Form::requireAnything ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireAnythingArray()

Wikimedia\Slimapp\Form::requireAnythingArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireBool()

Wikimedia\Slimapp\Form::requireBool ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireBoolArray()

Wikimedia\Slimapp\Form::requireBoolArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ required()

static Wikimedia\Slimapp\Form::required ( $options)
staticprotected

Ensure that the given options collection contains a 'required' key.

Parameters
array$options
Returns
array

◆ requireDateTime()

Wikimedia\Slimapp\Form::requireDateTime ( $name,
$format,
$options = null )
Parameters
string$nameParameter to require
string$formatExpected date/time format
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireEmail()

Wikimedia\Slimapp\Form::requireEmail ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireEmailArray()

Wikimedia\Slimapp\Form::requireEmailArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireFloat()

Wikimedia\Slimapp\Form::requireFloat ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireFloatArray()

Wikimedia\Slimapp\Form::requireFloatArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireInArray()

Wikimedia\Slimapp\Form::requireInArray ( $name,
$valids,
$options = null )
Parameters
string$nameParameter to require
array$validsValid values
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireInArrayArray()

Wikimedia\Slimapp\Form::requireInArrayArray ( $name,
$valids,
$options = null )
Parameters
string$nameParameter to require
array$validsValid values
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireInt()

Wikimedia\Slimapp\Form::requireInt ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireIntArray()

Wikimedia\Slimapp\Form::requireIntArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireIp()

Wikimedia\Slimapp\Form::requireIp ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireIpArray()

Wikimedia\Slimapp\Form::requireIpArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireRegex()

Wikimedia\Slimapp\Form::requireRegex ( $name,
$re,
$options = null )
Parameters
string$nameParameter to require
string$reRegular expression
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireRegexArray()

Wikimedia\Slimapp\Form::requireRegexArray ( $name,
$re,
$options = null )
Parameters
string$nameParameter to require
string$reRegular expression
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireString()

Wikimedia\Slimapp\Form::requireString ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireStringArray()

Wikimedia\Slimapp\Form::requireStringArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireTrue()

Wikimedia\Slimapp\Form::requireTrue ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireTrueArray()

Wikimedia\Slimapp\Form::requireTrueArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireUrl()

Wikimedia\Slimapp\Form::requireUrl ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ requireUrlArray()

Wikimedia\Slimapp\Form::requireUrlArray ( $name,
$options = null )
Parameters
string$nameParameter to require
array$optionsAdditional options
Returns
Form Self, for message chaining

◆ urlEncode()

static Wikimedia\Slimapp\Form::urlEncode ( $parms)
static

Make a URL-encoded string from a key=>value array.

Parameters
array$parmsParameter array
Returns
string URL-encoded message body

◆ validate()

Wikimedia\Slimapp\Form::validate ( $vars = null)

Validate the provided input data using this form's expectations.

Parameters
array$varsInput to validate (default $_POST)
Returns
bool True if input is valid, false otherwise

◆ wantArray()

static Wikimedia\Slimapp\Form::wantArray ( $options)
staticprotected

Ensure that the given options collection contains a 'flags' key that requires the input to be an array.

Parameters
array$options
Returns
array

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