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' into ValidatorMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Szendi committed Nov 4, 2013
Show file tree
Hide file tree
Showing 37 changed files with 232 additions and 118 deletions.
26 changes: 19 additions & 7 deletions src/Validator/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class PhoneNumber extends AbstractValidator
protected $messageTemplates = array(
self::NO_MATCH => 'The input does not match a phone number format',
self::UNSUPPORTED => 'The country provided is currently unsupported',
self::INVALID => 'Invalid type given. String expected',
self::INVALID => 'Invalid type given. String expected',
);

/**
* Phone Number Patterns
*
* @link http://libphonenumber.googlecode.com/svn/trunk/resources/PhoneNumberMetaData.xml
* @link http://code.google.com/p/libphonenumber/source/browse/trunk/resources/PhoneNumberMetadata.xml
* @var array
*/
protected static $phone = array();
Expand Down Expand Up @@ -164,7 +164,7 @@ public function setCountry($country)
*/
protected function loadPattern($code)
{
if (!isset(self::$phone[$code])) {
if (!isset(static::$phone[$code])) {
if (!preg_match('/^[A-Z]{2}$/D', $code)) {
return false;
}
Expand All @@ -174,10 +174,10 @@ protected function loadPattern($code)
return false;
}

self::$phone[$code] = include $file;
static::$phone[$code] = include $file;
}

return self::$phone[$code];
return static::$phone[$code];
}

/**
Expand Down Expand Up @@ -210,8 +210,20 @@ public function isValid($value = null, $context = null)
}
}

if ($countryPattern['code'] == substr($value, 0, strlen($countryPattern['code']))) {
$valueNoCountry = substr($value, strlen($countryPattern['code']));
$codeLength = strlen($countryPattern['code']);

/*
* Check for existence of either:
* 1) E.123/E.164 international prefix
* 2) International double-O prefix
* 3) Bare country prefix
*/
if (('+' . $countryPattern['code']) == substr($value, 0, $codeLength + 1)) {
$valueNoCountry = substr($value, $codeLength + 1);
} elseif (('00' . $countryPattern['code']) == substr($value, 0, $codeLength + 2)) {
$valueNoCountry = substr($value, $codeLength + 2);
} elseif ($countryPattern['code'] == substr($value, 0, $codeLength)) {
$valueNoCountry = substr($value, $codeLength);
}

