1
0
Fork 0
Dieser Commit ist enthalten in:
DSB 2011-06-10 21:55:32 +00:00
Ursprung 2b21070b1a
Commit f7a7c71f86
1583 geänderte Dateien mit 454759 neuen und 0 gelöschten Zeilen

146
library/Zend/Filter/Alnum.php Normale Datei
Datei anzeigen

@ -0,0 +1,146 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @see Zend_Locale
*/
require_once 'Zend/Locale.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Alnum implements Zend_Filter_Interface
{
/**
* Whether to allow white space characters; off by default
*
* @var boolean
* @deprecated
*/
public $allowWhiteSpace;
/**
* Is PCRE is compiled with UTF-8 and Unicode support
*
* @var mixed
**/
protected static $_unicodeEnabled;
/**
* Locale in browser.
*
* @var Zend_Locale object
*/
protected $_locale;
/**
* The Alphabet means english alphabet.
*
* @var boolean
*/
protected static $_meansEnglishAlphabet;
/**
* Sets default option values for this instance
*
* @param boolean $allowWhiteSpace
* @return void
*/
public function __construct($allowWhiteSpace = false)
{
if ($allowWhiteSpace instanceof Zend_Config) {
$allowWhiteSpace = $allowWhiteSpace->toArray();
} else if (is_array($allowWhiteSpace)) {
if (array_key_exists('allowwhitespace', $allowWhiteSpace)) {
$allowWhiteSpace = $allowWhiteSpace['allowwhitespace'];
} else {
$allowWhiteSpace = false;
}
}
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
if (null === self::$_unicodeEnabled) {
self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
}
if (null === self::$_meansEnglishAlphabet) {
$this->_locale = new Zend_Locale('auto');
self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(),
array('ja', 'ko', 'zh')
);
}
}
/**
* Returns the allowWhiteSpace option
*
* @return boolean
*/
public function getAllowWhiteSpace()
{
return $this->allowWhiteSpace;
}
/**
* Sets the allowWhiteSpace option
*
* @param boolean $allowWhiteSpace
* @return Zend_Filter_Alnum Provides a fluent interface
*/
public function setAllowWhiteSpace($allowWhiteSpace)
{
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value, removing all but alphabetic and digit characters
*
* @param string $value
* @return string
*/
public function filter($value)
{
$whiteSpace = $this->allowWhiteSpace ? '\s' : '';
if (!self::$_unicodeEnabled) {
// POSIX named classes are not supported, use alternative a-zA-Z0-9 match
$pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/';
} else if (self::$_meansEnglishAlphabet) {
//The Alphabet means english alphabet.
$pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/u';
} else {
//The Alphabet means each language's alphabet.
$pattern = '/[^\p{L}\p{N}' . $whiteSpace . ']/u';
}
return preg_replace($pattern, '', (string) $value);
}
}

146
library/Zend/Filter/Alpha.php Normale Datei
Datei anzeigen

@ -0,0 +1,146 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @see Zend_Locale
*/
require_once 'Zend/Locale.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Alpha implements Zend_Filter_Interface
{
/**
* Whether to allow white space characters; off by default
*
* @var boolean
* @deprecated
*/
public $allowWhiteSpace;
/**
* Is PCRE is compiled with UTF-8 and Unicode support
*
* @var mixed
**/
protected static $_unicodeEnabled;
/**
* Locale in browser.
*
* @var Zend_Locale object
*/
protected $_locale;
/**
* The Alphabet means english alphabet.
*
* @var boolean
*/
protected static $_meansEnglishAlphabet;
/**
* Sets default option values for this instance
*
* @param boolean $allowWhiteSpace
* @return void
*/
public function __construct($allowWhiteSpace = false)
{
if ($allowWhiteSpace instanceof Zend_Config) {
$allowWhiteSpace = $allowWhiteSpace->toArray();
} else if (is_array($allowWhiteSpace)) {
if (array_key_exists('allowwhitespace', $allowWhiteSpace)) {
$allowWhiteSpace = $allowWhiteSpace['allowwhitespace'];
} else {
$allowWhiteSpace = false;
}
}
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
if (null === self::$_unicodeEnabled) {
self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
}
if (null === self::$_meansEnglishAlphabet) {
$this->_locale = new Zend_Locale('auto');
self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(),
array('ja', 'ko', 'zh')
);
}
}
/**
* Returns the allowWhiteSpace option
*
* @return boolean
*/
public function getAllowWhiteSpace()
{
return $this->allowWhiteSpace;
}
/**
* Sets the allowWhiteSpace option
*
* @param boolean $allowWhiteSpace
* @return Zend_Filter_Alpha Provides a fluent interface
*/
public function setAllowWhiteSpace($allowWhiteSpace)
{
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value, removing all but alphabetic characters
*
* @param string $value
* @return string
*/
public function filter($value)
{
$whiteSpace = $this->allowWhiteSpace ? '\s' : '';
if (!self::$_unicodeEnabled) {
// POSIX named classes are not supported, use alternative a-zA-Z match
$pattern = '/[^a-zA-Z' . $whiteSpace . ']/';
} else if (self::$_meansEnglishAlphabet) {
//The Alphabet means english alphabet.
$pattern = '/[^a-zA-Z' . $whiteSpace . ']/u';
} else {
//The Alphabet means each language's alphabet.
$pattern = '/[^\p{L}' . $whiteSpace . ']/u';
}
return preg_replace($pattern, '', (string) $value);
}
}

Datei anzeigen

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_BaseName implements Zend_Filter_Interface
{
/**
* Defined by Zend_Filter_Interface
*
* Returns basename($value)
*
* @param string $value
* @return string
*/
public function filter($value)
{
return basename((string) $value);
}
}

Datei anzeigen

@ -0,0 +1,375 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Boolean implements Zend_Filter_Interface
{
const BOOLEAN = 1;
const INTEGER = 2;
const FLOAT = 4;
const STRING = 8;
const ZERO = 16;
const EMPTY_ARRAY = 32;
const NULL = 64;
const PHP = 127;
const FALSE_STRING = 128;
const YES = 256;
const ALL = 511;
protected $_constants = array(
self::BOOLEAN => 'boolean',
self::INTEGER => 'integer',
self::FLOAT => 'float',
self::STRING => 'string',
self::ZERO => 'zero',
self::EMPTY_ARRAY => 'array',
self::NULL => 'null',
self::PHP => 'php',
self::FALSE_STRING => 'false',
self::YES => 'yes',
self::ALL => 'all',
);
/**
* Internal type to detect
*
* @var integer
*/
protected $_type = self::PHP;
/**
* Internal locale
*
* @var array
*/
protected $_locale = array('auto');
/**
* Internal mode
*
* @var boolean
*/
protected $_casting = true;
/**
* Constructor
*
* @param string|array|Zend_Config $options OPTIONAL
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (!is_array($options)) {
$options = func_get_args();
$temp = array();
if (!empty($options)) {
$temp['type'] = array_shift($options);
}
if (!empty($options)) {
$temp['casting'] = array_shift($options);
}
if (!empty($options)) {
$temp['locale'] = array_shift($options);
}
$options = $temp;
}
if (array_key_exists('type', $options)) {
$this->setType($options['type']);
}
if (array_key_exists('casting', $options)) {
$this->setCasting($options['casting']);
}
if (array_key_exists('locale', $options)) {
$this->setLocale($options['locale']);
}
}
/**
* Returns the set null types
*
* @return int
*/
public function getType()
{
return $this->_type;
}
/**
* Set the null types
*
* @param integer|array $type
* @throws Zend_Filter_Exception
* @return Zend_Filter_Boolean
*/
public function setType($type = null)
{
if (is_array($type)) {
$detected = 0;
foreach($type as $value) {
if (is_int($value)) {
$detected += $value;
} 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)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Unknown type');
}
$this->_type = $type;
return $this;
}
/**
* Returns the set locale
*
* @return array
*/
public function getLocale()
{
return $this->_locale;
}
/**
* Set the locales which are accepted
*
* @param string|array|Zend_Locale $locale
* @throws Zend_Filter_Exception
* @return Zend_Filter_Boolean
*/
public function setLocale($locale = null)
{
if (is_string($locale)) {
$locale = array($locale);
} elseif ($locale instanceof Zend_Locale) {
$locale = array($locale->toString());
} elseif (!is_array($locale)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Locale has to be string, array or an instance of Zend_Locale');
}
require_once 'Zend/Locale.php';
foreach ($locale as $single) {
if (!Zend_Locale::isLocale($single)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Unknown locale '$single'");
}
}
$this->_locale = $locale;
return $this;
}
/**
* Returns the casting option
*
* @return boolean
*/
public function getCasting()
{
return $this->_casting;
}
/**
* Set the working mode
*
* @param boolean $locale When true this filter works like cast
* When false it recognises only true and false
* and all other values are returned as is
* @throws Zend_Filter_Exception
* @return Zend_Filter_Boolean
*/
public function setCasting($casting = true)
{
$this->_casting = (boolean) $casting;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns a boolean representation of $value
*
* @param string $value
* @return string
*/
public function filter($value)
{
$type = $this->getType();
$casting = $this->getCasting();
// STRING YES (Localized)
if ($type >= self::YES) {
$type -= self::YES;
if (is_string($value)) {
require_once 'Zend/Locale.php';
$locales = $this->getLocale();
foreach ($locales as $locale) {
if ($this->_getLocalizedQuestion($value, false, $locale) === false) {
return false;
}
if (!$casting && ($this->_getLocalizedQuestion($value, true, $locale) === true)) {
return true;
}
}
}
}
// STRING FALSE ('false')
if ($type >= self::FALSE_STRING) {
$type -= self::FALSE_STRING;
if (is_string($value) && (strtolower($value) == 'false')) {
return false;
}
if ((!$casting) && is_string($value) && (strtolower($value) == 'true')) {
return true;
}
}
// NULL (null)
if ($type >= self::NULL) {
$type -= self::NULL;
if ($value === null) {
return false;
}
}
// EMPTY_ARRAY (array())
if ($type >= self::EMPTY_ARRAY) {
$type -= self::EMPTY_ARRAY;
if (is_array($value) && ($value == array())) {
return false;
}
}
// ZERO ('0')
if ($type >= self::ZERO) {
$type -= self::ZERO;
if (is_string($value) && ($value == '0')) {
return false;
}
if ((!$casting) && (is_string($value)) && ($value == '1')) {
return true;
}
}
// STRING ('')
if ($type >= self::STRING) {
$type -= self::STRING;
if (is_string($value) && ($value == '')) {
return false;
}
}
// FLOAT (0.0)
if ($type >= self::FLOAT) {
$type -= self::FLOAT;
if (is_float($value) && ($value == 0.0)) {
return false;
}
if ((!$casting) && is_float($value) && ($value == 1.0)) {
return true;
}
}
// INTEGER (0)
if ($type >= self::INTEGER) {
$type -= self::INTEGER;
if (is_int($value) && ($value == 0)) {
return false;
}
if ((!$casting) && is_int($value) && ($value == 1)) {
return true;
}
}
// BOOLEAN (false)
if ($type >= self::BOOLEAN) {
$type -= self::BOOLEAN;
if (is_bool($value)) {
return $value;
}
}
if ($casting) {
return true;
}
return $value;
}
/**
* Determine the value of a localized string, and compare it to a given value
*
* @param string $value
* @param boolean $yes
* @param array $locale
* @return boolean
*/
protected function _getLocalizedQuestion($value, $yes, $locale)
{
if ($yes == true) {
$question = 'yes';
$return = true;
} else {
$question = 'no';
$return = false;
}
$str = Zend_Locale::getTranslation($question, 'question', $locale);
$str = explode(':', $str);
if (!empty($str)) {
foreach($str as $no) {
if (($no == $value) || (strtolower($no) == strtolower($value))) {
return $return;
}
}
}
}
}

Datei anzeigen

@ -0,0 +1,152 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Callback implements Zend_Filter_Interface
{
/**
* Callback in a call_user_func format
*
* @var string|array
*/
protected $_callback = null;
/**
* Default options to set for the filter
*
* @var mixed
*/
protected $_options = null;
/**
* Constructor
*
* @param string|array $callback Callback in a call_user_func format
* @param mixed $options (Optional) Default options for this filter
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} 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)) {
require_once 'Zend/Filter/Exception.php';
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
*/
public function getCallback()
{
return $this->_callback;
}
/**
* Sets a new callback for this filter
*
* @param unknown_type $callback
* @return unknown
*/
public function setCallback($callback, $options = null)
{
if (!is_callable($callback)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Callback can not be accessed');
}
$this->_callback = $callback;
$this->setOptions($options);
return $this;
}
/**
* Returns the set default options
*
* @return mixed
*/
public function getOptions()
{
return $this->_options;
}
/**
* Sets new default options to the callback filter
*
* @param mixed $options Default options to set
* @return Zend_Filter_Callback
*/
public function setOptions($options)
{
$this->_options = $options;
return $this;
}
/**
* Calls the filter per callback
*
* @param mixed $value Options for the set callback
* @return mixed Result from the filter which was callbacked
*/
public function filter($value)
{
$options = array();
if ($this->_options !== null) {
if (!is_array($this->_options)) {
$options = array($this->_options);
} else {
$options = $this->_options;
}
}
array_unshift($options, $value);
return call_user_func_array($this->_callback, $options);
}
}

Datei anzeigen

@ -0,0 +1,197 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* Compresses a given string
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Compress implements Zend_Filter_Interface
{
/**
* Compression adapter
*/
protected $_adapter = 'Gz';
/**
* Compression adapter constructor options
*/
protected $_adapterOptions = array();
/**
* Class constructor
*
* @param string|array $options (Optional) Options to set
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (is_string($options)) {
$this->setAdapter($options);
} elseif ($options instanceof Zend_Filter_Compress_CompressInterface) {
$this->setAdapter($options);
} elseif (is_array($options)) {
$this->setOptions($options);
}
}
/**
* Set filter setate
*
* @param array $options
* @return Zend_Filter_Compress
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
if ($key == 'options') {
$key = 'adapterOptions';
}
$method = 'set' . ucfirst($key);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Returns the current adapter, instantiating it if necessary
*
* @return string
*/
public function getAdapter()
{
if ($this->_adapter instanceof Zend_Filter_Compress_CompressInterface) {
return $this->_adapter;
}
$adapter = $this->_adapter;
$options = $this->getAdapterOptions();
if (!class_exists($adapter)) {
require_once 'Zend/Loader.php';
if (Zend_Loader::isReadable('Zend/Filter/Compress/' . ucfirst($adapter) . '.php')) {
$adapter = 'Zend_Filter_Compress_' . ucfirst($adapter);
}
Zend_Loader::loadClass($adapter);
}
$this->_adapter = new $adapter($options);
if (!$this->_adapter instanceof Zend_Filter_Compress_CompressInterface) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Compression adapter '" . $adapter . "' does not implement Zend_Filter_Compress_CompressInterface");
}
return $this->_adapter;
}
/**
* Retrieve adapter name
*
* @return string
*/
public function getAdapterName()
{
return $this->getAdapter()->toString();
}
/**
* Sets compression adapter
*
* @param string|Zend_Filter_Compress_CompressInterface $adapter Adapter to use
* @return Zend_Filter_Compress
*/
public function setAdapter($adapter)
{
if ($adapter instanceof Zend_Filter_Compress_CompressInterface) {
$this->_adapter = $adapter;
return $this;
}
if (!is_string($adapter)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Invalid adapter provided; must be string or instance of Zend_Filter_Compress_CompressInterface');
}
$this->_adapter = $adapter;
return $this;
}
/**
* Retrieve adapter options
*
* @return array
*/
public function getAdapterOptions()
{
return $this->_adapterOptions;
}
/**
* Set adapter options
*
* @param array $options
* @return void
*/
public function setAdapterOptions(array $options)
{
$this->_adapterOptions = $options;
return $this;
}
/**
* Calls adapter methods
*
* @param string $method Method to call
* @param string|array $options Options for this method
*/
public function __call($method, $options)
{
$adapter = $this->getAdapter();
if (!method_exists($adapter, $method)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Unknown method '{$method}'");
}
return call_user_func_array(array($adapter, $method), $options);
}
/**
* Defined by Zend_Filter_Interface
*
* Compresses the content $value with the defined settings
*
* @param string $value Content to compress
* @return string The compressed content
*/
public function filter($value)
{
return $this->getAdapter()->compress($value);
}
}

