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

Commit

Permalink
Merge branch 'feature/i18n-filters-upd' of https://github.com/denixpo…
Browse files Browse the repository at this point in the history
…rt/zf2 into feature/i18n-filters
  • Loading branch information
weierophinney committed Jul 3, 2012
14 parents 8cc5d58 + 869ab1c + 436e613 + ab7d56c + 6dbeef6 + 84670b1 + cccfba9 + 2717653 + b4dd364 + 460818e + b5ac15d + 2d218aa + 046d669 + 9ff7ef3 commit 79eb7d0
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 653 deletions.
57 changes: 0 additions & 57 deletions src/AbstractLocale.php

This file was deleted.

109 changes: 0 additions & 109 deletions src/Alnum.php

This file was deleted.

59 changes: 0 additions & 59 deletions src/Alpha.php

This file was deleted.

77 changes: 36 additions & 41 deletions src/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
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
*/
class Boolean extends AbstractLocale
class Boolean extends AbstractFilter
{
const TYPE_BOOLEAN = 1;
const TYPE_INTEGER = 2;
Expand Down Expand Up @@ -67,35 +66,38 @@ class Boolean extends AbstractLocale
protected $options = array(
'type' => self::TYPE_PHP,
'casting' => true,
'locale' => null,
'translations' => array(),
);

/**
* Constructor
*
* @param string|array|Traversable $options OPTIONAL
* @param array|Traversable|int|null $typeOrOptions
* @param bool $casting
* @param array $translations
*/
public function __construct($options = null)
public function __construct($typeOrOptions = null, $casting = true, $translations = array())
{
if ($options !== null) {
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
if ($typeOrOptions !== null) {
if ($typeOrOptions instanceof Traversable) {
$typeOrOptions = ArrayUtils::iteratorToArray($typeOrOptions);
}

if (!is_array($options)) {
$args = func_get_args();
if (isset($args[0])) {
$this->setType($args[0]);
}
if (isset($args[1])) {
$this->setCasting($args[1]);
}
if (isset($args[2])) {
$this->setLocale($args[2]);
if (is_array($typeOrOptions)) {
if (isset($typeOrOptions['type'])
|| isset($typeOrOptions['casting'])
|| isset($typeOrOptions['translations']))
{
$this->setOptions($typeOrOptions);
} else {
$this->setType($typeOrOptions);
$this->setCasting($casting);
$this->setTranslations($translations);
}
} else {
$this->setOptions($options);
$this->setType($typeOrOptions);
$this->setCasting($casting);
$this->setTranslations($translations);
}
}
}
Expand Down Expand Up @@ -171,14 +173,23 @@ public function getCasting()
}

/**
* @param array $translations
* @param array|Traversable $translations
* @return Boolean
*/
public function setTranslations(array $translations)
public function setTranslations($translations)
{
foreach ($translations as $locale => $translation) {
$this->addTranslation($locale, $translation);
if (!is_array($translations) && !$translations instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'"%s" expects an array or Traversable; received "%s"',
__METHOD__,
(is_object($translations) ? get_class($translations) : gettype($translations))
));
}

foreach ($translations as $message => $flag) {
$this->options['translations'][$message] = (bool) $flag;
}

return $this;
}

Expand All @@ -190,21 +201,6 @@ public function getTranslations()
return $this->options['translations'];
}

/**
* @param string $locale
* @param array $translation
* @return Boolean
* @throws Exception\InvalidArgumentException
*/
public function addTranslation($locale, array $translation)
{
foreach ($translation as $message => $flag) {
$this->options['translations'][$locale][$message] = (bool) $flag;
}

return $this;
}

/**
* Defined by Zend\Filter\FilterInterface
*
Expand All @@ -222,9 +218,8 @@ public function filter($value)
if ($type >= self::TYPE_LOCALIZED) {
$type -= self::TYPE_LOCALIZED;
if (is_string($value)) {
$locale = $this->getLocale();
if (isset($this->options['translations'][$locale][$value])) {
return (bool) $this->options['translations'][$locale][$value];
if (isset($this->options['translations'][$value])) {
return (bool) $this->options['translations'][$value];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/FilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class FilterPluginManager extends AbstractPluginManager
* @var array
*/
protected $invokableClasses = array(
'alnum' => 'Zend\Filter\Alnum',
'alpha' => 'Zend\Filter\Alpha',
'alnum' => 'Zend\I18n\Filter\Alnum',
'alpha' => 'Zend\I18n\Filter\Alpha',
'basename' => 'Zend\Filter\BaseName',
'boolean' => 'Zend\Filter\Boolean',
'callback' => 'Zend\Filter\Callback',
Expand Down
Loading

0 comments on commit 79eb7d0

Please sign in to comment.