Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid-sohrabloo committed Jul 5, 2012
15 parents 90b4677 + 79eb7d0 + 8cc5d58 + 869ab1c + 436e613 + ab7d56c + 6dbeef6 + 84670b1 + cccfba9 + 2717653 + b4dd364 + 460818e + b5ac15d + 2d218aa + 046d669 commit 5597f80
Show file tree
Hide file tree
Showing 79 changed files with 1,598 additions and 6,822 deletions.
14 changes: 0 additions & 14 deletions .travis/run-tests.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .travis/skipped-components

This file was deleted.

61 changes: 0 additions & 61 deletions .travis/tested-components

This file was deleted.

83 changes: 83 additions & 0 deletions src/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

namespace Zend\Filter;

use Traversable;
use Zend\Stdlib\ArrayUtils;

/**
* @category Zend
* @package Zend_Filter
Expand All @@ -28,6 +31,76 @@
*/
abstract class AbstractFilter implements FilterInterface
{
/**
* Filter options
*
* @var array
*/
protected $options = array();

/**
* Is PCRE is compiled with UTF-8 and Unicode support
*
* @var boolean
**/
protected static $hasPcreUnicodeSupport = null;

/**
* @return bool
*/
public static function hasPcreUnicodeSupport()
{
if (static::$hasPcreUnicodeSupport === null) {
if (defined('PREG_BAD_UTF8_OFFSET_ERROR') || @preg_match('/\pL/u', 'a') == 1){
static::$hasPcreUnicodeSupport = true;
} else {
static::$hasPcreUnicodeSupport = false;
}
}
return static::$hasPcreUnicodeSupport;
}

/**
* @param array|Traversable $options
* @return AbstractFilter
* @throws Exception\InvalidArgumentException
*/
public function setOptions($options)
{
if (!is_array($options) && !$options instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'"%s" expects an array or Traversable; received "%s"',
__METHOD__,
(is_object($options) ? get_class($options) : gettype($options))
));
}

foreach ($options as $key => $value) {
$setter = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
if (method_exists($this, $setter)) {
$this->{$setter}($value);
} elseif (array_key_exists($key, $this->options)) {
$this->options[$key] = $value;
} else {
throw new Exception\InvalidArgumentException(sprintf(
'The option "%s" does not have a matching %s setter method or options[%s] array key',
$key, $setter, $key
));
}
}
return $this;
}

/**
* Retrieve options representing object state
*
* @return array
*/
public function getOptions()
{
return $this->options;
}

/**
* Invoke filter as a command
*
Expand All @@ -41,4 +114,14 @@ public function __invoke($value)
{
return $this->filter($value);
}

/**
*
* @param mixed $options
* @return bool
*/
protected static function isOptions($options)
{
return (is_array($options) || $options instanceof Traversable);
}
}
76 changes: 76 additions & 0 deletions src/AbstractUnicode.php
Original file line number Diff line number Diff line change
@@ -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 [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Filter;

/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class AbstractUnicode extends AbstractFilter
{
/**
* Set the input encoding for the given string
*
* @param string|null $encoding
* @return StringToLower
* @throws Exception\InvalidArgumentException
* @throws Exception\ExtensionNotLoadedException
*/
public function setEncoding($encoding = null)
{
if ($encoding !== null) {
if (!function_exists('mb_strtolower')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s requires mbstring extension to be loaded',
get_class($this)
));
}

$encoding = strtolower($encoding);
$mbEncodings = array_map('strtolower', mb_list_encodings());
if (!in_array($encoding, $mbEncodings)) {
throw new Exception\InvalidArgumentException(sprintf(
"Encoding '%s' is not supported by mbstring extension",
$encoding
));
}
}

$this->options['encoding'] = $encoding;
return $this;
}

/**
* Returns the set encoding
*
* @return string
*/
public function getEncoding()
{
if ($this->options['encoding'] === null && function_exists('mb_internal_encoding')) {
$this->options['encoding'] = mb_internal_encoding();
}

return $this->options['encoding'];
}
}
Loading

0 comments on commit 5597f80

Please sign in to comment.