Datei anzeigen

@ -0,0 +1,188 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress_CompressAbstract
*/
require_once 'Zend/Filter/Compress/CompressAbstract.php';
/**
* Compression adapter for Bz2
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Compress_Bz2 extends Zend_Filter_Compress_CompressAbstract
{
/**
* Compression Options
* array(
* 'blocksize' => Blocksize to use from 0-9
* 'archive' => Archive to use
* )
*
* @var array
*/
protected $_options = array(
'blocksize' => 4,
'archive' => null,
);
/**
* Class constructor
*
* @param array|Zend_Config $options (Optional) Options to set
*/
public function __construct($options = null)
{
if (!extension_loaded('bz2')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs the bz2 extension');
}
parent::__construct($options);
}
/**
* Returns the set blocksize
*
* @return integer
*/
public function getBlocksize()
{
return $this->_options['blocksize'];
}
/**
* Sets a new blocksize
*
* @param integer $level
* @return Zend_Filter_Compress_Bz2
*/
public function setBlocksize($blocksize)
{
if (($blocksize < 0) || ($blocksize > 9)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Blocksize must be between 0 and 9');
}
$this->_options['blocksize'] = (int) $blocksize;
return $this;
}
/**
* Returns the set archive
*
* @return string
*/
public function getArchive()
{
return $this->_options['archive'];
}
/**
* Sets the archive to use for de-/compression
*
* @param string $archive Archive to use
* @return Zend_Filter_Compress_Bz2
*/
public function setArchive($archive)
{
$this->_options['archive'] = (string) $archive;
return $this;
}
/**
* Compresses the given content
*
* @param string $content
* @return string
*/
public function compress($content)
{
$archive = $this->getArchive();
if (!empty($archive)) {
$file = bzopen($archive, 'w');
if (!$file) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Error opening the archive '" . $archive . "'");
}
bzwrite($file, $content);
bzclose($file);
$compressed = true;
} else {
$compressed = bzcompress($content, $this->getBlocksize());
}
if (is_int($compressed)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error during compression');
}
return $compressed;
}
/**
* Decompresses the given content
*
* @param string $content
* @return string
*/
public function decompress($content)
{
$archive = $this->getArchive();
if (file_exists($content)) {
$archive = $content;
}
if (file_exists($archive)) {
$file = bzopen($archive, 'r');
if (!$file) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Error opening the archive '" . $content . "'");
}
$compressed = bzread($file);
bzclose($file);
} else {
$compressed = bzdecompress($content);
}
if (is_int($compressed)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error during decompression');
}
return $compressed;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Bz2';
}
}

Datei anzeigen

@ -0,0 +1,89 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress_CompressInterface
*/
require_once 'Zend/Filter/Compress/CompressInterface.php';
/**
* Abstract compression adapter
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Filter_Compress_CompressAbstract implements Zend_Filter_Compress_CompressInterface
{
/**
* Class constructor
*
* @param array|Zend_Config $options (Optional) Options to set
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (is_array($options)) {
$this->setOptions($options);
}
}
/**
* Returns one or all set options
*
* @param string $option (Optional) Option to return
* @return mixed
*/
public function getOptions($option = null)
{
if ($option === null) {
return $this->_options;
}
if (!array_key_exists($option, $this->_options)) {
return null;
}
return $this->_options[$option];
}
/**
* Sets all or one option
*
* @param array $options
* @return Zend_Filter_Compress_Bz2
*/
public function setOptions(array $options)
{
foreach ($options as $key => $option) {
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($option);
}
}
return $this;
}
}

Datei anzeigen

@ -0,0 +1,54 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Compression interface
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Filter_Compress_CompressInterface
{
/**
* Compresses $value with the defined settings
*
* @param string $value Data to compress
* @return string The compressed data
*/
public function compress($value);
/**
* Decompresses $value with the defined settings
*
* @param string $value Data to decompress
* @return string The decompressed data
*/
public function decompress($value);
/**
* Return the adapter name
*
* @return string
*/
public function toString();
}

Datei anzeigen

@ -0,0 +1,228 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress_CompressAbstract
*/
require_once 'Zend/Filter/Compress/CompressAbstract.php';
/**
* Compression adapter for Gzip (ZLib)
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Compress_Gz extends Zend_Filter_Compress_CompressAbstract
{
/**
* Compression Options
* array(
* 'level' => Compression level 0-9
* 'mode' => Compression mode, can be 'compress', 'deflate'
* 'archive' => Archive to use
* )
*
* @var array
*/
protected $_options = array(
'level' => 9,
'mode' => 'compress',
'archive' => null,
);
/**
* Class constructor
*
* @param array|Zend_Config|null $options (Optional) Options to set
*/
public function __construct($options = null)
{
if (!extension_loaded('zlib')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs the zlib extension');
}
parent::__construct($options);
}
/**
* Returns the set compression level
*
* @return integer
*/
public function getLevel()
{
return $this->_options['level'];
}
/**
* Sets a new compression level
*
* @param integer $level
* @return Zend_Filter_Compress_Gz
*/
public function setLevel($level)
{
if (($level < 0) || ($level > 9)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Level must be between 0 and 9');
}
$this->_options['level'] = (int) $level;
return $this;
}
/**
* Returns the set compression mode
*
* @return string
*/
public function getMode()
{
return $this->_options['mode'];
}
/**
* Sets a new compression mode
*
* @param string $mode Supported are 'compress', 'deflate' and 'file'
*/
public function setMode($mode)
{
if (($mode != 'compress') && ($mode != 'deflate')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Given compression mode not supported');
}
$this->_options['mode'] = $mode;
return $this;
}
/**
* Returns the set archive
*
* @return string
*/
public function getArchive()
{
return $this->_options['archive'];
}
/**
* Sets the archive to use for de-/compression
*
* @param string $archive Archive to use
* @return Zend_Filter_Compress_Gz
*/
public function setArchive($archive)
{
$this->_options['archive'] = (string) $archive;
return $this;
}
/**
* Compresses the given content
*
* @param string $content
* @return string
*/
public function compress($content)
{
$archive = $this->getArchive();
if (!empty($archive)) {
$file = gzopen($archive, 'w' . $this->getLevel());
if (!$file) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Error opening the archive '" . $this->_options['archive'] . "'");
}
gzwrite($file, $content);
gzclose($file);
$compressed = true;
} else if ($this->_options['mode'] == 'deflate') {
$compressed = gzdeflate($content, $this->getLevel());
} else {
$compressed = gzcompress($content, $this->getLevel());
}
if (!$compressed) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error during compression');
}
return $compressed;
}
/**
* Decompresses the given content
*
* @param string $content
* @return string
*/
public function decompress($content)
{
$archive = $this->getArchive();
$mode = $this->getMode();
if (file_exists($content)) {
$archive = $content;
}
if (file_exists($archive)) {
$handler = fopen($archive, "rb");
if (!$handler) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Error opening the archive '" . $archive . "'");
}
fseek($handler, -4, SEEK_END);
$packet = fread($handler, 4);
$bytes = unpack("V", $packet);
$size = end($bytes);
fclose($handler);
$file = gzopen($archive, 'r');
$compressed = gzread($file, $size);
gzclose($file);
} else if ($mode == 'deflate') {
$compressed = gzinflate($content);
} else {
$compressed = gzuncompress($content);
}
if (!$compressed) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error during compression');
}
return $compressed;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Gz';
}
}

Datei anzeigen

@ -0,0 +1,91 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress_CompressInterface
*/
require_once 'Zend/Filter/Compress/CompressInterface.php';
/**
* Compression adapter for Lzf
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Compress_Lzf implements Zend_Filter_Compress_CompressInterface
{
/**
* Class constructor
*/
public function __construct()
{
if (!extension_loaded('lzf')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs the lzf extension');
}
}
/**
* Compresses the given content
*
* @param string $content
* @return string
*/
public function compress($content)
{
$compressed = lzf_compress($content);
if (!$compressed) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error during compression');
}
return $compressed;
}
/**
* Decompresses the given content
*
* @param string $content
* @return string
*/
public function decompress($content)
{
$compressed = lzf_decompress($content);
if (!$compressed) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error during compression');
}
return $compressed;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Lzf';
}
}

Datei anzeigen

@ -0,0 +1,252 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress_CompressAbstract
*/
require_once 'Zend/Filter/Compress/CompressAbstract.php';
/**
* Compression adapter for Rar
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Compress_Rar extends Zend_Filter_Compress_CompressAbstract
{
/**
* Compression Options
* array(
* 'callback' => Callback for compression
* 'archive' => Archive to use
* 'password' => Password to use
* 'target' => Target to write the files to
* )
*
* @var array
*/
protected $_options = array(
'callback' => null,
'archive' => null,
'password' => null,
'target' => '.',
);
/**
* Class constructor
*
* @param array $options (Optional) Options to set
*/
public function __construct($options = null)
{
if (!extension_loaded('rar')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs the rar extension');
}
parent::__construct($options);
}
/**
* Returns the set callback for compression
*
* @return string
*/
public function getCallback()
{
return $this->_options['callback'];
}
/**
* Sets the callback to use
*
* @param string $callback
* @return Zend_Filter_Compress_Rar
*/
public function setCallback($callback)
{
if (!is_callable($callback)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Callback can not be accessed');
}
$this->_options['callback'] = $callback;
return $this;
}
/**
* Returns the set archive
*
* @return string
*/
public function getArchive()
{
return $this->_options['archive'];
}
/**
* Sets the archive to use for de-/compression
*
* @param string $archive Archive to use
* @return Zend_Filter_Compress_Rar
*/
public function setArchive($archive)
{
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $archive);
$this->_options['archive'] = (string) $archive;
return $this;
}
/**
* Returns the set password
*
* @return string
*/
public function getPassword()
{
return $this->_options['password'];
}
/**
* Sets the password to use
*
* @param string $password
* @return Zend_Filter_Compress_Rar
*/
public function setPassword($password)
{
$this->_options['password'] = (string) $password;
return $this;
}
/**
* Returns the set targetpath
*
* @return string
*/
public function getTarget()
{
return $this->_options['target'];
}
/**
* Sets the targetpath to use
*
* @param string $target
* @return Zend_Filter_Compress_Rar
*/
public function setTarget($target)
{
if (!file_exists(dirname($target))) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The directory '$target' does not exist");
}
$target = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $target);
$this->_options['target'] = (string) $target;
return $this;
}
/**
* Compresses the given content
*
* @param string|array $content
* @return string
*/
public function compress($content)
{
$callback = $this->getCallback();
if ($callback === null) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('No compression callback available');
}
$options = $this->getOptions();
unset($options['callback']);
$result = call_user_func($callback, $options, $content);
if ($result !== true) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error compressing the RAR Archive');
}
return $this->getArchive();
}
/**
* Decompresses the given content
*
* @param string $content
* @return boolean
*/
public function decompress($content)
{
$archive = $this->getArchive();
if (file_exists($content)) {
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content));
} elseif (empty($archive) || !file_exists($archive)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('RAR Archive not found');
}
$password = $this->getPassword();
if ($password !== null) {
$archive = rar_open($archive, $password);
} else {
$archive = rar_open($archive);
}
if (!$archive) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Error opening the RAR Archive");
}
$target = $this->getTarget();
if (!is_dir($target)) {
$target = dirname($target);
}
$filelist = rar_list($archive);
if (!$filelist) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Error reading the RAR Archive");
}
foreach($filelist as $file) {
$file->extract($target);
}
rar_close($archive);
return true;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Rar';
}
}

