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

Commit

Permalink
Merge remote-tracking branch 'zf2/master' into feature/doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Jul 11, 2012
Show file tree
Hide file tree
Showing 123 changed files with 1,861 additions and 4,955 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zendframework/zend-filter",
"description": "Zend\\Filter component",
"description": "provides a set of commonly needed data filters",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
Expand All @@ -9,11 +9,11 @@
"homepage": "https://github.com/zendframework/zend-filter",
"autoload": {
"psr-4": {
"Zend\\Filter\\": "src/"
"Zend\\Filter": "src/"
}
},
"require": {
"php": ">=5.3.23",
"php": ">=5.3.3",
"zendframework/zend-stdlib": "self.version"
},
"require-dev": {
Expand All @@ -28,7 +28,8 @@
"zendframework/zend-crypt": "Zend\\Crypt component",
"zendframework/zend-i18n": "Zend\\I18n component",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component",
"zendframework/zend-uri": "Zend\\Uri component for UriNormalize filter"
"zendframework/zend-uri": "Zend\\Uri component for UriNormalize filter",
"zendframework/zend-validator": "Zend\\Validator component"
},
"extra": {
"branch-alias": {
Expand Down
105 changes: 88 additions & 17 deletions src/AbstractFilter.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,94 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Filter
*/

namespace Zend\Filter;

use Traversable;
use Zend\Stdlib\ArrayUtils;

/**
* @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 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 +102,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);
}
}
64 changes: 64 additions & 0 deletions src/AbstractUnicode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Filter
*/

namespace Zend\Filter;

/**
* @category Zend
* @package Zend_Filter
*/
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'];
}
}
167 changes: 0 additions & 167 deletions src/Alnum.php

This file was deleted.

Loading

0 comments on commit 7ed02b7

Please sign in to comment.