Blesta
  • Package
  • Class
  • Tree
  • Deprecated

Packages

  • blesta
    • app
      • components
        • events
          • default
      • controllers
      • models
    • components
      • auth
      • delivery
        • interfax
        • postal
          • methods
      • download
      • email
      • exchange
        • rates
          • foxrate
          • google
            • finance
          • yahoo
            • finance
      • gateway
        • payments
      • gateways
      • invoice
        • delivery
        • templates
      • json
      • modules
      • net
        • http
        • net
          • amazon
            • s3
          • geo
            • ip
      • plugins
      • recaptcha
      • security
      • session
        • cart
      • settingscollection
      • upgrades
      • upload
      • vcard
    • helpers
      • currency
        • format
      • data
        • structure
          • array
          • string
      • text
        • parser
  • com
    • tecnick
      • tcpdf
        • blesta
          • components
            • invoice
              • templates
                • quickbooks
                  • invoice
                • templates
                  • default
  • Crypt
    • AES
    • DES
    • Hash
    • Random
    • RC4
    • Rijndael
    • RSA
    • TerraDES
  • File
    • ANSI
    • ASN1
    • X509
  • Math
    • BigInteger
  • minPHP
    • components
      • input
      • record
    • helpers
      • color
      • data
        • structure
      • date
      • html
      • xml
    • lib
  • Net
    • SFTP
    • SSH1
    • SSH2
  • None
  • PHP
  • PHPMailer
  • Services
    • JSON
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Input

Class Input

Supplies methods useful in verifying and formatting input data. Provides a number of methods to verify whether the input data is formatted correctly. Supports validating both scalar and array data.

Package: minPHP\components\input
Located at components/input/input.php

Methods summary

public static
# isEmail( string $str, boolean $check_record = true )

Checks if the given string is a valid email address

Checks if the given string is a valid email address

Parameters

$str
string
$str The string to test
$check_record
boolean
$check_record True to check DNS/MX record

Retrun

boolean True if the email is valid, false otherwise
public static boolean
# isEmpty( string $str )

Checks if the given string is empty or otherwise not set

Checks if the given string is empty or otherwise not set

Parameters

$str
string
$str The string to test

Returns

boolean
True if the string is empty or not set, false otherwise
public static boolean
# isPassword( string $str, integer $min_length = 6, string $type = "any", string $custom_regex = null )

Tests whether the given string meets the requirements to be considered a password

Tests whether the given string meets the requirements to be considered a password

Parameters

$str
string
$str The string to test
$min_length
integer
$min_length The minimum length of the string
$type
string
$type Types include "any", "any_no_space", "alpha_num", "alpha", "num", and "custom"
$custom_regex
string
$custom_regex Used when $type is set to "custom". Does not use $min_length, any length requirement must be included in the regex

Returns

boolean
True if it meets the given requirements, false otherwise
public static boolean
# isDate( string $str, mixed $min = null, mixed $max = null )

Tests whether the given string is considered a valid date suitable to strtotime()

Tests whether the given string is considered a valid date suitable to strtotime()

Parameters

$str
string
$str The string to test
$min
mixed
$min The minimum acceptable date (string) or unix time stamp (int)
$max
mixed
$min The maximum acceptable date (string) or unix time stamp (int)

Returns

boolean
True if $str is a valid date, false otherwise
public static boolean
# matches( string $str, string $regex )

Tests wether the given string satisfies the given regular expression

Tests wether the given string satisfies the given regular expression

Parameters

$str
string
$str The string to test
$regex
string
$regex The regular expression to satisfy

Returns

boolean
True when the string passes the regex, false otherwise
public static boolean
# compares( mixed $a, string $op, mixed $b )

Tests how the given values compare

Tests how the given values compare

Parameters

$a
mixed
$a The value to compare
$op
string
$op The comparison operator: >, <, >=, <=, ==, ===, !=, !==
$b
mixed
$b The value to compare against

Returns

boolean
True if $a validates $op against $b, false otherwise

Throws

Exception
Thrown when an unrecognized operator, $op, is given
public static boolean
# between( mixed $val, mixed $min, mixed $max, boolean $inclusive = true )

Tests that $val is between $min and $max

Tests that $val is between $min and $max

Parameters

$val
mixed
$val The value to compare
$min
mixed
$min The lower value to compare against
$max
mixed
$max The higher value to compare against
$inclusive
boolean
$inclusive Set to false if $val must be strictly between $min and $max

Returns

boolean
True if $val is between $min and $max, false otherwise
public static boolean
# minLength( string $str, integer $length )

Test whether $str is at least $length bytes

Test whether $str is at least $length bytes

Parameters

$str
string
$str The string to check
$length
integer
$length The number of bytes required in $str

Returns

boolean
True if $str is at least $length bytes
public static boolean
# maxLength( string $str, integer $length )

Test whether $str is no more than $length bytes

Test whether $str is no more than $length bytes

Parameters

$str
string
$str The string to check
$length
integer
$length The number of bytes allowed in $str

Returns

boolean
True if $str is no more than $length bytes
public static boolean
# betweenLength( string $str, integer $min_length, integer $max_length )

Test whether $str is between $min_length and $max_length