Datei anzeigen

@ -0,0 +1,245 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress_CompressAbstract
*/
require_once 'Zend/Filter/Compress/CompressAbstract.php';
/**
* Compression adapter for Tar
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Compress_Tar extends Zend_Filter_Compress_CompressAbstract
{
/**
* Compression Options
* array(
* 'archive' => Archive to use
* 'target' => Target to write the files to
* )
*
* @var array
*/
protected $_options = array(
'archive' => null,
'target' => '.',
'mode' => null,
);
/**
* Class constructor
*
* @param array $options (Optional) Options to set
*/
public function __construct($options = null)
{
if (!class_exists('Archive_Tar')) {
require_once 'Zend/Loader.php';
try {
Zend_Loader::loadClass('Archive_Tar');
} catch (Zend_Exception $e) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs PEARs Archive_Tar', 0, $e);
}
}
parent::__construct($options);
}
/**
* Returns the set archive
*
* @return string
*/
public function getArchive()
{
return $this->_options['archive'];
}
/**
* Sets the archive to use for de-/compression
*
* @param string $archive Archive to use
* @return Zend_Filter_Compress_Tar
*/
public function setArchive($archive)
{
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $archive);
$this->_options['archive'] = (string) $archive;
return $this;
}
/**
* Returns the set targetpath
*
* @return string
*/
public function getTarget()
{
return $this->_options['target'];
}
/**
* Sets the targetpath to use
*
* @param string $target
* @return Zend_Filter_Compress_Tar
*/
public function setTarget($target)
{
if (!file_exists(dirname($target))) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The directory '$target' does not exist");
}
$target = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $target);
$this->_options['target'] = (string) $target;
return $this;
}
/**
* Returns the set compression mode
*/
public function getMode()
{
return $this->_options['mode'];
}
/**
* Compression mode to use
* Eighter Gz or Bz2
*
* @param string $mode
*/
public function setMode($mode)
{
$mode = ucfirst(strtolower($mode));
if (($mode != 'Bz2') && ($mode != 'Gz')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The mode '$mode' is unknown");
}
if (($mode == 'Bz2') && (!extension_loaded('bz2'))) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This mode needs the bz2 extension');
}
if (($mode == 'Gz') && (!extension_loaded('zlib'))) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This mode needs the zlib extension');
}
}
/**
* Compresses the given content
*
* @param string $content
* @return string
*/
public function compress($content)
{
$archive = new Archive_Tar($this->getArchive(), $this->getMode());
if (!file_exists($content)) {
$file = $this->getTarget();
if (is_dir($file)) {
$file .= DIRECTORY_SEPARATOR . "tar.tmp";
}
$result = file_put_contents($file, $content);
if ($result === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error creating the temporary file');
}
$content = $file;
}
if (is_dir($content)) {
// collect all file infos
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($content, RecursiveDirectoryIterator::KEY_AS_PATHNAME),
RecursiveIteratorIterator::SELF_FIRST
) as $directory => $info
) {
if ($info->isFile()) {
$file[] = $directory;
}
}
$content = $file;
}
$result = $archive->create($content);
if ($result === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error creating the Tar archive');
}
return $this->getArchive();
}
/**
* Decompresses the given content
*
* @param string $content
* @return boolean
*/
public function decompress($content)
{
$archive = $this->getArchive();
if (file_exists($content)) {
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content));
} elseif (empty($archive) || !file_exists($archive)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Tar Archive not found');
}
$archive = new Archive_Tar($archive, $this->getMode());
$target = $this->getTarget();
if (!is_dir($target)) {
$target = dirname($target);
}
$result = $archive->extract($target);
if ($result === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Error while extracting the Tar archive');
}
return true;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Tar';
}
}

Datei anzeigen

@ -0,0 +1,355 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress_CompressAbstract
*/
require_once 'Zend/Filter/Compress/CompressAbstract.php';
/**
* Compression adapter for zip
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Compress_Zip extends Zend_Filter_Compress_CompressAbstract
{
/**
* Compression Options
* array(
* 'archive' => Archive to use
* 'password' => Password to use
* 'target' => Target to write the files to
* )
*
* @var array
*/
protected $_options = array(
'archive' => null,
'target' => null,
);
/**
* Class constructor
*
* @param string|array $options (Optional) Options to set
*/
public function __construct($options = null)
{
if (!extension_loaded('zip')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs the zip extension');
}
parent::__construct($options);
}
/**
* Returns the set archive
*
* @return string
*/
public function getArchive()
{
return $this->_options['archive'];
}
/**
* Sets the archive to use for de-/compression
*
* @param string $archive Archive to use
* @return Zend_Filter_Compress_Rar
*/
public function setArchive($archive)
{
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $archive);
$this->_options['archive'] = (string) $archive;
return $this;
}
/**
* Returns the set targetpath
*
* @return string
*/
public function getTarget()
{
return $this->_options['target'];
}
/**
* Sets the target to use
*
* @param string $target
* @return Zend_Filter_Compress_Rar
*/
public function setTarget($target)
{
if (!file_exists(dirname($target))) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The directory '$target' does not exist");
}
$target = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $target);
$this->_options['target'] = (string) $target;
return $this;
}
/**
* Compresses the given content
*
* @param string $content
* @return string Compressed archive
*/
public function compress($content)
{
$zip = new ZipArchive();
$res = $zip->open($this->getArchive(), ZipArchive::CREATE | ZipArchive::OVERWRITE);
if ($res !== true) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception($this->_errorString($res));
}
if (file_exists($content)) {
$content = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content));
$basename = substr($content, strrpos($content, DIRECTORY_SEPARATOR) + 1);
if (is_dir($content)) {
$index = strrpos($content, DIRECTORY_SEPARATOR) + 1;
$content .= DIRECTORY_SEPARATOR;
$stack = array($content);
while (!empty($stack)) {
$current = array_pop($stack);
$files = array();
$dir = dir($current);
while (false !== ($node = $dir->read())) {
if (($node == '.') || ($node == '..')) {
continue;
}
if (is_dir($current . $node)) {
array_push($stack, $current . $node . DIRECTORY_SEPARATOR);
}
if (is_file($current . $node)) {
$files[] = $node;
}
}
$local = substr($current, $index);
$zip->addEmptyDir(substr($local, 0, -1));
foreach ($files as $file) {
$zip->addFile($current . $file, $local . $file);
if ($res !== true) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception($this->_errorString($res));
}
}
}
} else {
$res = $zip->addFile($content, $basename);
if ($res !== true) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception($this->_errorString($res));
}
}
} else {
$file = $this->getTarget();
if (!is_dir($file)) {
$file = basename($file);
} else {
$file = "zip.tmp";
}
$res = $zip->addFromString($file, $content);
if ($res !== true) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception($this->_errorString($res));
}
}
$zip->close();
return $this->_options['archive'];
}
/**
* Decompresses the given content
*
* @param string $content
* @return string
*/
public function decompress($content)
{
$archive = $this->getArchive();
if (file_exists($content)) {
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content));
} elseif (empty($archive) || !file_exists($archive)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('ZIP Archive not found');
}
$zip = new ZipArchive();
$res = $zip->open($archive);
$target = $this->getTarget();
if (!empty($target) && !is_dir($target)) {
$target = dirname($target);
}
if (!empty($target)) {
$target = rtrim($target, '/\\') . DIRECTORY_SEPARATOR;
}
if (empty($target) || !is_dir($target)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('No target for ZIP decompression set');
}
if ($res !== true) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception($this->_errorString($res));
}
if (version_compare(PHP_VERSION, '5.2.8', '<')) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$statIndex = $zip->statIndex($i);
$currName = $statIndex['name'];
if (($currName{0} == '/') ||
(substr($currName, 0, 2) == '..') ||
(substr($currName, 0, 4) == './..')
)
{
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Upward directory traversal was detected inside ' . $archive
. ' please use PHP 5.2.8 or greater to take advantage of path resolution features of '
. 'the zip extension in this decompress() method.'
);
}
}
}
$res = @$zip->extractTo($target);
if ($res !== true) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception($this->_errorString($res));
}
$zip->close();
return $target;
}
/**
* Returns the proper string based on the given error constant
*
* @param string $error
*/
protected function _errorString($error)
{
switch($error) {
case ZipArchive::ER_MULTIDISK :
return 'Multidisk ZIP Archives not supported';
case ZipArchive::ER_RENAME :
return 'Failed to rename the temporary file for ZIP';
case ZipArchive::ER_CLOSE :
return 'Failed to close the ZIP Archive';
case ZipArchive::ER_SEEK :
return 'Failure while seeking the ZIP Archive';
case ZipArchive::ER_READ :
return 'Failure while reading the ZIP Archive';
case ZipArchive::ER_WRITE :
return 'Failure while writing the ZIP Archive';
case ZipArchive::ER_CRC :
return 'CRC failure within the ZIP Archive';
case ZipArchive::ER_ZIPCLOSED :
return 'ZIP Archive already closed';
case ZipArchive::ER_NOENT :
return 'No such file within the ZIP Archive';
case ZipArchive::ER_EXISTS :
return 'ZIP Archive already exists';
case ZipArchive::ER_OPEN :
return 'Can not open ZIP Archive';
case ZipArchive::ER_TMPOPEN :
return 'Failure creating temporary ZIP Archive';
case ZipArchive::ER_ZLIB :
return 'ZLib Problem';
case ZipArchive::ER_MEMORY :
return 'Memory allocation problem while working on a ZIP Archive';
case ZipArchive::ER_CHANGED :
return 'ZIP Entry has been changed';
case ZipArchive::ER_COMPNOTSUPP :
return 'Compression method not supported within ZLib';
case ZipArchive::ER_EOF :
return 'Premature EOF within ZIP Archive';
case ZipArchive::ER_INVAL :
return 'Invalid argument for ZLIB';
case ZipArchive::ER_NOZIP :
return 'Given file is no zip archive';
case ZipArchive::ER_INTERNAL :
return 'Internal error while working on a ZIP Archive';
case ZipArchive::ER_INCONS :
return 'Inconsistent ZIP archive';
case ZipArchive::ER_REMOVE :
return 'Can not remove ZIP Archive';
case ZipArchive::ER_DELETED :
return 'ZIP Entry has been deleted';
default :
return 'Unknown error within ZIP Archive';
}
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Zip';
}
}

Datei anzeigen

@ -0,0 +1,49 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Compress
*/
require_once 'Zend/Filter/Compress.php';
/**
* Decompresses a given string
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Decompress extends Zend_Filter_Compress
{
/**
* Defined by Zend_Filter_Interface
*
* Decompresses the content $value with the defined settings
*
* @param string $value Content to decompress
* @return string The decompressed content
*/
public function filter($value)
{
return $this->getAdapter()->decompress($value);
}
}

Datei anzeigen

@ -0,0 +1,49 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Encrypt
*/
require_once 'Zend/Filter/Encrypt.php';
/**
* Decrypts a given string
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Decrypt extends Zend_Filter_Encrypt
{
/**
* Defined by Zend_Filter_Interface
*
* Decrypts the content $value with the defined settings
*
* @param string $value Content to decrypt
* @return string The decrypted content
*/
public function filter($value)
{
return $this->_adapter->decrypt($value);
}
}

Datei anzeigen

@ -0,0 +1,82 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Digits implements Zend_Filter_Interface
{
/**
* Is PCRE is compiled with UTF-8 and Unicode support
*
* @var mixed
**/
protected static $_unicodeEnabled;
/**
* Class constructor
*
* Checks if PCRE is compiled with UTF-8 and Unicode support
*
* @return void
*/
public function __construct()
{
if (null === self::$_unicodeEnabled) {
self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
}
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value, removing all but digit characters
*
* @param string $value
* @return string
*/
public function filter($value)
{
if (!self::$_unicodeEnabled) {
// POSIX named classes are not supported, use alternative 0-9 match
$pattern = '/[^0-9]/';
} else if (extension_loaded('mbstring')) {
// Filter for the value with mbstring
$pattern = '/[^[:digit:]]/';
} else {
// Filter for the value without mbstring
$pattern = '/[\p{^N}]/';
}
return preg_replace($pattern, '', (string) $value);
}
}

50
library/Zend/Filter/Dir.php Normale Datei
Datei anzeigen

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Dir implements Zend_Filter_Interface
{
/**
* Defined by Zend_Filter_Interface
*
* Returns dirname($value)
*
* @param string $value
* @return string
*/
public function filter($value)
{
return dirname((string) $value);
}
}

Datei anzeigen

@ -0,0 +1,138 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* Encrypts a given string
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Encrypt implements Zend_Filter_Interface
{
/**
* Encryption adapter
*/
protected $_adapter;
/**
* Class constructor
*
* @param string|array $options (Optional) Options to set, if null mcrypt is used
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
$this->setAdapter($options);
}
/**
* Returns the name of the set adapter
*
* @return string
*/
public function getAdapter()
{
return $this->_adapter->toString();
}
/**
* Sets new encryption options
*
* @param string|array $options (Optional) Encryption options
* @return Zend_Filter_Encrypt
*/
public function setAdapter($options = null)
{
if (is_string($options)) {
$adapter = $options;
} else if (isset($options['adapter'])) {
$adapter = $options['adapter'];
unset($options['adapter']);
} else {
$adapter = 'Mcrypt';
}
if (!is_array($options)) {
$options = array();
}
if (Zend_Loader::isReadable('Zend/Filter/Encrypt/' . ucfirst($adapter). '.php')) {
$adapter = 'Zend_Filter_Encrypt_' . ucfirst($adapter);
}
if (!class_exists($adapter)) {
Zend_Loader::loadClass($adapter);
}
$this->_adapter = new $adapter($options);
if (!$this->_adapter instanceof Zend_Filter_Encrypt_Interface) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Encoding adapter '" . $adapter . "' does not implement Zend_Filter_Encrypt_Interface");
}
return $this;
}
/**
* Calls adapter methods
*
* @param string $method Method to call
* @param string|array $options Options for this method
*/
public function __call($method, $options)
{
$part = substr($method, 0, 3);
if ((($part != 'get') and ($part != 'set')) or !method_exists($this->_adapter, $method)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Unknown method '{$method}'");
}
return call_user_func_array(array($this->_adapter, $method), $options);
}
/**
* Defined by Zend_Filter_Interface
*
* Encrypts the content $value with the defined settings
*
* @param string $value Content to encrypt
* @return string The encrypted content
*/
public function filter($value)
{
return $this->_adapter->encrypt($value);
}
}

