Exemple #1
0
 /**
  * Clean up an input variable.
  *
  * @param mixed  $var  The input variable.
  * @param int    $mask Filter bit mask.
  *                      - 1=no trim: If this flag is cleared and the input is a string,
  *                        the string will have leading and trailing whitespace trimmed.
  *                      - 2=allow_raw: If set, no more filtering is performed, higher bits are ignored.
  *                      - 4=allow_html: HTML is allowed, but passed through a safe HTML filter first.
  *                        If set, no more filtering is performed.
  *                      - If no bits other than the 1 bit is set, a strict filter is applied.
  * @param string $type The variable type. See {@link FilterInput::clean()}.
  *
  * @return string
  */
 protected static function cleanVar($var, $mask = 0, $type = null)
 {
     // Static input filters for specific settings
     static $noHtmlFilter = null;
     static $safeHtmlFilter = null;
     // convert $var in array if $type is ARRAY
     if (strtolower($type) === 'array' && !is_array($var)) {
         $var = array($var);
     }
     // If the no trim flag is not set, trim the variable
     if (!($mask & static::MASK_NO_TRIM) && is_string($var)) {
         $var = trim($var);
     }
     // Now we handle input filtering
     // If the allow raw flag is set, do not modify the variable
     if (!($mask & static::MASK_ALLOW_RAW)) {
         if ($mask & static::MASK_ALLOW_HTML) {
             // If the allow html flag is set, apply a safe html filter to the variable
             if (null === $safeHtmlFilter) {
                 $safeHtmlFilter = FilterInput::getInstance(array(), array(), 1, 1);
             }
             $var = $safeHtmlFilter->clean($var, $type);
         } else {
             // Since no allow flags were set, we will apply the most strict filter to the variable
             if (null === $noHtmlFilter) {
                 $noHtmlFilter = FilterInput::getInstance();
             }
             $var = $noHtmlFilter->clean($var, $type);
         }
     }
     return $var;
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->object = FilterInput::getInstance();
 }