symfony API

sfValidatorBase Class

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

1.2 API OpenSearch

Packages

You are currently browsing the symfony API for the 1.2 version. Switch to:
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

sfValidatorBase is the base class for all validators.

Method Summary

  • addMessage($name, $value)
    Adds a new error code with a default error message.
  • addOption($name, $value = null)
    Adds a new option value with a default value.
  • addRequiredOption($name)
    Adds a required option.
  • string asString($indent)
    Returns a string representation of this validator.
  • mixed clean($value)
    Cleans the input value.
  • configure($options = array(), $messages = array())
    Configures the current validator.
  • mixed doClean($value)
    Cleans the input value.
  • string getCharset()
    Returns the charset to use when validating strings.
  • array getDefaultMessages()
    Returns default messages for all possible error codes.
  • array getDefaultOptions()
    Returns default option values.
  • mixed getEmptyValue()
    Returns an empty value for this validator.
  • array getErrorCodes()
    Returns an array of all error codes for this validator.
  • string getMessage($name)
    Returns an error message given an error code.
  • array getMessages()
    Returns an array of current error messages.
  • string getMessagesWithoutDefaults()
    Returns all error messages with non default values.
  • mixed getOption($name)
    Gets an option value.
  • array getOptions()
    Returns all options.
  • string getOptionsWithoutDefaults()
    Returns all options with non default values.
  • array getRequiredOptions()
    Returns all required option names.
  • bool hasOption($name)
    Returns true if the option exists.
  • bool isEmpty($value)
    Returns true if the value is empty.
  • setCharset($charset)
    Sets the charset to use when validating strings.
  • setDefaultMessages($messages)
    Sets default messages for all possible error codes.
  • setDefaultOptions($options)
    Sets default option values.
  • setInvalidMessage($message)
    Sets the default invalid message
  • setMessage($name, $value)
    Changes an error message given the error code.
  • setMessages($values)
    Changes all error messages.
  • setOption($name, $value)
    Changes an option value.
  • setOptions($values)
    Changes all options.
  • setRequiredMessage($message)
    Sets the default required message
  • __construct($options = array(), $messages = array())
    Constructor.

Method Details

  • addMessage ($name, $value) Browse code

    $name The error code
    $value The error message

    Adds a new error code with a default error message.

  • addOption ($name, $value = null) Browse code

    $name The option name
    $value The default value

    Adds a new option value with a default value.

  • addRequiredOption ($name) Browse code

    $name The option name

    Adds a required option.

  • (string) asString ($indent) Browse code

    $indent Indentation (number of spaces before each line)

    Returns a string representation of this validator.

    returns The string representation of the validator

  • (mixed) clean ($value) Browse code

    $value The input value

    Cleans the input value.


    This method is also responsible for trimming the input value and checking the required option.

    returns The cleaned value

    throws sfValidatorError

  • configure ($options = array(), $messages = array()) Browse code

    $options An array of options
    $messages An array of error messages

    Configures the current validator.


    This method allows each validator to add options and error messages during validator creation.

    If some options and messages are given in the sfValidatorBase constructor they will take precedence over the options and messages you configure in this method.

  • (mixed) doClean ($value) Browse code

    $value The input value

    Cleans the input value.


    Every subclass must implements this method.

    returns The cleaned value

    throws sfValidatorError

  • (string) getCharset () Browse code

    Returns the charset to use when validating strings.

    returns The charset (default to UTF-8)

  • (array) getDefaultMessages () Browse code

    Returns default messages for all possible error codes.

    returns An array of default error codes and messages

  • (array) getDefaultOptions () Browse code

    Returns default option values.

    returns An array of default option values

  • (mixed) getEmptyValue () Browse code

    Returns an empty value for this validator.

    returns The empty value for this validator

  • (array) getErrorCodes () Browse code

    Returns an array of all error codes for this validator.

    returns An array of possible error codes

  • (string) getMessage ($name) Browse code

    $name The error code

    Returns an error message given an error code.

    returns The error message, or the empty string if the error code does not exist

  • (array) getMessages () Browse code

    Returns an array of current error messages.

    returns An array of messages

  • (string) getMessagesWithoutDefaults () Browse code

    Returns all error messages with non default values.

    returns A string representation of the error messages

  • (mixed) getOption ($name) Browse code

    $name The option name

    Gets an option value.

    returns The option value

  • (array) getOptions () Browse code

    Returns all options.

    returns An array of options

  • (string) getOptionsWithoutDefaults () Browse code

    Returns all options with non default values.

    returns A string representation of the options

  • (array) getRequiredOptions () Browse code

    Returns all required option names.

    returns An array of required option names

  • (bool) hasOption ($name) Browse code

    $name The option name

    Returns true if the option exists.

    returns true if the option exists, false otherwise

  • (bool) isEmpty ($value) Browse code

    $value The input value

    Returns true if the value is empty.

    returns true if the value is empty, false otherwise

  • setCharset ($charset) Browse code

    $charset The charset

    Sets the charset to use when validating strings.

  • setDefaultMessages ($messages) Browse code

    $messages An array of default error codes and messages

    Sets default messages for all possible error codes.

  • setDefaultOptions ($options) Browse code

    $options An array of default option values

    Sets default option values.

  • setInvalidMessage ($message) Browse code

    $message

    Sets the default invalid message

  • setMessage ($name, $value) Browse code

    $name The error code
    $value The error message

    Changes an error message given the error code.

  • setMessages ($values) Browse code

    $values An array of error messages

    Changes all error messages.

  • setOption ($name, $value) Browse code

    $name The option name
    $value The value

    Changes an option value.

  • setOptions ($values) Browse code

    $values An array of options

    Changes all options.

  • setRequiredMessage ($message) Browse code

    $message

    Sets the default required message

  • __construct ($options = array(), $messages = array()) Browse code

    $options An array of options
    $messages An array of error messages

    Constructor.


    Available options:

    * required: true if the value is required, false otherwise (default to true)
    * trim: true if the value must be trimmed, false otherwise (default to false)
    * empty_value: empty value when value is not required

    Available error codes:

    * required * invalid