Datei anzeigen

@ -0,0 +1,47 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Encryption interface
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Filter_Encrypt_Interface
{
/**
* Encrypts $value with the defined settings
*
* @param string $value Data to encrypt
* @return string The encrypted data
*/
public function encrypt($value);
/**
* Decrypts $value with the defined settings
*
* @param string $value Data to decrypt
* @return string The decrypted data
*/
public function decrypt($value);
}

Datei anzeigen

@ -0,0 +1,364 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Encrypt_Interface
*/
require_once 'Zend/Filter/Encrypt/Interface.php';
/**
* Encryption adapter for mcrypt
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
{
/**
* Definitions for encryption
* array(
* 'key' => encryption key string
* 'algorithm' => algorithm to use
* 'algorithm_directory' => directory where to find the algorithm
* 'mode' => encryption mode to use
* 'modedirectory' => directory where to find the mode
* )
*/
protected $_encryption = array(
'key' => 'ZendFramework',
'algorithm' => 'blowfish',
'algorithm_directory' => '',
'mode' => 'cbc',
'mode_directory' => '',
'vector' => null,
'salt' => false
);
/**
* Internal compression
*
* @var array
*/
protected $_compression;
protected static $_srandCalled = false;
/**
* Class constructor
*
* @param string|array|Zend_Config $options Cryption Options
*/
public function __construct($options)
{
if (!extension_loaded('mcrypt')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs the mcrypt extension');
}
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_string($options)) {
$options = array('key' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Invalid options argument provided to filter');
}
if (array_key_exists('compression', $options)) {
$this->setCompression($options['compression']);
unset($options['compress']);
}
$this->setEncryption($options);
}
/**
* Returns the set encryption options
*
* @return array
*/
public function getEncryption()
{
return $this->_encryption;
}
/**
* Sets new encryption options
*
* @param string|array $options Encryption options
* @return Zend_Filter_File_Encryption
*/
public function setEncryption($options)
{
if (is_string($options)) {
$options = array('key' => $options);
}
if (!is_array($options)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Invalid options argument provided to filter');
}
$options = $options + $this->getEncryption();
$algorithms = mcrypt_list_algorithms($options['algorithm_directory']);
if (!in_array($options['algorithm'], $algorithms)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The algorithm '{$options['algorithm']}' is not supported");
}
$modes = mcrypt_list_modes($options['mode_directory']);
if (!in_array($options['mode'], $modes)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The mode '{$options['mode']}' is not supported");
}
if (!mcrypt_module_self_test($options['algorithm'], $options['algorithm_directory'])) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('The given algorithm can not be used due an internal mcrypt problem');
}
if (!isset($options['vector'])) {
$options['vector'] = null;
}
$this->_encryption = $options;
$this->setVector($options['vector']);
return $this;
}
/**
* Returns the set vector
*
* @return string
*/
public function getVector()
{
return $this->_encryption['vector'];
}
/**
* Sets the initialization vector
*
* @param string $vector (Optional) Vector to set
* @return Zend_Filter_Encrypt_Mcrypt
*/
public function setVector($vector = null)
{
$cipher = $this->_openCipher();
$size = mcrypt_enc_get_iv_size($cipher);
if (empty($vector)) {
$this->_srand();
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && version_compare(PHP_VERSION, '5.3.0', '<')) {
$method = MCRYPT_RAND;
} else {
if (file_exists('/dev/urandom') || (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) {
$method = MCRYPT_DEV_URANDOM;
} elseif (file_exists('/dev/random')) {
$method = MCRYPT_DEV_RANDOM;
} else {
$method = MCRYPT_RAND;
}
}
$vector = mcrypt_create_iv($size, $method);
} else if (strlen($vector) != $size) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('The given vector has a wrong size for the set algorithm');
}
$this->_encryption['vector'] = $vector;
$this->_closeCipher($cipher);
return $this;
}
/**
* Returns the compression
*
* @return array
*/
public function getCompression()
{
return $this->_compression;
}
/**
* Sets a internal compression for values to encrypt
*
* @param string|array $compression
* @return Zend_Filter_Encrypt_Mcrypt
*/
public function setCompression($compression)
{
if (is_string($this->_compression)) {
$compression = array('adapter' => $compression);
}
$this->_compression = $compression;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Encrypts $value with the defined settings
*
* @param string $value The content to encrypt
* @return string The encrypted content
*/
public function encrypt($value)
{
// compress prior to encryption
if (!empty($this->_compression)) {
require_once 'Zend/Filter/Compress.php';
$compress = new Zend_Filter_Compress($this->_compression);
$value = $compress->filter($value);
}
$cipher = $this->_openCipher();
$this->_initCipher($cipher);
$encrypted = mcrypt_generic($cipher, $value);
mcrypt_generic_deinit($cipher);
$this->_closeCipher($cipher);
return $encrypted;
}
/**
* Defined by Zend_Filter_Interface
*
* Decrypts $value with the defined settings
*
* @param string $value Content to decrypt
* @return string The decrypted content
*/
public function decrypt($value)
{
$cipher = $this->_openCipher();
$this->_initCipher($cipher);
$decrypted = mdecrypt_generic($cipher, $value);
mcrypt_generic_deinit($cipher);
$this->_closeCipher($cipher);
// decompress after decryption
if (!empty($this->_compression)) {
require_once 'Zend/Filter/Decompress.php';
$decompress = new Zend_Filter_Decompress($this->_compression);
$decrypted = $decompress->filter($decrypted);
}
return $decrypted;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Mcrypt';
}
/**
* Open a cipher
*
* @throws Zend_Filter_Exception When the cipher can not be opened
* @return resource Returns the opened cipher
*/
protected function _openCipher()
{
$cipher = mcrypt_module_open(
$this->_encryption['algorithm'],
$this->_encryption['algorithm_directory'],
$this->_encryption['mode'],
$this->_encryption['mode_directory']);
if ($cipher === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Mcrypt can not be opened with your settings');
}
return $cipher;
}
/**
* Close a cipher
*
* @param resource $cipher Cipher to close
* @return Zend_Filter_Encrypt_Mcrypt
*/
protected function _closeCipher($cipher)
{
mcrypt_module_close($cipher);
return $this;
}
/**
* Initialises the cipher with the set key
*
* @param resource $cipher
* @throws
* @return resource
*/
protected function _initCipher($cipher)
{
$key = $this->_encryption['key'];
$keysizes = mcrypt_enc_get_supported_key_sizes($cipher);
if (empty($keysizes) || ($this->_encryption['salt'] == true)) {
$this->_srand();
$keysize = mcrypt_enc_get_key_size($cipher);
$key = substr(md5($key), 0, $keysize);
} else if (!in_array(strlen($key), $keysizes)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('The given key has a wrong size for the set algorithm');
}
$result = mcrypt_generic_init($cipher, $key, $this->_encryption['vector']);
if ($result < 0) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Mcrypt could not be initialize with the given setting');
}
return $this;
}
/**
* _srand() interception
*
* @see ZF-8742
*/
protected function _srand()
{
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
return;
}
if (!self::$_srandCalled) {
srand((double) microtime() * 1000000);
self::$_srandCalled = true;
}
}
}

Datei anzeigen

@ -0,0 +1,492 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Encrypt_Interface
*/
require_once 'Zend/Filter/Encrypt/Interface.php';
/**
* Encryption adapter for openssl
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
{
/**
* Definitions for encryption
* array(
* 'public' => public keys
* 'private' => private keys
* 'envelope' => resulting envelope keys
* )
*/
protected $_keys = array(
'public' => array(),
'private' => array(),
'envelope' => array()
);
/**
* Internal passphrase
*
* @var string
*/
protected $_passphrase;
/**
* Internal compression
*
* @var array
*/
protected $_compression;
/**
* Internal create package
*
* @var boolean
*/
protected $_package = false;
/**
* Class constructor
* Available options
* 'public' => public key
* 'private' => private key
* 'envelope' => envelope key
* 'passphrase' => passphrase
* 'compression' => compress value with this compression adapter
* 'package' => pack envelope keys into encrypted string, simplifies decryption
*
* @param string|array $options Options for this adapter
*/
public function __construct($options = array())
{
if (!extension_loaded('openssl')) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('This filter needs the openssl extension');
}
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (!is_array($options)) {
$options = array('public' => $options);
}
if (array_key_exists('passphrase', $options)) {
$this->setPassphrase($options['passphrase']);
unset($options['passphrase']);
}
if (array_key_exists('compression', $options)) {
$this->setCompression($options['compression']);
unset($options['compress']);
}
if (array_key_exists('package', $options)) {
$this->setPackage($options['package']);
unset($options['package']);
}
$this->_setKeys($options);
}
/**
* Sets the encryption keys
*
* @param string|array $keys Key with type association
* @return Zend_Filter_Encrypt_Openssl
*/
protected function _setKeys($keys)
{
if (!is_array($keys)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Invalid options argument provided to filter');
}
foreach ($keys as $type => $key) {
if (is_file($key) and is_readable($key)) {
$file = fopen($key, 'r');
$cert = fread($file, 8192);
fclose($file);
} else {
$cert = $key;
$key = count($this->_keys[$type]);
}
switch ($type) {
case 'public':
$test = openssl_pkey_get_public($cert);
if ($test === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Public key '{$cert}' not valid");
}
openssl_free_key($test);
$this->_keys['public'][$key] = $cert;
break;
case 'private':
$test = openssl_pkey_get_private($cert, $this->_passphrase);
if ($test === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Private key '{$cert}' not valid");
}
openssl_free_key($test);
$this->_keys['private'][$key] = $cert;
break;
case 'envelope':
$this->_keys['envelope'][$key] = $cert;
break;
default:
break;
}
}
return $this;
}
/**
* Returns all public keys
*
* @return array
*/
public function getPublicKey()
{
$key = $this->_keys['public'];
return $key;
}
/**
* Sets public keys
*
* @param string|array $key Public keys
* @return Zend_Filter_Encrypt_Openssl
*/
public function setPublicKey($key)
{
if (is_array($key)) {
foreach($key as $type => $option) {
if ($type !== 'public') {
$key['public'] = $option;
unset($key[$type]);
}
}
} else {
$key = array('public' => $key);
}
return $this->_setKeys($key);
}
/**
* Returns all private keys
*
* @return array
*/
public function getPrivateKey()
{
$key = $this->_keys['private'];
return $key;
}
/**
* Sets private keys
*
* @param string $key Private key
* @param string $passphrase
* @return Zend_Filter_Encrypt_Openssl
*/
public function setPrivateKey($key, $passphrase = null)
{
if (is_array($key)) {
foreach($key as $type => $option) {
if ($type !== 'private') {
$key['private'] = $option;
unset($key[$type]);
}
}
} else {
$key = array('private' => $key);
}
if ($passphrase !== null) {
$this->setPassphrase($passphrase);
}
return $this->_setKeys($key);
}
/**
* Returns all envelope keys
*
* @return array
*/
public function getEnvelopeKey()
{
$key = $this->_keys['envelope'];
return $key;
}
/**
* Sets envelope keys
*
* @param string|array $options Envelope keys
* @return Zend_Filter_Encrypt_Openssl
*/
public function setEnvelopeKey($key)
{
if (is_array($key)) {
foreach($key as $type => $option) {
if ($type !== 'envelope') {
$key['envelope'] = $option;
unset($key[$type]);
}
}
} else {
$key = array('envelope' => $key);
}
return $this->_setKeys($key);
}
/**
* Returns the passphrase
*
* @return string
*/
public function getPassphrase()
{
return $this->_passphrase;
}
/**
* Sets a new passphrase
*
* @param string $passphrase
* @return Zend_Filter_Encrypt_Openssl
*/
public function setPassphrase($passphrase)
{
$this->_passphrase = $passphrase;
return $this;
}
/**
* Returns the compression
*
* @return array
*/
public function getCompression()
{
return $this->_compression;
}
/**
* Sets a internal compression for values to encrypt
*
* @param string|array $compression
* @return Zend_Filter_Encrypt_Openssl
*/
public function setCompression($compression)
{
if (is_string($this->_compression)) {
$compression = array('adapter' => $compression);
}
$this->_compression = $compression;
return $this;
}
/**
* Returns if header should be packaged
*
* @return boolean
*/
public function getPackage()
{
return $this->_package;
}
/**
* Sets if the envelope keys should be included in the encrypted value
*
* @param boolean $package
* @return Zend_Filter_Encrypt_Openssl
*/
public function setPackage($package)
{
$this->_package = (boolean) $package;
return $this;
}
/**
* Encrypts $value with the defined settings
* Note that you also need the "encrypted" keys to be able to decrypt
*
* @param string $value Content to encrypt
* @return string The encrypted content
* @throws Zend_Filter_Exception
*/
public function encrypt($value)
{
$encrypted = array();
$encryptedkeys = array();
if (count($this->_keys['public']) == 0) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Openssl can not encrypt without public keys');
}
$keys = array();
$fingerprints = array();
$count = -1;
foreach($this->_keys['public'] as $key => $cert) {
$keys[$key] = openssl_pkey_get_public($cert);
if ($this->_package) {
$details = openssl_pkey_get_details($keys[$key]);
if ($details === false) {
$details = array('key' => 'ZendFramework');
}
++$count;
$fingerprints[$count] = md5($details['key']);
}
}
// compress prior to encryption
if (!empty($this->_compression)) {
require_once 'Zend/Filter/Compress.php';
$compress = new Zend_Filter_Compress($this->_compression);
$value = $compress->filter($value);
}
$crypt = openssl_seal($value, $encrypted, $encryptedkeys, $keys);
foreach ($keys as $key) {
openssl_free_key($key);
}
if ($crypt === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Openssl was not able to encrypt your content with the given options');
}
$this->_keys['envelope'] = $encryptedkeys;
// Pack data and envelope keys into single string
if ($this->_package) {
$header = pack('n', count($this->_keys['envelope']));
foreach($this->_keys['envelope'] as $key => $envKey) {
$header .= pack('H32n', $fingerprints[$key], strlen($envKey)) . $envKey;
}
$encrypted = $header . $encrypted;
}
return $encrypted;
}
/**
* Defined by Zend_Filter_Interface
*
* Decrypts $value with the defined settings
*
* @param string $value Content to decrypt
* @return string The decrypted content
* @throws Zend_Filter_Exception
*/
public function decrypt($value)
{
$decrypted = "";
$envelope = current($this->getEnvelopeKey());
if (count($this->_keys['private']) !== 1) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Please give a private key for decryption with Openssl');
}
if (!$this->_package && empty($envelope)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Please give a envelope key for decryption with Openssl');
}
foreach($this->_keys['private'] as $key => $cert) {
$keys = openssl_pkey_get_private($cert, $this->getPassphrase());
}
if ($this->_package) {
$details = openssl_pkey_get_details($keys);
if ($details !== false) {
$fingerprint = md5($details['key']);
} else {
$fingerprint = md5("ZendFramework");
}
$count = unpack('ncount', $value);
$count = $count['count'];
$length = 2;
for($i = $count; $i > 0; --$i) {
$header = unpack('H32print/nsize', substr($value, $length, 18));
$length += 18;
if ($header['print'] == $fingerprint) {
$envelope = substr($value, $length, $header['size']);
}
$length += $header['size'];
}
// remainder of string is the value to decrypt
$value = substr($value, $length);
}
$crypt = openssl_open($value, $decrypted, $envelope, $keys);
openssl_free_key($keys);
if ($crypt === false) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Openssl was not able to decrypt you content with the given options');
}
// decompress after decryption
if (!empty($this->_compression)) {
require_once 'Zend/Filter/Decompress.php';
$decompress = new Zend_Filter_Decompress($this->_compression);
$decrypted = $decompress->filter($decrypted);
}
return $decrypted;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return 'Openssl';
}
}

