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

Commit

Permalink
Merge branch 'develop' of git://github.com/zendframework/zf2 into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 22 deletions.
20 changes: 10 additions & 10 deletions src/Translator/Plural/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ protected function evaluateAstPart(array $ast, $number)
*/
public static function fromString($string)
{
if (self::$parser === null) {
self::$parser = new Parser();
if (static::$parser === null) {
static::$parser = new Parser();
}

if (!preg_match('(nplurals=(?P<nplurals>\d+))', $string, $match)) {
Expand All @@ -202,8 +202,8 @@ public static function fromString($string)
));
}

$tree = self::$parser->parse($match['plural']);
$ast = self::createAst($tree);
$tree = static::$parser->parse($match['plural']);
$ast = static::createAst($tree);

return new self($numPlurals, $ast);
}
Expand All @@ -230,18 +230,18 @@ protected static function createAst(Symbol $symbol)
break;

case '!':
$ast['arguments'][] = self::createAst($symbol->first);
$ast['arguments'][] = static::createAst($symbol->first);
break;

case '?':
$ast['arguments'][] = self::createAst($symbol->first);
$ast['arguments'][] = self::createAst($symbol->second);
$ast['arguments'][] = self::createAst($symbol->third);
$ast['arguments'][] = static::createAst($symbol->first);
$ast['arguments'][] = static::createAst($symbol->second);
$ast['arguments'][] = static::createAst($symbol->third);
break;

default:
$ast['arguments'][] = self::createAst($symbol->first);
$ast['arguments'][] = self::createAst($symbol->second);
$ast['arguments'][] = static::createAst($symbol->first);
$ast['arguments'][] = static::createAst($symbol->second);
break;
}

Expand Down
120 changes: 120 additions & 0 deletions src/Translator/TranslatorAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?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_I18n
*/

namespace Zend\I18n\Translator;

use Zend\I18n\Translator\Translator;

/**
* @category Zend
* @package Zend_I18n
* @subpackage Translator
*/
trait TranslatorAwareTrait
{
/**
* @var Translator
*/
protected $translator = null;

/**
* @var bool
*/
protected $translatorEnabled = true;

/**
* @var string
*/
protected $translatorTextDomain = 'default';

/**
* Sets translator to use in helper
*
* @param Translator $translator
* @param string $textDomain
* @return mixed
*/
public function setTranslator(Translator $translator = null, $textDomain = null)
{
$this->translator = $translator;

if (!is_null($textDomain)) {
$this->setTranslatorTextDomain($textDomain);
}

return $this;
}

/**
* Returns translator used in object
*
* @return Translator
*/
public function getTranslator()
{
return $this->translator;
}

/**
* Checks if the object has a translator
*
* @return bool
*/
public function hasTranslator()
{
return !is_null($this->translator);
}

/**
* Sets whether translator is enabled and should be used
*
* @param bool $enabled
* @return mixed
*/
public function setTranslatorEnabled($enabled = true)
{
$this->translatorEnabled = $enabled;

return $this;
}

/**
* Returns whether translator is enabled and should be used
*
* @return bool
*/
public function isTranslatorEnabled()
{
return $this->translatorEnabled;
}

/**
* Set translation text domain
*
* @param string $textDomain
* @return mixed
*/
public function setTranslatorTextDomain($textDomain = 'default')
{
$this->translatorTextDomain = $textDomain;

return $this;
}

/**
* Return the translation text domain
*
* @return string
*/
public function getTranslatorTextDomain()
{
return $this->translatorTextDomain;
}
}
8 changes: 4 additions & 4 deletions src/Validator/Alnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ public function isValid($value)
return false;
}