Test whether $str is between $min_length and $max_length

Parameters

$str
string
$str The string to check
$min_length
integer
$min_length The number of bytes required in $str
$max_length
integer
$max_length The number of bytes allowed in $str

Returns

boolean
True if $str is between $min_length and $max_length
public
# setRules( array $rules )

Set rules, overriding any existing rules set and empting any existing errors

Set rules, overriding any existing rules set and empting any existing errors

Parameters

$rules
array
$rules A multi-deminsional array, where the 1st dimension is the index value of the data given to Input::validates()

See

Input::validates()
public
# processValidation( mixed $value, string $key, array $var, integer $max_depth = null, integer $cur_depth = 0, array $path = array() )

Invokes Input::validateRule() to process the rule against the given value. This method formatted for use by array_walk_recusrive to process elements recusively.

Invokes Input::validateRule() to process the rule against the given value. This method formatted for use by array_walk_recusrive to process elements recusively.

Parameters

$value
mixed
$value The value to evaluate
$key
string
$key The most immediate key to the given value
$var
array
$var An array containing the full string index of the rule to evaluate ('index') and the complete rule ('rule')
$max_depth
integer
$max_depth The maximum depth to travel
$cur_depth
integer
$cur_depth The current depth traveled
$path
array
$path A list of all array indexes encountered
public boolean
# validates( array & $data )

Validates all set rules using the given data, sets any error messages to Input::$errors Each ruleset attached to a field can have the following indices: rule, message, negate, last, final, pre_format, post_format

Validates all set rules using the given data, sets any error messages to Input::$errors Each ruleset attached to a field can have the following indices: rule, message, negate, last, final, pre_format, post_format

pre_format and post_format accept a typical PHP callback parameter, post_format will only be called if the rule passes validation

Parameters

$data
array
$data An array of data such as POST

Returns

boolean
true if all rules pass, false if any rule is broken

See

Input::errors()
public
# setErrors( array $errors )

Sets the given errors into the object, overriding existing errors (if any)

Sets the given errors into the object, overriding existing errors (if any)

Parameters

$errors
array
$errors An array of errors as returned by Input::errors()

See

Input::errors()
public mixed
# errors( )

Return all errors

Return all errors

Returns

mixed
An array of error messages indexed as their field name, boolean false if no errors set
private
# formatData( mixed $callback, mixed $data, string $key, array $path )

Format Data from Input::validates() with the given $callback

Format Data from Input::validates() with the given $callback

Parameters

$callback
mixed
$callback A string whose function accepts a single parameter, or an array whose format is that of a PHP callback with the addition of optional parameters
$data
mixed
$data The data to be formatted
$key
string
$key The most immediate key to the given value
$path
array
$path A list of all array indexes encountered
private
# validateRule( string $index, array $rule, mixed & $value, string $key, array $path = array() )

Validate the rule against the given index and value, sets any errors into this object's $errors class variable

Validate the rule against the given index and value, sets any errors into this object's $errors class variable

Parameters

$index
string
$index The index set for this rule
$rule
array
$rule the Rule to validate against
$value
mixed
$value The value given by the data element to which the rule is applied
$key
string
$key The most immediate key to the given value
$path
array
$path A list of all array indexes encountered
private static boolean
# array_walk_recursive( array & $input, callable $callback, array $params = null, integer $max_depth = null, integer $cur_depth = 0, array $path = array() )

Emulates the standard array_walk_recursive function, with the added functionality of passing array elements through when no further recusion can be made

Emulates the standard array_walk_recursive function, with the added functionality of passing array elements through when no further recusion can be made

Parameters

$input
array
$input The input array to recurse through
$callback
callable
$callback The callback function to apply to each member of $input
$params
array
$params An array of additional parameters to be passed to the callback
$max_depth
integer
$max_depth The maximum permitted depth to recurse
$cur_depth
integer
$cur_depth The current depth
$path
array
$path A list of all array indexes encountered

Returns

boolean
False if the input is no longer an array and therefore can not be recursed through, true otherwise
private static boolean
# pathSet( mixed $data, mixed $field )

Recursively evaluates whether the path defined by $field is defined in $data

Recursively evaluates whether the path defined by $field is defined in $data

Parameters

$data
mixed
$data An array of data, or a scalar value if the array has been fully traversed
$field
mixed
$field An array defining a path that $data should define, scalar if the array has been fully traversed

Returns

boolean
True if $field is fully defined in $data, false otherwise.
private static
# clearLeaves( mixed & $data )

Recursively sets all leaf elements of the given array to null

Recursively sets all leaf elements of the given array to null

Parameters

$data
mixed
$data An array of data whose leaves to set to null, or a scalar value if the array has been fully traversed

Magic methods summary

Properties summary

private array $errors
#

All errors violated in the Input::validates() method

All errors violated in the Input::validates() method

private array $rules
#

All rules set in Input::setRules()

All rules set in Input::setRules()

private boolean $end_checks
#

Flag whether or not checking should cease

Flag whether or not checking should cease

private mixed $data
#

A set of data that this instance is currently validating

A set of data that this instance is currently validating

Blesta API documentation generated by ApiGen 2.8.0