Datei anzeigen

@ -0,0 +1,37 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Exception extends Zend_Exception
{}

Datei anzeigen

@ -0,0 +1,106 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Decrypt
*/
require_once 'Zend/Filter/Decrypt.php';
/**
* Decrypts a given file and stores the decrypted file content
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_File_Decrypt extends Zend_Filter_Decrypt
{
/**
* New filename to set
*
* @var string
*/
protected $_filename;
/**
* Returns the new filename where the content will be stored
*
* @return string
*/
public function getFilename()
{
return $this->_filename;
}
/**
* Sets the new filename where the content will be stored
*
* @param string $filename (Optional) New filename to set
* @return Zend_Filter_File_Encryt
*/
public function setFilename($filename = null)
{
$this->_filename = $filename;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Decrypts the file $value with the defined settings
*
* @param string $value Full path of file to change
* @return string The filename which has been set, or false when there were errors
*/
public function filter($value)
{
if (!file_exists($value)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '$value' not found");
}
if (!isset($this->_filename)) {
$this->_filename = $value;
}
if (file_exists($this->_filename) and !is_writable($this->_filename)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '{$this->_filename}' is not writable");
}
$content = file_get_contents($value);
if (!$content) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while reading file '$value'");
}
$decrypted = parent::filter($content);
$result = file_put_contents($this->_filename, $decrypted);
if (!$result) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while writing file '{$this->_filename}'");
}
return $this->_filename;
}
}

Datei anzeigen

@ -0,0 +1,106 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Encrypt
*/
require_once 'Zend/Filter/Encrypt.php';
/**
* Encrypts a given file and stores the encrypted file content
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_File_Encrypt extends Zend_Filter_Encrypt
{
/**
* New filename to set
*
* @var string
*/
protected $_filename;
/**
* Returns the new filename where the content will be stored
*
* @return string
*/
public function getFilename()
{
return $this->_filename;
}
/**
* Sets the new filename where the content will be stored
*
* @param string $filename (Optional) New filename to set
* @return Zend_Filter_File_Encryt
*/
public function setFilename($filename = null)
{
$this->_filename = $filename;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Encrypts the file $value with the defined settings
*
* @param string $value Full path of file to change
* @return string The filename which has been set, or false when there were errors
*/
public function filter($value)
{
if (!file_exists($value)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '$value' not found");
}
if (!isset($this->_filename)) {
$this->_filename = $value;
}
if (file_exists($this->_filename) and !is_writable($this->_filename)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '{$this->_filename}' is not writable");
}
$content = file_get_contents($value);
if (!$content) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while reading file '$value'");
}
$encrypted = parent::filter($content);
$result = file_put_contents($this->_filename, $encrypted);
if (!$result) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while writing file '{$this->_filename}'");
}
return $this->_filename;
}
}

Datei anzeigen

@ -0,0 +1,84 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_StringToLower
*/
require_once 'Zend/Filter/StringToLower.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_File_LowerCase extends Zend_Filter_StringToLower
{
/**
* Adds options to the filter at initiation
*
* @param string $options
*/
public function __construct($options = null)
{
if (!empty($options)) {
$this->setEncoding($options);
}
}
/**
* Defined by Zend_Filter_Interface
*
* Does a lowercase on the content of the given file
*
* @param string $value Full path of file to change
* @return string The given $value
* @throws Zend_Filter_Exception
*/
public function filter($value)
{
if (!file_exists($value)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '$value' not found");
}
if (!is_writable($value)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '$value' is not writable");
}
$content = file_get_contents($value);
if (!$content) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while reading file '$value'");
}
$content = parent::filter($content);
$result = file_put_contents($value, $content);
if (!$result) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while writing file '$value'");
}
return $value;
}
}

Datei anzeigen

@ -0,0 +1,304 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_File_Rename implements Zend_Filter_Interface
{
/**
* Internal array of array(source, target, overwrite)
*/
protected $_files = array();
/**
* Class constructor
*
* Options argument may be either a string, a Zend_Config object, or an array.
* If an array or Zend_Config object, it accepts the following keys:
* 'source' => Source filename or directory which will be renamed
* 'target' => Target filename or directory, the new name of the sourcefile
* 'overwrite' => Shall existing files be overwritten ?
*
* @param string|array $options Target file or directory to be renamed
* @param string $target Source filename or directory (deprecated)
* @param bool $overwrite Should existing files be overwritten (deprecated)
* @return void
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_string($options)) {
$options = array('target' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Invalid options argument provided to filter');
}
if (1 < func_num_args()) {
$argv = func_get_args();
array_shift($argv);
$source = array_shift($argv);
$overwrite = false;
if (!empty($argv)) {
$overwrite = array_shift($argv);
}
$options['source'] = $source;
$options['overwrite'] = $overwrite;
}
$this->setFile($options);
}
/**
* Returns the files to rename and their new name and location
*
* @return array
*/
public function getFile()
{
return $this->_files;
}
/**
* Sets a new file or directory as target, deleting existing ones
*
* Array accepts the following keys:
* 'source' => Source filename or directory which will be renamed
* 'target' => Target filename or directory, the new name of the sourcefile
* 'overwrite' => Shall existing files be overwritten ?
*
* @param string|array $options Old file or directory to be rewritten
* @return Zend_Filter_File_Rename
*/
public function setFile($options)
{
$this->_files = array();
$this->addFile($options);
return $this;
}
/**
* Adds a new file or directory as target to the existing ones
*
* Array accepts the following keys:
* 'source' => Source filename or directory which will be renamed
* 'target' => Target filename or directory, the new name of the sourcefile
* 'overwrite' => Shall existing files be overwritten ?
*
* @param string|array $options Old file or directory to be rewritten
* @return Zend_Filter_File_Rename
*/
public function addFile($options)
{
if (is_string($options)) {
$options = array('target' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception ('Invalid options to rename filter provided');
}
$this->_convertOptions($options);
return $this;
}
/**
* Returns only the new filename without moving it
* But existing files will be erased when the overwrite option is true
*
* @param string $value Full path of file to change
* @param boolean $source Return internal informations
* @return string The new filename which has been set
*/
public function getNewName($value, $source = false)
{
$file = $this->_getFileName($value);
if ($file['source'] == $file['target']) {
return $value;
}
if (!file_exists($file['source'])) {
return $value;
}
if (($file['overwrite'] == true) && (file_exists($file['target']))) {
unlink($file['target']);
}
if (file_exists($file['target'])) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception(sprintf("File '%s' could not be renamed. It already exists.", $value));
}
if ($source) {
return $file;
}
return $file['target'];
}
/**
* Defined by Zend_Filter_Interface
*
* Renames the file $value to the new name set before
* Returns the file $value, removing all but digit characters
*
* @param string $value Full path of file to change
* @throws Zend_Filter_Exception
* @return string The new filename which has been set, or false when there were errors
*/
public function filter($value)
{
$file = $this->getNewName($value, true);
if (is_string($file)) {
return $file;
}
$result = rename($file['source'], $file['target']);
if ($result === true) {
return $file['target'];
}
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception(sprintf("File '%s' could not be renamed. An error occured while processing the file.", $value));
}
/**
* Internal method for creating the file array
* Supports single and nested arrays
*
* @param array $options
* @return array
*/
protected function _convertOptions($options) {
$files = array();
foreach ($options as $key => $value) {
if (is_array($value)) {
$this->_convertOptions($value);
continue;
}
switch ($key) {
case "source":
$files['source'] = (string) $value;
break;
case 'target' :
$files['target'] = (string) $value;
break;
case 'overwrite' :
$files['overwrite'] = (boolean) $value;
break;
default:
break;
}
}
if (empty($files)) {
return $this;
}
if (empty($files['source'])) {
$files['source'] = '*';
}
if (empty($files['target'])) {
$files['target'] = '*';
}
if (empty($files['overwrite'])) {
$files['overwrite'] = false;
}
$found = false;
foreach ($this->_files as $key => $value) {
if ($value['source'] == $files['source']) {
$this->_files[$key] = $files;
$found = true;
}
}
if (!$found) {
$count = count($this->_files);
$this->_files[$count] = $files;
}
return $this;
}
/**
* Internal method to resolve the requested source
* and return all other related parameters
*
* @param string $file Filename to get the informations for
* @return array
*/
protected function _getFileName($file)
{
$rename = array();
foreach ($this->_files as $value) {
if ($value['source'] == '*') {
if (!isset($rename['source'])) {
$rename = $value;
$rename['source'] = $file;
}
}
if ($value['source'] == $file) {
$rename = $value;
}
}
if (!isset($rename['source'])) {
return $file;
}
if (!isset($rename['target']) or ($rename['target'] == '*')) {
$rename['target'] = $rename['source'];
}
if (is_dir($rename['target'])) {
$name = basename($rename['source']);
$last = $rename['target'][strlen($rename['target']) - 1];
if (($last != '/') and ($last != '\\')) {
$rename['target'] .= DIRECTORY_SEPARATOR;
}
$rename['target'] .= $name;
}
return $rename;
}
}

Datei anzeigen

@ -0,0 +1,84 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_StringToUpper
*/
require_once 'Zend/Filter/StringToUpper.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_File_UpperCase extends Zend_Filter_StringToUpper
{
/**
* Adds options to the filter at initiation
*
* @param string $options
*/
public function __construct($options = null)
{
if (!empty($options)) {
$this->setEncoding($options);
}
}
/**
* Defined by Zend_Filter_Interface
*
* Does a lowercase on the content of the given file
*
* @param string $value Full path of file to change
* @return string The given $value
* @throws Zend_Filter_Exception
*/
public function filter($value)
{
if (!file_exists($value)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '$value' not found");
}
if (!is_writable($value)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("File '$value' is not writable");
}
$content = file_get_contents($value);
if (!$content) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while reading file '$value'");
}
$content = parent::filter($content);
$result = file_put_contents($value, $content);
if (!$result) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Problem while writing file '$value'");
}
return $value;
}
}

Datei anzeigen