if (null === self::$filter) {
self::$filter = new AlnumFilter();
if (null === static::$filter) {
static::$filter = new AlnumFilter();
}

self::$filter->setAllowWhiteSpace($this->options['allowWhiteSpace']);
static::$filter->setAllowWhiteSpace($this->options['allowWhiteSpace']);

if ($value != self::$filter->filter($value)) {
if ($value != static::$filter->filter($value)) {
$this->error(self::NOT_ALNUM);
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Validator/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public function isValid($value)
return false;
}

if (null === self::$filter) {
self::$filter = new AlphaFilter();
if (null === static::$filter) {
static::$filter = new AlphaFilter();
}

//self::$filter->setAllowWhiteSpace($this->allowWhiteSpace);
self::$filter->setAllowWhiteSpace($this->options['allowWhiteSpace']);
//static::$filter->setAllowWhiteSpace($this->allowWhiteSpace);
static::$filter->setAllowWhiteSpace($this->options['allowWhiteSpace']);

if ($value !== self::$filter->filter($value)) {
if ($value !== static::$filter->filter($value)) {
$this->error(self::NOT_ALPHA);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/PostCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ public function isValid($value)
if ('' === $region) {
throw new Exception\InvalidArgumentException("Locale must contain a region");
}
if (isset(self::$postCodeRegex[$region])) {
$format = self::$postCodeRegex[$region];
if (isset(static::$postCodeRegex[$region])) {
$format = static::$postCodeRegex[$region];
}
}
if (null === $format || '' === $format) {
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __invoke(
}

$timezone = $this->getTimezone();
$formatterId = md5($dateType . "\0" . $timeType . "\0" . $locale);
$formatterId = md5($dateType . "\0" . $timeType . "\0" . $locale ."\0" . $pattern);

if (!isset($this->formatters[$formatterId])) {
$this->formatters[$formatterId] = new IntlDateFormatter(
Expand Down
129 changes: 129 additions & 0 deletions test/Translator/TranslatorAwareTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?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_I18n
*/

namespace ZendTest\I18n\Translator;

use \PHPUnit_Framework_TestCase as TestCase;
use \Zend\I18n\Translator\Translator;

/**
* @requires PHP 5.4
*/
class TranslatorAwareTraitTest extends TestCase
{
public function testSetTranslator()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertAttributeEquals(null, 'translator', $object);

$translator = new Translator;

$object->setTranslator($translator);

$this->assertAttributeEquals($translator, 'translator', $object);
}

public function testSetTranslatorAndTextDomain()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertAttributeEquals(null, 'translator', $object);
$this->assertAttributeEquals('default', 'translatorTextDomain', $object);

$translator = new Translator;
$textDomain = 'domain';

$object->setTranslator($translator, $textDomain);

$this->assertAttributeEquals($translator, 'translator', $object);
$this->assertAttributeEquals($textDomain, 'translatorTextDomain', $object);
}

public function testGetTranslator()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertNull($object->getTranslator());

$translator = new Translator;

$object->setTranslator($translator);

$this->assertEquals($translator, $object->getTranslator());
}

public function testHasTranslator()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertFalse($object->hasTranslator());

$translator = new Translator;

$object->setTranslator($translator);

$this->assertTrue($object->hasTranslator());
}

public function testSetTranslatorEnabled()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertAttributeEquals(true, 'translatorEnabled', $object);

$enabled = false;

$object->setTranslatorEnabled($enabled);

$this->assertAttributeEquals($enabled, 'translatorEnabled', $object);

$object->setTranslatorEnabled();

$this->assertAttributeEquals(true, 'translatorEnabled', $object);
}

public function testIsTranslatorEnabled()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertTrue($object->isTranslatorEnabled());

$object->setTranslatorEnabled(false);

$this->assertFalse($object->isTranslatorEnabled());
}

public function testSetTranslatorTextDomain()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertAttributeEquals('default', 'translatorTextDomain', $object);

$textDomain = 'domain';

$object->setTranslatorTextDomain($textDomain);

$this->assertAttributeEquals($textDomain, 'translatorTextDomain', $object);
}

public function testGetTranslatorTextDomain()
{
$object = $this->getObjectForTrait('\Zend\I18n\Translator\TranslatorAwareTrait');

$this->assertEquals('default', $object->getTranslatorTextDomain());

$textDomain = 'domain';

$object->setTranslatorTextDomain($textDomain);

$this->assertEquals($textDomain, $object->getTranslatorTextDomain());
}
}
10 changes: 10 additions & 0 deletions test/View/Helper/DateFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ public function testDefaultLocale()
$this->assertEquals(Locale::getDefault(), $this->helper->getLocale());
}

public function testBugTwoPatternOnSameHelperInstance()
{
$date = new DateTime('2012-07-02T22:44:03Z');

$helper = new DateFormatHelper();
$helper->setTimezone('Europe/Berlin');
$this->assertEquals('03/2012', $helper->__invoke($date, null, null, 'it_IT', 'dd/Y'));
$this->assertEquals('03-2012', $helper->__invoke($date, null, null, 'it_IT', 'dd-Y'));
}

public function assertMbStringEquals($expected, $test, $message = '')
{
$expected = str_replace(array("\xC2\xA0", ' '), '', $expected);
Expand Down

0 comments on commit 83d837e

Please sign in to comment.