symfony API

sfValidatorBase Class

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

Packages

You are currently browsing the symfony API for the 1.4 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

  • sfValidatorBase addMessage($name, $value)
    Adds a new error code with a default error message.
  • sfValidatorBase addOption($name, $value)
    Adds a new option value with a default value.
  • sfValidatorBase 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, $messages)
    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.
  • setDefaultMessage($name, $message)
    Sets the default message for a given name.
  • setDefaultMessages($messages)
    Sets default messages for all possible error codes.
  • setDefaultOptions($options)
    Sets default option values.
  • sfValidatorBase setMessage($name, $value)
    Changes an error message given the error code.
  • sfValidatorBase setMessages($values)
    Changes all error messages.
  • sfValidatorBase setOption($name, $value)
    Changes an option value.
  • sfValidatorBase setOptions($values)
    Changes all options.
  • __construct($options, $messages)
    Constructor.

Method Details

  • (sfValidatorBase) addMessage ($name, $value)

    $name The error code
    $value The error message

    Adds a new error code with a default error message.

    returns The current validator instance

  • (sfValidatorBase) addOption ($name, $value)

    $name The option name
    $value The default value

    Adds a new option value with a default value.

    returns The current validator instance

  • (sfValidatorBase) addRequiredOption ($name)

    $name The option name

    Adds a required option.

    returns The current validator instance

  • (string) asString ($indent)

    $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)

    $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, $messages)

    $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)

    $value The input value

    Cleans the input value.


    Every subclass must implements this method.

    returns The cleaned value

    throws sfValidatorError

  • (string) getCharset ()

    Returns the charset to use when validating strings.

    returns The charset (default to UTF-8)

  • (array) getDefaultMessages ()

    Returns default messages for all possible error codes.

    returns An array of default error codes and messages

  • (array) getDefaultOptions ()

    Returns default option values.

    returns An array of default option values

  • (mixed) getEmptyValue ()

    Returns an empty value for this validator.

    returns The empty value for this validator

  • (array) getErrorCodes ()

    Returns an array of all error codes for this validator.

    returns An array of possible error codes

  • (string) getMessage ($name)

    $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 ()

    Returns an array of current error messages.

    returns An array of messages

  • (string) getMessagesWithoutDefaults ()

    Returns all error messages with non default values.

    returns A string representation of the error messages

  • (mixed) getOption ($name)

    $name The option name

    Gets an option value.

    returns The option value

  • (array) getOptions ()

    Returns all options.

    returns An array of options

  • (string) getOptionsWithoutDefaults ()

    Returns all options with non default values.

    returns A string representation of the options

  • (array) getRequiredOptions ()

    Returns all required option names.

    returns An array of required option names

  • (bool) hasOption ($name)

    $name The option name

    Returns true if the option exists.

    returns true if the option exists, false otherwise

  • (bool) isEmpty ($value)

    $value The input value

    Returns true if the value is empty.

    returns true if the value is empty, false otherwise

  • setCharset ($charset)

    $charset The charset

    Sets the charset to use when validating strings.

  • setDefaultMessage ($name, $message)

    $name The name of the message
    $message The default message string

    Sets the default message for a given name.

  • setDefaultMessages ($messages)

    $messages An array of default error codes and messages

    Sets default messages for all possible error codes.

  • setDefaultOptions ($options)

    $options An array of default option values

    Sets default option values.

  • (sfValidatorBase) setMessage ($name, $value)

    $name The error code
    $value The error message

    Changes an error message given the error code.

    returns The current validator instance

  • (sfValidatorBase) setMessages ($values)

    $values An array of error messages

    Changes all error messages.

    returns The current validator instance

  • (sfValidatorBase) setOption ($name, $value)

    $name The option name
    $value The value

    Changes an option value.

    returns The current validator instance

  • (sfValidatorBase) setOptions ($values)

    $values An array of options

    Changes all options.

    returns The current validator instance

  • __construct ($options, $messages)

    $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