@ -0,0 +1,202 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_HtmlEntities implements Zend_Filter_Interface
{
/**
* Corresponds to the second htmlentities() argument
*
* @var integer
*/
protected $_quoteStyle;
/**
* Corresponds to the third htmlentities() argument
*
* @var string
*/
protected $_encoding;
/**
* Corresponds to the forth htmlentities() argument
*
* @var unknown_type
*/
protected $_doubleQuote;
/**
* Sets filter options
*
* @param integer|array $quoteStyle
* @param string $charSet
* @return void
*/
public function __construct($options = array())
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp['quotestyle'] = array_shift($options);
if (!empty($options)) {
$temp['charset'] = array_shift($options);
}
$options = $temp;
}
if (!isset($options['quotestyle'])) {
$options['quotestyle'] = ENT_COMPAT;
}
if (!isset($options['encoding'])) {
$options['encoding'] = 'UTF-8';
}
if (isset($options['charset'])) {
$options['encoding'] = $options['charset'];
}
if (!isset($options['doublequote'])) {
$options['doublequote'] = true;
}
$this->setQuoteStyle($options['quotestyle']);
$this->setEncoding($options['encoding']);
$this->setDoubleQuote($options['doublequote']);
}
/**
* Returns the quoteStyle option
*
* @return integer
*/
public function getQuoteStyle()
{
return $this->_quoteStyle;
}
/**
* Sets the quoteStyle option
*
* @param integer $quoteStyle
* @return Zend_Filter_HtmlEntities Provides a fluent interface
*/
public function setQuoteStyle($quoteStyle)
{
$this->_quoteStyle = $quoteStyle;
return $this;
}
/**
* Get encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Set encoding
*
* @param string $value
* @return Zend_Filter_HtmlEntities
*/
public function setEncoding($value)
{
$this->_encoding = (string) $value;
return $this;
}
/**
* Returns the charSet option
*
* Proxies to {@link getEncoding()}
*
* @return string
*/
public function getCharSet()
{
return $this->getEncoding();
}
/**
* Sets the charSet option
*
* Proxies to {@link setEncoding()}
*
* @param string $charSet
* @return Zend_Filter_HtmlEntities Provides a fluent interface
*/
public function setCharSet($charSet)
{
return $this->setEncoding($charSet);
}
/**
* Returns the doubleQuote option
*
* @return boolean
*/
public function getDoubleQuote()
{
return $this->_doubleQuote;
}
/**
* Sets the doubleQuote option
*
* @param boolean $doubleQuote
* @return Zend_Filter_HtmlEntities Provides a fluent interface
*/
public function setDoubleQuote($doubleQuote)
{
$this->_doubleQuote = (boolean) $doubleQuote;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value, converting characters to their corresponding HTML entity
* equivalents where they exist
*
* @param string $value
* @return string
*/
public function filter($value)
{
return htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
}
}

Datei anzeigen

@ -0,0 +1,527 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter.php';
/**
* @see Zend_Loader_PluginLoader
*/
require_once 'Zend/Loader/PluginLoader.php';
/**
* Filter chain for string inflection
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Inflector implements Zend_Filter_Interface
{
/**
* @var Zend_Loader_PluginLoader_Interface
*/
protected $_pluginLoader = null;
/**
* @var string
*/
protected $_target = null;
/**
* @var bool
*/
protected $_throwTargetExceptionsOn = true;
/**
* @var string
*/
protected $_targetReplacementIdentifier = ':';
/**
* @var array
*/
protected $_rules = array();
/**
* Constructor
*
* @param string|array $options Options to set
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp = array();
if (!empty($options)) {
$temp['target'] = array_shift($options);
}
if (!empty($options)) {
$temp['rules'] = array_shift($options);
}
if (!empty($options)) {
$temp['throwTargetExceptionsOn'] = array_shift($options);
}
if (!empty($options)) {
$temp['targetReplacementIdentifier'] = array_shift($options);
}
$options = $temp;
}
$this->setOptions($options);
}
/**
* Retreive PluginLoader
*
* @return Zend_Loader_PluginLoader_Interface
*/
public function getPluginLoader()
{
if (!$this->_pluginLoader instanceof Zend_Loader_PluginLoader_Interface) {
$this->_pluginLoader = new Zend_Loader_PluginLoader(array('Zend_Filter_' => 'Zend/Filter/'), __CLASS__);
}
return $this->_pluginLoader;
}
/**
* Set PluginLoader
*
* @param Zend_Loader_PluginLoader_Interface $pluginLoader
* @return Zend_Filter_Inflector
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $pluginLoader)
{
$this->_pluginLoader = $pluginLoader;
return $this;
}
/**
* Use Zend_Config object to set object state
*
* @deprecated Use setOptions() instead
* @param Zend_Config $config
* @return Zend_Filter_Inflector
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config);
}
/**
* Set options
*
* @param array $options
* @return Zend_Filter_Inflector
*/
public function setOptions($options) {
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
// Set Präfix Path
if (array_key_exists('filterPrefixPath', $options)) {
if (!is_scalar($options['filterPrefixPath'])) {
foreach ($options['filterPrefixPath'] as $prefix => $path) {
$this->addFilterPrefixPath($prefix, $path);
}
}
}
if (array_key_exists('throwTargetExceptionsOn', $options)) {
$this->setThrowTargetExceptionsOn($options['throwTargetExceptionsOn']);
}
if (array_key_exists('targetReplacementIdentifier', $options)) {
$this->setTargetReplacementIdentifier($options['targetReplacementIdentifier']);
}
if (array_key_exists('target', $options)) {
$this->setTarget($options['target']);
}
if (array_key_exists('rules', $options)) {
$this->addRules($options['rules']);
}
return $this;
}
/**
* Convienence method to add prefix and path to PluginLoader
*
* @param string $prefix
* @param string $path
* @return Zend_Filter_Inflector
*/
public function addFilterPrefixPath($prefix, $path)
{
$this->getPluginLoader()->addPrefixPath($prefix, $path);
return $this;
}
/**
* Set Whether or not the inflector should throw an exception when a replacement
* identifier is still found within an inflected target.
*
* @param bool $throwTargetExceptions
* @return Zend_Filter_Inflector
*/
public function setThrowTargetExceptionsOn($throwTargetExceptionsOn)
{
$this->_throwTargetExceptionsOn = ($throwTargetExceptionsOn == true) ? true : false;
return $this;
}
/**
* Will exceptions be thrown?
*
* @return bool
*/
public function isThrowTargetExceptionsOn()
{
return $this->_throwTargetExceptionsOn;
}
/**
* Set the Target Replacement Identifier, by default ':'
*
* @param string $targetReplacementIdentifier
* @return Zend_Filter_Inflector
*/
public function setTargetReplacementIdentifier($targetReplacementIdentifier)
{
if ($targetReplacementIdentifier) {
$this->_targetReplacementIdentifier = (string) $targetReplacementIdentifier;
}
return $this;
}
/**
* Get Target Replacement Identifier
*
* @return string
*/
public function getTargetReplacementIdentifier()
{
return $this->_targetReplacementIdentifier;
}
/**
* Set a Target
* ex: 'scripts/:controller/:action.:suffix'
*
* @param string
* @return Zend_Filter_Inflector
*/
public function setTarget($target)
{
$this->_target = (string) $target;
return $this;
}
/**
* Retrieve target
*
* @return string
*/
public function getTarget()
{
return $this->_target;
}
/**
* Set Target Reference
*
* @param reference $target
* @return Zend_Filter_Inflector
*/
public function setTargetReference(&$target)
{
$this->_target =& $target;
return $this;
}
/**
* SetRules() is the same as calling addRules() with the exception that it
* clears the rules before adding them.
*
* @param array $rules
* @return Zend_Filter_Inflector
*/
public function setRules(Array $rules)
{
$this->clearRules();
$this->addRules($rules);
return $this;
}
/**
* AddRules(): multi-call to setting filter rules.
*
* If prefixed with a ":" (colon), a filter rule will be added. If not
* prefixed, a static replacement will be added.
*
* ex:
* array(
* ':controller' => array('CamelCaseToUnderscore','StringToLower'),
* ':action' => array('CamelCaseToUnderscore','StringToLower'),
* 'suffix' => 'phtml'
* );
*
* @param array
* @return Zend_Filter_Inflector
*/
public function addRules(Array $rules)
{
$keys = array_keys($rules);
foreach ($keys as $spec) {
if ($spec[0] == ':') {
$this->addFilterRule($spec, $rules[$spec]);
} else {
$this->setStaticRule($spec, $rules[$spec]);
}
}
return $this;
}
/**
* Get rules
*
* By default, returns all rules. If a $spec is provided, will return those
* rules if found, false otherwise.
*
* @param string $spec
* @return array|false
*/
public function getRules($spec = null)
{
if (null !== $spec) {
$spec = $this->_normalizeSpec($spec);
if (isset($this->_rules[$spec])) {
return $this->_rules[$spec];
}
return false;
}
return $this->_rules;
}
/**
* getRule() returns a rule set by setFilterRule(), a numeric index must be provided
*
* @param string $spec
* @param int $index
* @return Zend_Filter_Interface|false
*/
public function getRule($spec, $index)
{
$spec = $this->_normalizeSpec($spec);
if (isset($this->_rules[$spec]) && is_array($this->_rules[$spec])) {
if (isset($this->_rules[$spec][$index])) {
return $this->_rules[$spec][$index];
}
}
return false;
}
/**
* ClearRules() clears the rules currently in the inflector
*
* @return Zend_Filter_Inflector
*/
public function clearRules()
{
$this->_rules = array();
return $this;
}
/**
* Set a filtering rule for a spec. $ruleSet can be a string, Filter object
* or an array of strings or filter objects.
*
* @param string $spec
* @param array|string|Zend_Filter_Interface $ruleSet
* @return Zend_Filter_Inflector
*/
public function setFilterRule($spec, $ruleSet)
{
$spec = $this->_normalizeSpec($spec);
$this->_rules[$spec] = array();
return $this->addFilterRule($spec, $ruleSet);
}
/**
* Add a filter rule for a spec
*
* @param mixed $spec
* @param mixed $ruleSet
* @return void
*/
public function addFilterRule($spec, $ruleSet)
{
$spec = $this->_normalizeSpec($spec);
if (!isset($this->_rules[$spec])) {
$this->_rules[$spec] = array();
}
if (!is_array($ruleSet)) {
$ruleSet = array($ruleSet);
}
if (is_string($this->_rules[$spec])) {
$temp = $this->_rules[$spec];
$this->_rules[$spec] = array();
$this->_rules[$spec][] = $temp;
}
foreach ($ruleSet as $rule) {
$this->_rules[$spec][] = $this->_getRule($rule);
}
return $this;
}
/**
* Set a static rule for a spec. This is a single string value
*
* @param string $name
* @param string $value
* @return Zend_Filter_Inflector
*/
public function setStaticRule($name, $value)
{
$name = $this->_normalizeSpec($name);
$this->_rules[$name] = (string) $value;
return $this;
}
/**
* Set Static Rule Reference.
*
* This allows a consuming class to pass a property or variable
* in to be referenced when its time to build the output string from the
* target.
*
* @param string $name
* @param mixed $reference
* @return Zend_Filter_Inflector
*/
public function setStaticRuleReference($name, &$reference)
{
$name = $this->_normalizeSpec($name);
$this->_rules[$name] =& $reference;
return $this;
}
/**
* Inflect
*
* @param string|array $source
* @return string
*/
public function filter($source)
{
// clean source
foreach ( (array) $source as $sourceName => $sourceValue) {
$source[ltrim($sourceName, ':')] = $sourceValue;
}
$pregQuotedTargetReplacementIdentifier = preg_quote($this->_targetReplacementIdentifier, '#');
$processedParts = array();
foreach ($this->_rules as $ruleName => $ruleValue) {
if (isset($source[$ruleName])) {
if (is_string($ruleValue)) {
// overriding the set rule
$processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = str_replace('\\', '\\\\', $source[$ruleName]);
} elseif (is_array($ruleValue)) {
$processedPart = $source[$ruleName];
foreach ($ruleValue as $ruleFilter) {
$processedPart = $ruleFilter->filter($processedPart);
}
$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)) {
require_once 'Zend/Filter/Exception.php';
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
*/
protected function _normalizeSpec($spec)
{
return ltrim((string) $spec, ':&');
}
/**
* Resolve named filters and convert them to filter objects.
*
* @param string $rule
* @return Zend_Filter_Interface
*/
protected function _getRule($rule)
{
if ($rule instanceof Zend_Filter_Interface) {
return $rule;
}
$rule = (string) $rule;
$className = $this->getPluginLoader()->load($rule);
$ruleObject = new $className();
if (!$ruleObject instanceof Zend_Filter_Interface) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('No class named ' . $rule . ' implementing Zend_Filter_Interface could be found');
}
return $ruleObject;
}
}

1126
library/Zend/Filter/Input.php Normale Datei

Datei-Diff unterdrückt, da er zu groß ist Diff laden

50
library/Zend/Filter/Int.php Normale Datei
Datei anzeigen

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Int implements Zend_Filter_Interface
{
/**
* Defined by Zend_Filter_Interface
*
* Returns (int) $value
*
* @param string $value
* @return integer
*/
public function filter($value)
{
return (int) ((string) $value);
}
}

Datei anzeigen

@ -0,0 +1,40 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Filter_Interface
{
/**
* Returns the result of filtering $value
*
* @param mixed $value
* @throws Zend_Filter_Exception If filtering $value is impossible
* @return mixed
*/
public function filter($value);
}

Datei anzeigen

@ -0,0 +1,112 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Locale/Format.php';
/**
* Normalizes given localized input
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_LocalizedToNormalized implements Zend_Filter_Interface
{
/**
* Set options
* @var array
*/
protected $_options = array(
'locale' => null,
'date_format' => null,
'precision' => null
);
/**
* Class constructor
*
* @param string|Zend_Locale $locale (Optional) Locale to set
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (null !== $options) {
$this->setOptions($options);
}
}
/**
* Returns the set options
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Sets options to use
*
* @param array $options (Optional) Options to use
* @return Zend_Filter_LocalizedToNormalized
*/
public function setOptions(array $options = null)
{
$this->_options = $options + $this->_options;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Normalizes the given input
*
* @param string $value Value to normalized
* @return string|array The normalized value
*/
public function filter($value)
{
if (Zend_Locale_Format::isNumber($value, $this->_options)) {
return Zend_Locale_Format::getNumber($value, $this->_options);
} else if (($this->_options['date_format'] === null) && (strpos($value, ':') !== false)) {
// Special case, no date format specified, detect time input
return Zend_Locale_Format::getTime($value, $this->_options);
} else if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) {
// Detect date or time input
return Zend_Locale_Format::getDate($value, $this->_options);
}
return $value;
}
}

