Zend_Filter_Exception example


    public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader$type)
    {
        $type = strtolower($type);
        switch ($type) {
            case self::FILTER:
            case self::VALIDATE:
                $this->_loaders[$type] = $loader;
                return $this;
            default:
                throw new Zend_Filter_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type));
        }

        return $this;
    }

    /** * Retrieve plugin loader for given type * * $type may be one of: * - filter * - validator * * If a plugin loader does not exist for the given type, defaults are * created. * * @param string $type 'filter' or 'validate' * @return Zend_Loader_PluginLoader_Interface * @throws Zend_Filter_Exception on invalid type */
$class = new ReflectionClass($className);
            if ($class->implementsInterface('Zend_Filter_Interface')) {
                if ($class->hasMethod('__construct')) {
                    $object = $class->newInstanceArgs($args);
                } else {
                    $object = $class->newInstance();
                }
                return $object->filter($value);
            }
        }
        throw new Zend_Filter_Exception("Filter class not found from basename '$classBaseName'");
    }
}
/** * Do the real work, replaces the seperator to search for with the replacement seperator * * Returns the replaced string * * @param string $value * @return string */
    protected function _separatorToSeparatorFilter($value)
    {
        if ($this->_searchSeparator == null) {
            throw new Zend_Filter_Exception('You must provide a search separator for this filter to work.');
        }

        $this->setMatchPattern('#' . preg_quote($this->_searchSeparator, '#') . '#');
        $this->setReplacement($this->_replacementSeparator);
        return parent::filter($value);
    }

}
 else if (!is_array($options) || !array_key_exists('callback', $options)) {
            $options          = func_get_args();
            $temp['callback'] = array_shift($options);
            if (!empty($options)) {
                $temp['options'] = array_shift($options);
            }

            $options = $temp;
        }

        if (!array_key_exists('callback', $options)) {
            throw new Zend_Filter_Exception('Missing callback to use');
        }

        $this->setCallback($options['callback']);
        if (array_key_exists('options', $options)) {
            $this->setOptions($options['options']);
        }
    }

    /** * Returns the set callback * * @return string|array Set callback */

            }

            $type = $detected;
        } else if (is_string($type)) {
            if (in_array($type$this->_constants)) {
                $type = array_search($type$this->_constants);
            }
        }

        if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
            throw new Zend_Filter_Exception('Unknown type');
        }

        $this->_type = $type;
        return $this;
    }

    /** * Defined by Zend_Filter_Interface * * Returns null representation of $value, if value is empty and matches * types that should be considered null. * * @param string $value * @return string */
 elseif (in_array($value$this->_constants)) {
                    $detected += array_search($value$this->_constants);
                }
            }

            $type = $detected;
        } elseif (is_string($type) && in_array($type$this->_constants)) {
            $type = array_search($type$this->_constants);
        }

        if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
            throw new Zend_Filter_Exception('Unknown type');
        }

        $this->_type = $type;
        return $this;
    }

    /** * Returns the set locale * * @return array */
    
$processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = str_replace('\\', '\\\\', $processedPart);
                }
            } elseif (is_string($ruleValue)) {
                $processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = str_replace('\\', '\\\\', $ruleValue);
            }
        }

        // all of the values of processedParts would have been str_replace('\\', '\\\\', ..)'d to disable preg_replace backreferences         $inflectedTarget = preg_replace(array_keys($processedParts)array_values($processedParts)$this->_target);

        if ($this->_throwTargetExceptionsOn && (preg_match('#(?='.$pregQuotedTargetReplacementIdentifier.'[A-Za-z]{1})#', $inflectedTarget) == true)) {
            throw new Zend_Filter_Exception('A replacement identifier ' . $this->_targetReplacementIdentifier . ' was found inside the inflected target, perhaps a rule was not satisfied with a target source? Unsatisfied inflected target: ' . $inflectedTarget);
        }

        return $inflectedTarget;
    }

    /** * Normalize spec string * * @param string $spec * @return string */
    

    public function filter($value)
    {
        $filtered = htmlentities((string) $value$this->getQuoteStyle()$this->getEncoding()$this->getDoubleQuote());
        if (strlen((string) $value) && !strlen($filtered)) {
            if (!function_exists('iconv')) {
                throw new Zend_Filter_Exception('Encoding mismatch has resulted in htmlentities errors');
            }
            $enc      = $this->getEncoding();
            $value    = iconv('', $enc . '//IGNORE', (string) $value);
            $filtered = htmlentities($value$this->getQuoteStyle()$enc$this->getDoubleQuote());
            if (!strlen($filtered)) {
                throw new Zend_Filter_Exception('Encoding mismatch has resulted in htmlentities errors');
            }
        }
        return $filtered;
    }
}
/** * Set the input encoding for the given string * * @param string $encoding * @return Zend_Filter_StringToUpper Provides a fluent interface * @throws Zend_Filter_Exception */
    public function setEncoding($encoding = null)
    {
        if ($encoding !== null) {
            if (!function_exists('mb_strtoupper')) {
                throw new Zend_Filter_Exception('mbstring is required for this feature');
            }

            $encoding = (string) $encoding;
            if (!in_array(strtolower($encoding)array_map('strtolower', mb_list_encodings()))) {
                throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
            }
        }

        $this->_encoding = $encoding;
        return $this;
    }

    
/** * Set the input encoding for the given string * * @param string $encoding * @return Zend_Filter_StringToLower Provides a fluent interface * @throws Zend_Filter_Exception */
    public function setEncoding($encoding = null)
    {
        if ($encoding !== null) {
            if (!function_exists('mb_strtolower')) {
                throw new Zend_Filter_Exception('mbstring is required for this feature');
            }

            $encoding = (string) $encoding;
            if (!in_array(strtolower($encoding)array_map('strtolower', mb_list_encodings()))) {
                throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
            }
        }

        $this->_encoding = $encoding;
        return $this;
    }

    


    /** * Sets a new seperator * * @param string $separator Seperator * @return $this */
    public function setSeparator($separator)
    {
        if ($separator == null) {
            throw new Zend_Filter_Exception('"' . $separator . '" is not a valid separator.');
        }
        $this->_separator = $separator;
        return $this;
    }

    /** * Returns the actual set seperator * * @return string */
    public function getSeparator()
    {


    /** * Perform regexp replacement as filter * * @param string $value * @return string */
    public function filter($value)
    {
        if ($this->_matchPattern == null) {
            throw new Zend_Filter_Exception(get_class($this) . ' does not have a valid MatchPattern set.');
        }

        return preg_replace($this->_matchPattern, $this->_replacement, $value);
    }

}
Home | Imprint | This part of the site doesn't use cookies.