// check against allowed types strict match:
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/PhoneNumber/MO.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'national' => array(
'general' => '/^[268]\\d{7}$/',
'fixed' => '/^(?:28[2-57-9]|8[2-57-9]\\d)\\d{5}$/',
'mobile' => '/^6[236]\\d{6}$/',
'mobile' => '/^6[2356]\\d{6}$/',
'emergency' => '/^999$/',
),
'possible' => array(
Expand Down
26 changes: 23 additions & 3 deletions src/View/Helper/CurrencyFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,33 @@ public function __invoke(
if (null === $currencyCode) {
$currencyCode = $this->getCurrencyCode();
}
if (null !== $showDecimals) {
$this->setShouldShowDecimals($showDecimals);
if (null === $showDecimals) {
$showDecimals = $this->shouldShowDecimals();
}
if (null === $pattern) {
$pattern = $this->getCurrencyPattern();
}

return $this->formatCurrency($number, $currencyCode, $showDecimals, $locale, $pattern);
}

/**
* Format a number
*
* @param float $number
* @param string $currencyCode
* @param bool $showDecimals
* @param string $locale
* @param string $pattern
* @return string
*/
protected function formatCurrency(
$number,
$currencyCode,
$showDecimals,
$locale,
$pattern
) {
$formatterId = md5($locale);

if (!isset($this->formatters[$formatterId])) {
Expand All @@ -110,7 +130,7 @@ public function __invoke(
$this->formatters[$formatterId]->setPattern($pattern);
}

if ($this->shouldShowDecimals()) {
if ($showDecimals) {
$this->formatters[$formatterId]->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
} else {
$this->formatters[$formatterId]->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
Expand Down
7 changes: 5 additions & 2 deletions src/View/Helper/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __invoke(
}

// DateTime support for IntlDateFormatter::format() was only added in 5.3.4
if ($date instanceof DateTime && version_compare(PHP_VERSION, '5.3.4', '<')) {
if ($date instanceof DateTime && (PHP_VERSION_ID < 50304)) {
$date = $date->getTimestamp();
}

Expand Down Expand Up @@ -133,8 +133,11 @@ public function setTimezone($timezone)
{
$this->timezone = (string) $timezone;

// The method setTimeZoneId is deprecated as of PHP 5.5.0
$setTimeZoneMethodName = (PHP_VERSION_ID < 50500) ? 'setTimeZoneId' : 'setTimeZone';

foreach ($this->formatters as $formatter) {
$formatter->setTimeZoneId($this->timezone);
$formatter->$setTimeZoneMethodName($this->timezone);
}

return $this;
Expand Down
20 changes: 10 additions & 10 deletions test/Filter/AlnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_I18n
*/

namespace ZendTest\Filter;
Expand All @@ -14,9 +13,6 @@
use Locale;

/**
* @category Zend
* @package Zend_Filter
* @subpackage UnitTests
* @group Zend_Filter
*/
class AlnumTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -56,12 +52,16 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('ext/intl not enabled');
}

$this->filter = new AlnumFilter();

$this->locale = Locale::getDefault();
$language = Locale::getPrimaryLanguage($this->locale);
self::$meansEnglishAlphabet = in_array($language, array('ja'));
self::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
static::$meansEnglishAlphabet = in_array($language, array('ja'));
static::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
}

/**
Expand All @@ -71,7 +71,7 @@ public function setUp()
*/
public function testBasic()
{
if (!self::$unicodeEnabled) {
if (!static::$unicodeEnabled) {
// POSIX named classes are not supported, use alternative a-zA-Z match
$valuesExpected = array(
'abc123' => 'abc123',
Expand All @@ -80,7 +80,7 @@ public function testBasic()
'AZ@#4.3' => 'AZ43',
'' => ''
);
} elseif (self::$meansEnglishAlphabet) {
} elseif (static::$meansEnglishAlphabet) {
// The Alphabet means english alphabet.

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testAllowWhiteSpace()
{
$this->filter->setAllowWhiteSpace(true);

if (!self::$unicodeEnabled) {
if (!static::$unicodeEnabled) {
// POSIX named classes are not supported, use alternative a-zA-Z match
$valuesExpected = array(
'abc123' => 'abc123',
Expand All @@ -134,7 +134,7 @@ public function testAllowWhiteSpace()
"\n" => "\n",
" \t " => " \t "
);
} elseif (self::$meansEnglishAlphabet) {
} elseif (static::$meansEnglishAlphabet) {
//The Alphabet means english alphabet.
$valuesExpected = array(
'a B 45' => 'a B 5',
Expand Down
8 changes: 4 additions & 4 deletions test/Filter/AlphaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_I18n
*/

namespace ZendTest\Filter;
Expand All @@ -14,9 +13,6 @@
use Locale;

/**
* @category Zend
* @package Zend_Filter
* @subpackage UnitTests
* @group Zend_Filter
*/
class AlphaTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -56,6 +52,10 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('ext/intl not enabled');
}

$this->filter = new AlphaFilter();

$this->locale = Locale::getDefault();
Expand Down
28 changes: 25 additions & 3 deletions test/Filter/NumberFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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\Filter;
Expand All @@ -16,6 +15,13 @@

class NumberFormatTest extends TestCase
{
public function setUp()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('ext/intl not enabled');
}
}

public function testConstructWithOptions()
{
$filter = new NumberFormatFilter(array(
Expand Down Expand Up @@ -64,8 +70,16 @@ public function testFormattedToNumber($locale, $style, $type, $value, $expected)
$this->assertEquals($expected, $filter->filter($value));
}

public static function numberToFormattedProvider()
public function numberToFormattedProvider()
{
if (!extension_loaded('intl')) {
if (version_compare(\PHPUnit_Runner_Version::VERSION, '3.8.0-dev') === 1) {
$this->markTestSkipped('ext/intl not enabled');
} else {
return array(array());
}
}

return array(
array(
'en_US',
Expand All @@ -91,8 +105,16 @@ public static function numberToFormattedProvider()
);
}

public static function formattedToNumberProvider()
public function formattedToNumberProvider()
{
if (!extension_loaded('intl')) {
if (version_compare(\PHPUnit_Runner_Version::VERSION, '3.8.0-dev') === 1) {
$this->markTestSkipped('ext/intl not enabled');
} else {
return array(array());
}
}

return array(
array(
'en_US',
Expand Down
9 changes: 7 additions & 2 deletions test/Translator/Loader/GettextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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\Loader;
Expand All @@ -21,6 +20,10 @@ class GettextTest extends TestCase

public function setUp()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('ext/intl not enabled');
}

$this->originalLocale = Locale::getDefault();
Locale::setDefault('en_EN');

Expand All @@ -29,7 +32,9 @@ public function setUp()

public function tearDown()
{
Locale::setDefault($this->originalLocale);
if (extension_loaded('intl')) {
Locale::setDefault($this->originalLocale);
}
}

public function testLoaderFailsToLoadMissingFile()
Expand Down
1 change: 0 additions & 1 deletion test/Translator/Loader/IniTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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\Loader;
Expand Down
9 changes: 7 additions & 2 deletions test/Translator/Loader/PhpArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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\Loader;
Expand All @@ -21,6 +20,10 @@ class PhpArrayTest extends TestCase

public function setUp()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('ext/intl not enabled');
}

$this->originalLocale = Locale::getDefault();
Locale::setDefault('en_EN');

Expand All @@ -29,7 +32,9 @@ public function setUp()

public function tearDown()
{
Locale::setDefault($this->originalLocale);
if (extension_loaded('intl')) {
Locale::setDefault($this->originalLocale);
}
}

public function testLoaderFailsToLoadMissingFile()
Expand Down
1 change: 0 additions & 1 deletion test/Translator/Plural/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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\Plural;
Expand Down
5 changes: 0 additions & 5 deletions test/Translator/TestAsset/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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\TestAsset;
Expand All @@ -14,10 +13,6 @@

/**
* Test loader.
*
* @category Zend
* @package ZendTest_I18n
* @subpackage Translator
*/
class Loader implements FileLoaderInterface
{
Expand Down
1 change: 0 additions & 1 deletion test/Translator/TextDomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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;
Expand Down
Loading

0 comments on commit 6bd67b2

Please sign in to comment.