Datei anzeigen

@ -0,0 +1,111 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Locale/Format.php';
/**
* Localizes given normalized input
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_NormalizedToLocalized implements Zend_Filter_Interface
{
/**
* Set options
*/
protected $_options = array(
'locale' => null,
'date_format' => null,
'precision' => null
);
/**
* Class constructor
*
* @param string|Zend_Locale $locale (Optional) Locale to set
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (null !== $options) {
$this->setOptions($options);
}
}
/**
* Returns the set options
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Sets options to use
*
* @param array $options (Optional) Options to use
* @return Zend_Filter_LocalizedToNormalized
*/
public function setOptions(array $options = null)
{
$this->_options = $options + $this->_options;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Normalizes the given input
*
* @param string $value Value to normalized
* @return string|array The normalized value
*/
public function filter($value)
{
if (is_array($value)) {
require_once 'Zend/Date.php';
$date = new Zend_Date($value, $this->_options['locale']);
return $date->toString($this->_options['date_format']);
} else if ($this->_options['precision'] === 0) {
return Zend_Locale_Format::toInteger($value, $this->_options);
} else if ($this->_options['precision'] === null) {
return Zend_Locale_Format::toFloat($value, $this->_options);
}
return Zend_Locale_Format::toNumber($value, $this->_options);
}
}

183
library/Zend/Filter/Null.php Normale Datei
Datei anzeigen

@ -0,0 +1,183 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Null implements Zend_Filter_Interface
{
const BOOLEAN = 1;
const INTEGER = 2;
const EMPTY_ARRAY = 4;
const STRING = 8;
const ZERO = 16;
const ALL = 31;
protected $_constants = array(
self::BOOLEAN => 'boolean',
self::INTEGER => 'integer',
self::EMPTY_ARRAY => 'array',
self::STRING => 'string',
self::ZERO => 'zero',
self::ALL => 'all'
);
/**
* Internal type to detect
*
* @var integer
*/
protected $_type = self::ALL;
/**
* Constructor
*
* @param string|array|Zend_Config $options OPTIONAL
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp = array();
if (!empty($options)) {
$temp = array_shift($options);
}
$options = $temp;
} else if (is_array($options) && array_key_exists('type', $options)) {
$options = $options['type'];
}
if (!empty($options)) {
$this->setType($options);
}
}
/**
* Returns the set null types
*
* @return array
*/
public function getType()
{
return $this->_type;
}
/**
* Set the null types
*
* @param integer|array $type
* @throws Zend_Filter_Exception
* @return Zend_Filter_Null
*/
public function setType($type = null)
{
if (is_array($type)) {
$detected = 0;
foreach($type as $value) {
if (is_int($value)) {
$detected += $value;
} else if (in_array($value, $this->_constants)) {
$detected += array_search($value, $this->_constants);
}
}
$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)) {
require_once 'Zend/Filter/Exception.php';
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
*/
public function filter($value)
{
$type = $this->getType();
// STRING ZERO ('0')
if ($type >= self::ZERO) {
$type -= self::ZERO;
if (is_string($value) && ($value == '0')) {
return null;
}
}
// STRING ('')
if ($type >= self::STRING) {
$type -= self::STRING;
if (is_string($value) && ($value == '')) {
return null;
}
}
// EMPTY_ARRAY (array())
if ($type >= self::EMPTY_ARRAY) {
$type -= self::EMPTY_ARRAY;
if (is_array($value) && ($value == array())) {
return null;
}
}
// INTEGER (0)
if ($type >= self::INTEGER) {
$type -= self::INTEGER;
if (is_int($value) && ($value == 0)) {
return null;
}
}
// BOOLEAN (false)
if ($type >= self::BOOLEAN) {
$type -= self::BOOLEAN;
if (is_bool($value) && ($value == false)) {
return null;
}
}
return $value;
}
}

Datei anzeigen

@ -0,0 +1,174 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_PregReplace implements Zend_Filter_Interface
{
/**
* Pattern to match
* @var mixed
*/
protected $_matchPattern = null;
/**
* Replacement pattern
* @var mixed
*/
protected $_replacement = '';
/**
* Is unicode enabled?
*
* @var bool
*/
static protected $_unicodeSupportEnabled = null;
/**
* Is Unicode Support Enabled Utility function
*
* @return bool
*/
static public function isUnicodeSupportEnabled()
{
if (self::$_unicodeSupportEnabled === null) {
self::_determineUnicodeSupport();
}
return self::$_unicodeSupportEnabled;
}
/**
* Method to cache the regex needed to determine if unicode support is available
*
* @return bool
*/
static protected function _determineUnicodeSupport()
{
self::$_unicodeSupportEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
}
/**
* Constructor
* Supported options are
* 'match' => matching pattern
* 'replace' => replace with this
*
* @param string|array $options
* @return void
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp = array();
if (!empty($options)) {
$temp['match'] = array_shift($options);
}
if (!empty($options)) {
$temp['replace'] = array_shift($options);
}
$options = $temp;
}
if (array_key_exists('match', $options)) {
$this->setMatchPattern($options['match']);
}
if (array_key_exists('replace', $options)) {
$this->setReplacement($options['replace']);
}
}
/**
* Set the match pattern for the regex being called within filter()
*
* @param mixed $match - same as the first argument of preg_replace
* @return Zend_Filter_PregReplace
*/
public function setMatchPattern($match)
{
$this->_matchPattern = $match;
return $this;
}
/**
* Get currently set match pattern
*
* @return string
*/
public function getMatchPattern()
{
return $this->_matchPattern;
}
/**
* Set the Replacement pattern/string for the preg_replace called in filter
*
* @param mixed $replacement - same as the second argument of preg_replace
* @return Zend_Filter_PregReplace
*/
public function setReplacement($replacement)
{
$this->_replacement = $replacement;
return $this;
}
/**
* Get currently set replacement value
*
* @return string
*/
public function getReplacement()
{
return $this->_replacement;
}
/**
* Perform regexp replacement as filter
*
* @param string $value
* @return string
*/
public function filter($value)
{
if ($this->_matchPattern == null) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception(get_class($this) . ' does not have a valid MatchPattern set.');
}
return preg_replace($this->_matchPattern, $this->_replacement, $value);
}
}

Datei anzeigen

@ -0,0 +1,134 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_RealPath implements Zend_Filter_Interface
{
/**
* @var boolean $_pathExists
*/
protected $_exists = true;
/**
* Class constructor
*
* @param boolean|Zend_Config $options Options to set
*/
public function __construct($options = true)
{
$this->setExists($options);
}
/**
* Returns true if the filtered path must exist
*
* @return boolean
*/
public function getExists()
{
return $this->_exists;
}
/**
* Sets if the path has to exist
* TRUE when the path must exist
* FALSE when not existing paths can be given
*
* @param boolean|Zend_Config $exists Path must exist
* @return Zend_Filter_RealPath
*/
public function setExists($exists)
{
if ($exists instanceof Zend_Config) {
$exists = $exists->toArray();
}
if (is_array($exists)) {
if (isset($exists['exists'])) {
$exists = (boolean) $exists['exists'];
}
}
$this->_exists = (boolean) $exists;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns realpath($value)
*
* @param string $value
* @return string
*/
public function filter($value)
{
$path = (string) $value;
if ($this->_exists) {
return realpath($path);
}
$realpath = @realpath($path);
if ($realpath) {
return $realpath;
}
$drive = '';
if (substr(PHP_OS, 0, 3) == 'WIN') {
$path = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $path);
if (preg_match('/([a-zA-Z]\:)(.*)/', $path, $matches)) {
list($fullMatch, $drive, $path) = $matches;
} else {
$cwd = getcwd();
$drive = substr($cwd, 0, 2);
if (substr($path, 0, 1) != DIRECTORY_SEPARATOR) {
$path = substr($cwd, 3) . DIRECTORY_SEPARATOR . $path;
}
}
} elseif (substr($path, 0, 1) != DIRECTORY_SEPARATOR) {
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
$stack = array();
$parts = explode(DIRECTORY_SEPARATOR, $path);
foreach ($parts as $dir) {
if (strlen($dir) && $dir !== '.') {
if ($dir == '..') {
array_pop($stack);
} else {
array_push($stack, $dir);
}
}
}
return $drive . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $stack);
}
}

Datei anzeigen

@ -0,0 +1,121 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_StringToLower implements Zend_Filter_Interface
{
/**
* Encoding for the input string
*
* @var string
*/
protected $_encoding = null;
/**
* Constructor
*
* @param string|array|Zend_Config $options OPTIONAL
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp = array();
if (!empty($options)) {
$temp['encoding'] = array_shift($options);
}
$options = $temp;
}
if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) {
$options['encoding'] = mb_internal_encoding();
}
if (array_key_exists('encoding', $options)) {
$this->setEncoding($options['encoding']);
}
}
/**
* Returns the set encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* 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')) {
require_once 'Zend/Filter/Exception.php';
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()))) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
}
}
$this->_encoding = $encoding;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value, converting characters to lowercase as necessary
*
* @param string $value
* @return string
*/
public function filter($value)
{
if ($this->_encoding !== null) {
return mb_strtolower((string) $value, $this->_encoding);
}
return strtolower((string) $value);
}
}

Datei anzeigen

@ -0,0 +1,121 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_StringToUpper implements Zend_Filter_Interface
{
/**
* Encoding for the input string
*
* @var string
*/
protected $_encoding = null;
/**
* Constructor
*
* @param string|array $options OPTIONAL
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp = array();
if (!empty($options)) {
$temp['encoding'] = array_shift($options);
}
$options = $temp;
}
if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) {
$options['encoding'] = mb_internal_encoding();
}
if (array_key_exists('encoding', $options)) {
$this->setEncoding($options['encoding']);
}
}
/**
* Returns the set encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* 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')) {
require_once 'Zend/Filter/Exception.php';
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()))) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
}
}
$this->_encoding = $encoding;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value, converting characters to uppercase as necessary
*
* @param string $value
* @return string
*/
public function filter($value)
{
if ($this->_encoding) {
return mb_strtoupper((string) $value, $this->_encoding);
}
return strtoupper((string) $value);
}
}

Datei anzeigen

@ -0,0 +1,124 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_StringTrim implements Zend_Filter_Interface
{
/**
* List of characters provided to the trim() function
*
* If this is null, then trim() is called with no specific character list,
* and its default behavior will be invoked, trimming whitespace.
*
* @var string|null
*/
protected $_charList;
/**
* Sets filter options
*
* @param string|array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp['charlist'] = array_shift($options);
$options = $temp;
}
if (array_key_exists('charlist', $options)) {
$this->setCharList($options['charlist']);
}
}
/**
* Returns the charList option
*
* @return string|null
*/
public function getCharList()
{
return $this->_charList;
}
/**
* Sets the charList option
*
* @param string|null $charList
* @return Zend_Filter_StringTrim Provides a fluent interface
*/
public function setCharList($charList)
{
$this->_charList = $charList;
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value with characters stripped from the beginning and end
*
* @param string $value
* @return string
*/
public function filter($value)
{
if (null === $this->_charList) {
return $this->_unicodeTrim((string) $value);
} else {
return $this->_unicodeTrim((string) $value, $this->_charList);
}
}
/**
* Unicode aware trim method
* Fixes a PHP problem
*
* @param string $value
* @param string $charlist
* @return string
*/
protected function _unicodeTrim($value, $charlist = '\\\\s')
{
$chars = preg_replace(
array( '/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'),
array( '\\\\\\0', '\\', '\/' ),
$charlist
);
$pattern = '^[' . $chars . ']*|[' . $chars . ']*$';
return preg_replace("/$pattern/sSD", '', $value);
}
}

Datei anzeigen

@ -0,0 +1,48 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_StripNewlines implements Zend_Filter_Interface
{
/**
* Defined by Zend_Filter_Interface
*
* Returns $value without newline control characters
*
* @param string $value
* @return string
*/
public function filter ($value)
{
return str_replace(array("\n", "\r"), '', $value);
}
}

Datei anzeigen

@ -0,0 +1,352 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_StripTags implements Zend_Filter_Interface
{
/**
* Unique ID prefix used for allowing comments
*/
const UNIQUE_ID_PREFIX = '__Zend_Filter_StripTags__';
/**
* Whether comments are allowed
*
* If false (the default), then comments are removed from the input string.
*
* This setting is now deprecated, and ignored internally.
*
* @deprecated
* @var boolean
*/
public $commentsAllowed = false;
/**
* Array of allowed tags and allowed attributes for each allowed tag
*
* Tags are stored in the array keys, and the array values are themselves
* arrays of the attributes allowed for the corresponding tag.
*
* @var array
*/
protected $_tagsAllowed = array();
/**
* Array of allowed attributes for all allowed tags
*
* Attributes stored here are allowed for all of the allowed tags.
*
* @var array
*/
protected $_attributesAllowed = array();
/**
* Sets the filter options
* Allowed options are
* 'allowTags' => Tags which are allowed
* 'allowAttribs' => Attributes which are allowed
* 'allowComments' => Are comments allowed ?
*
* @param string|array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if ((!is_array($options)) || (is_array($options) && !array_key_exists('allowTags', $options) &&
!array_key_exists('allowAttribs', $options) && !array_key_exists('allowComments', $options))) {
$options = func_get_args();
$temp['allowTags'] = array_shift($options);
if (!empty($options)) {
$temp['allowAttribs'] = array_shift($options);
}
if (!empty($options)) {
$temp['allowComments'] = array_shift($options);
}
$options = $temp;
}
if (array_key_exists('allowTags', $options)) {
$this->setTagsAllowed($options['allowTags']);
}
if (array_key_exists('allowAttribs', $options)) {
$this->setAttributesAllowed($options['allowAttribs']);
}
if (array_key_exists('allowComments', $options)) {
$this->setCommentsAllowed($options['allowComments']);
}
}
/**
* Returns the commentsAllowed option
*
* This setting is now deprecated and ignored internally.
*
* @deprecated
* @return bool
*/
public function getCommentsAllowed()
{
return $this->commentsAllowed;
}
/**
* Sets the commentsAllowed option
*
* This setting is now deprecated and ignored internally.
*
* @deprecated
* @param boolean $commentsAllowed
* @return Zend_Filter_StripTags Provides a fluent interface
*/
public function setCommentsAllowed($commentsAllowed)
{
$this->commentsAllowed = (boolean) $commentsAllowed;
return $this;
}
/**
* Returns the tagsAllowed option
*
* @return array
*/
public function getTagsAllowed()
{
return $this->_tagsAllowed;
}
/**
* Sets the tagsAllowed option
*
* @param array|string $tagsAllowed
* @return Zend_Filter_StripTags Provides a fluent interface
*/
public function setTagsAllowed($tagsAllowed)
{
if (!is_array($tagsAllowed)) {
$tagsAllowed = array($tagsAllowed);
}
foreach ($tagsAllowed as $index => $element) {
// If the tag was provided without attributes
if (is_int($index) && is_string($element)) {
// Canonicalize the tag name
$tagName = strtolower($element);
// Store the tag as allowed with no attributes
$this->_tagsAllowed[$tagName] = array();
}
// Otherwise, if a tag was provided with attributes
else if (is_string($index) && (is_array($element) || is_string($element))) {
// Canonicalize the tag name
$tagName = strtolower($index);
// Canonicalize the attributes
if (is_string($element)) {
$element = array($element);
}
// Store the tag as allowed with the provided attributes
$this->_tagsAllowed[$tagName] = array();
foreach ($element as $attribute) {
if (is_string($attribute)) {
// Canonicalize the attribute name
$attributeName = strtolower($attribute);
$this->_tagsAllowed[$tagName][$attributeName] = null;
}
}
}
}
return $this;
}
/**
* Returns the attributesAllowed option
*
* @return array
*/
public function getAttributesAllowed()
{
return $this->_attributesAllowed;
}
/**
* Sets the attributesAllowed option
*
* @param array|string $attributesAllowed
* @return Zend_Filter_StripTags Provides a fluent interface
*/
public function setAttributesAllowed($attributesAllowed)
{
if (!is_array($attributesAllowed)) {
$attributesAllowed = array($attributesAllowed);
}
// Store each attribute as allowed
foreach ($attributesAllowed as $attribute) {
if (is_string($attribute)) {
// Canonicalize the attribute name
$attributeName = strtolower($attribute);
$this->_attributesAllowed[$attributeName] = null;
}
}
return $this;
}
/**
* Defined by Zend_Filter_Interface
*
* @todo improve docblock descriptions
*
* @param string $value
* @return string
*/
public function filter($value)
{
$value = (string) $value;
// Strip HTML comments first
while (strpos($value, '<!--') !== false) {
$pos = strrpos($value, '<!--');
$start = substr($value, 0, $pos);
$value = substr($value, $pos);
// If there is no comment closing tag, strip whole text
if (!preg_match('/--\s*>/s', $value)) {
$value = '';
} else {
$value = preg_replace('/<(?:!(?:--[\s\S]*?--\s*)?(>))/s', '', $value);
}
$value = $start . $value;
}
// Initialize accumulator for filtered data
$dataFiltered = '';
// Parse the input data iteratively as regular pre-tag text followed by a
// tag; either may be empty strings
preg_match_all('/([^<]*)(<?[^>]*>?)/', (string) $value, $matches);
// Iterate over each set of matches
foreach ($matches[1] as $index => $preTag) {
// If the pre-tag text is non-empty, strip any ">" characters from it
if (strlen($preTag)) {
$preTag = str_replace('>', '', $preTag);
}
// If a tag exists in this match, then filter the tag
$tag = $matches[2][$index];
if (strlen($tag)) {
$tagFiltered = $this->_filterTag($tag);
} else {
$tagFiltered = '';
}
// Add the filtered pre-tag text and filtered tag to the data buffer
$dataFiltered .= $preTag . $tagFiltered;
}
// Return the filtered data
return $dataFiltered;
}
/**
* Filters a single tag against the current option settings
*
* @param string $tag
* @return string
*/
protected function _filterTag($tag)
{
// Parse the tag into:
// 1. a starting delimiter (mandatory)
// 2. a tag name (if available)
// 3. a string of attributes (if available)
// 4. an ending delimiter (if available)
$isMatch = preg_match('~(</?)(\w*)((/(?!>)|[^/>])*)(/?>)~', $tag, $matches);
// If the tag does not match, then strip the tag entirely
if (!$isMatch) {
return '';
}
// Save the matches to more meaningfully named variables
$tagStart = $matches[1];
$tagName = strtolower($matches[2]);
$tagAttributes = $matches[3];
$tagEnd = $matches[5];
// If the tag is not an allowed tag, then remove the tag entirely
if (!isset($this->_tagsAllowed[$tagName])) {
return '';
}
// Trim the attribute string of whitespace at the ends
$tagAttributes = trim($tagAttributes);
// If there are non-whitespace characters in the attribute string
if (strlen($tagAttributes)) {
// Parse iteratively for well-formed attributes
preg_match_all('/(\w+)\s*=\s*(?:(")(.*?)"|(\')(.*?)\')/s', $tagAttributes, $matches);
// Initialize valid attribute accumulator
$tagAttributes = '';
// Iterate over each matched attribute
foreach ($matches[1] as $index => $attributeName) {
$attributeName = strtolower($attributeName);
$attributeDelimiter = empty($matches[2][$index]) ? $matches[4][$index] : $matches[2][$index];
$attributeValue = empty($matches[3][$index]) ? $matches[5][$index] : $matches[3][$index];
// If the attribute is not allowed, then remove it entirely
if (!array_key_exists($attributeName, $this->_tagsAllowed[$tagName])
&& !array_key_exists($attributeName, $this->_attributesAllowed)) {
continue;
}
// Add the attribute to the accumulator
$tagAttributes .= " $attributeName=" . $attributeDelimiter
. $attributeValue . $attributeDelimiter;
}
}
// Reconstruct tags ending with "/>" as backwards-compatible XHTML tag
if (strpos($tagEnd, '/') !== false) {
$tagEnd = " $tagEnd";
}
// Return the filtered tag
return $tagStart . $tagName . $tagAttributes . $tagEnd;
}
}

Datei anzeigen

@ -0,0 +1,44 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Word/CamelCaseToSeparator.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_CamelCaseToDash extends Zend_Filter_Word_CamelCaseToSeparator
{
/**
* Constructor
*
* @return void
*/
public function __construct()
{
parent::__construct('-');
}
}

Datei anzeigen

@ -0,0 +1,49 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/Word/Separator/Abstract.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_CamelCaseToSeparator extends Zend_Filter_Word_Separator_Abstract
{
public function filter($value)
{
if (self::isUnicodeSupportEnabled()) {
parent::setMatchPattern(array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#','#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#'));
parent::setReplacement(array($this->_separator . '\1', $this->_separator . '\1'));
} else {
parent::setMatchPattern(array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'));
parent::setReplacement(array('\1' . $this->_separator . '\2', $this->_separator . '\1'));
}
return parent::filter($value);
}
}

Datei anzeigen

@ -0,0 +1,44 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_CamelCaseToSeparator
*/
require_once 'Zend/Filter/Word/CamelCaseToSeparator.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_CamelCaseToUnderscore extends Zend_Filter_Word_CamelCaseToSeparator
{
/**
* Constructor
*
* @return void
*/
public function __construct()
{
parent::__construct('_');
}
}

Datei anzeigen

@ -0,0 +1,44 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Word/SeparatorToCamelCase.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_DashToCamelCase extends Zend_Filter_Word_SeparatorToCamelCase
{
/**
* Constructor
*
* @return void
*/
public function __construct()
{
parent::__construct('-');
}
}

Datei anzeigen

@ -0,0 +1,42 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/Word/Separator/Abstract.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_DashToSeparator extends Zend_Filter_Word_Separator_Abstract
{
public function filter($value)
{
$this->setMatchPattern('#-#');
$this->setReplacement($this->_separator);
return parent::filter($value);
}
}

Datei anzeigen

@ -0,0 +1,45 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/Word/SeparatorToSeparator.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_DashToUnderscore extends Zend_Filter_Word_SeparatorToSeparator
{
/**
* Constructor
*
* @param string $separator Space by default
* @return void
*/
public function __construct()
{
parent::__construct('-', '_');
}
}

Datei anzeigen

@ -0,0 +1,76 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/PregReplace.php';
/**
* @category Zend
* @package Zend_Filter
* @uses Zend_Filter_PregReplace
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Filter_Word_Separator_Abstract extends Zend_Filter_PregReplace
{
protected $_separator = null;
/**
* Constructor
*
* @param string $separator Space by default
* @return void
*/
public function __construct($separator = ' ')
{
$this->setSeparator($separator);
}
/**
* Sets a new seperator
*
* @param string $separator Seperator
* @return $this
*/
public function setSeparator($separator)
{
if ($separator == null) {
require_once 'Zend/Filter/Exception.php';
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()
{
return $this->_separator;
}
}

Datei anzeigen

@ -0,0 +1,52 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/Word/Separator/Abstract.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_SeparatorToCamelCase extends Zend_Filter_Word_Separator_Abstract
{
public function filter($value)
{
// a unicode safe way of converting characters to \x00\x00 notation
$pregQuotedSeparator = preg_quote($this->_separator, '#');
if (self::isUnicodeSupportEnabled()) {
parent::setMatchPattern(array('#('.$pregQuotedSeparator.')(\p{L}{1})#e','#(^\p{Ll}{1})#e'));
parent::setReplacement(array("strtoupper('\\2')","strtoupper('\\1')"));
} else {
parent::setMatchPattern(array('#('.$pregQuotedSeparator.')([A-Za-z]{1})#e','#(^[A-Za-z]{1})#e'));
parent::setReplacement(array("strtoupper('\\2')","strtoupper('\\1')"));
}
return parent::filter($value);
}
}

Datei anzeigen

@ -0,0 +1,46 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_SeperatorToSeparator
*/
require_once 'Zend/Filter/Word/SeparatorToSeparator.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_SeparatorToDash extends Zend_Filter_Word_SeparatorToSeparator
{
/**
* Constructor
*
* @param string $searchSeparator Seperator to search for change
* @return void
*/
public function __construct($searchSeparator = ' ')
{
parent::__construct($searchSeparator, '-');
}
}

Datei anzeigen

@ -0,0 +1,129 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/PregReplace.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_SeparatorToSeparator extends Zend_Filter_PregReplace
{
protected $_searchSeparator = null;
protected $_replacementSeparator = null;
/**
* Constructor
*
* @param string $searchSeparator Seperator to search for
* @param string $replacementSeperator Seperator to replace with
* @return void
*/
public function __construct($searchSeparator = ' ', $replacementSeparator = '-')
{
$this->setSearchSeparator($searchSeparator);
$this->setReplacementSeparator($replacementSeparator);
}
/**
* Sets a new seperator to search for
*
* @param string $separator Seperator to search for
* @return $this
*/
public function setSearchSeparator($separator)
{
$this->_searchSeparator = $separator;
return $this;
}
/**
* Returns the actual set seperator to search for
*
* @return string
*/
public function getSearchSeparator()
{
return $this->_searchSeparator;
}
/**
* Sets a new seperator which replaces the searched one
*
* @param string $separator Seperator which replaces the searched one
* @return $this
*/
public function setReplacementSeparator($separator)
{
$this->_replacementSeparator = $separator;
return $this;
}
/**
* Returns the actual set seperator which replaces the searched one
*
* @return string
*/
public function getReplacementSeparator()
{
return $this->_replacementSeparator;
}
/**
* Defined by Zend_Filter_Interface
*
* Returns the string $value, replacing the searched seperators with the defined ones
*
* @param string $value
* @return string
*/
public function filter($value)
{
return $this->_separatorToSeparatorFilter($value);
}
/**
* 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) {
require_once 'Zend/Filter/Exception.php';
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);
}
}

Datei anzeigen

@ -0,0 +1,44 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Word/SeparatorToCamelCase.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_UnderscoreToCamelCase extends Zend_Filter_Word_SeparatorToCamelCase
{
/**
* Constructor
*
* @return void
*/
public function __construct()
{
parent::__construct('_');
}
}

Datei anzeigen

@ -0,0 +1,45 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/Word/SeparatorToSeparator.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_UnderscoreToDash extends Zend_Filter_Word_SeparatorToSeparator
{
/**
* Constructor
*
* @param string $separator Space by default
* @return void
*/
public function __construct()
{
parent::__construct('_', '-');
}
}

Datei anzeigen

@ -0,0 +1,45 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/Word/SeparatorToSeparator.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter_Word_UnderscoreToSeparator extends Zend_Filter_Word_SeparatorToSeparator
{
/**
* Constructor
*
* @param string $separator Space by default
* @return void
*/
public function __construct($replacementSeparator = ' ')
{
parent::__construct('_', $replacementSeparator);
}
}