From ef3c4b7ed2332b14cf2c5941e958cd42e3d4edfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 20 May 2013 19:05:40 +0200 Subject: [PATCH 01/21] Rename Number filter to NumberParse As suggested by @denixport. --- src/Filter/{Number.php => NumberParse.php} | 2 +- test/Filter/{NumberTest.php => NumberParseTest.php} | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) rename src/Filter/{Number.php => NumberParse.php} (96%) rename test/Filter/{NumberTest.php => NumberParseTest.php} (89%) diff --git a/src/Filter/Number.php b/src/Filter/NumberParse.php similarity index 96% rename from src/Filter/Number.php rename to src/Filter/NumberParse.php index e4bdc6e9..54e16e38 100644 --- a/src/Filter/Number.php +++ b/src/Filter/NumberParse.php @@ -12,7 +12,7 @@ use Zend\I18n\Exception; use Zend\Stdlib\ErrorHandler; -class Number extends NumberFormat +class NumberParse extends NumberFormat { /** diff --git a/test/Filter/NumberTest.php b/test/Filter/NumberParseTest.php similarity index 89% rename from test/Filter/NumberTest.php rename to test/Filter/NumberParseTest.php index 232ed951..068df896 100644 --- a/test/Filter/NumberTest.php +++ b/test/Filter/NumberParseTest.php @@ -11,14 +11,14 @@ namespace ZendTest\I18n\Filter; use PHPUnit_Framework_TestCase as TestCase; -use Zend\I18n\Filter\Number as NumberFilter; +use Zend\I18n\Filter\NumberParse as NumberParseFilter; use NumberFormatter; class NumberTest extends TestCase { public function testConstructWithOptions() { - $filter = new NumberFilter(array( + $filter = new NumberParseFilter(array( 'locale' => 'en_US', 'style' => NumberFormatter::DECIMAL )); @@ -29,7 +29,7 @@ public function testConstructWithOptions() public function testConstructWithParameters() { - $filter = new NumberFilter('en_US', NumberFormatter::DECIMAL); + $filter = new NumberParseFilter('en_US', NumberFormatter::DECIMAL); $this->assertEquals('en_US', $filter->getLocale()); $this->assertEquals(NumberFormatter::DECIMAL, $filter->getStyle()); @@ -45,7 +45,7 @@ public function testConstructWithParameters() */ public function testFormattedToNumber($locale, $style, $type, $value, $expected) { - $filter = new NumberFilter($locale, $style, $type); + $filter = new NumberParseFilter($locale, $style, $type); $this->assertSame($expected, $filter->filter($value)); } From bff68299e32ef38e88c0a41cb5cd2b33f835491c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 21 May 2013 00:20:08 +0200 Subject: [PATCH 02/21] Remove package annotation As suggested by @samsonasik. --- test/Filter/NumberFormatTest.php | 1 - test/Filter/NumberParseTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/test/Filter/NumberFormatTest.php b/test/Filter/NumberFormatTest.php index cec23e7b..8df09fad 100644 --- a/test/Filter/NumberFormatTest.php +++ b/test/Filter/NumberFormatTest.php @@ -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; diff --git a/test/Filter/NumberParseTest.php b/test/Filter/NumberParseTest.php index 068df896..1cecbc7e 100644 --- a/test/Filter/NumberParseTest.php +++ b/test/Filter/NumberParseTest.php @@ -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; From 0a3141020df7fb76a1fbbac00869d9a6586f0616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Tue, 21 May 2013 14:04:45 +0200 Subject: [PATCH 03/21] Fix condition --- src/Filter/NumberParse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filter/NumberParse.php b/src/Filter/NumberParse.php index 54e16e38..cabce4f8 100644 --- a/src/Filter/NumberParse.php +++ b/src/Filter/NumberParse.php @@ -25,7 +25,7 @@ class NumberParse extends NumberFormat public function filter($value) { if (!is_int($value) - || !is_float($value)) { + && !is_float($value)) { ErrorHandler::start(); From 7edf50ccb381a0516ed1546e0b9d182fcb150865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Tue, 21 May 2013 16:33:04 +0200 Subject: [PATCH 04/21] Change order of inheritance --- src/Filter/NumberFormat.php | 138 ++++-------------------------------- src/Filter/NumberParse.php | 119 ++++++++++++++++++++++++++++++- 2 files changed, 131 insertions(+), 126 deletions(-) diff --git a/src/Filter/NumberFormat.php b/src/Filter/NumberFormat.php index 7c626790..b1091854 100644 --- a/src/Filter/NumberFormat.php +++ b/src/Filter/NumberFormat.php @@ -9,127 +9,11 @@ namespace Zend\I18n\Filter; -use NumberFormatter; -use Traversable; use Zend\I18n\Exception; use Zend\Stdlib\ErrorHandler; -class NumberFormat extends AbstractLocale +class NumberFormat extends NumberParse { - protected $options = array( - 'locale' => null, - 'style' => NumberFormatter::DEFAULT_STYLE, - 'type' => NumberFormatter::TYPE_DOUBLE - ); - - /** - * @var NumberFormatter - */ - protected $formatter = null; - - /** - * @param array|Traversable|string|null $localeOrOptions - * @param int $style - * @param int $type - */ - public function __construct( - $localeOrOptions = null, - $style = NumberFormatter::DEFAULT_STYLE, - $type = NumberFormatter::TYPE_DOUBLE) - { - parent::__construct(); - if ($localeOrOptions !== null) { - if ($localeOrOptions instanceof Traversable) { - $localeOrOptions = iterator_to_array($localeOrOptions); - } - - if (!is_array($localeOrOptions)) { - $this->setLocale($localeOrOptions); - $this->setStyle($style); - $this->setType($type); - } else { - $this->setOptions($localeOrOptions); - } - } - } - - /** - * @param string|null $locale - * @return NumberFormat - */ - public function setLocale($locale = null) - { - $this->options['locale'] = $locale; - $this->formatter = null; - return $this; - } - - /** - * @param int $style - * @return NumberFormat - */ - public function setStyle($style) - { - $this->options['style'] = (int) $style; - $this->formatter = null; - return $this; - } - - /** - * @return int - */ - public function getStyle() - { - return $this->options['style']; - } - - /** - * @param int $type - * @return NumberFormat - */ - public function setType($type) - { - $this->options['type'] = (int) $type; - return $this; - } - - /** - * @return int - */ - public function getType() - { - return $this->options['type']; - } - - /** - * @param NumberFormatter $formatter - * @return NumberFormat - */ - public function setFormatter(NumberFormatter $formatter) - { - $this->formatter = $formatter; - return $this; - } - - /** - * @return NumberFormatter - * @throws Exception\RuntimeException - */ - public function getFormatter() - { - if ($this->formatter === null) { - $formatter = NumberFormatter::create($this->getLocale(), $this->getStyle()); - if (!$formatter) { - throw new Exception\RuntimeException( - 'Can not create NumberFormatter instance; ' . intl_get_error_message() - ); - } - - $this->formatter = $formatter; - } - - return $this->formatter; - } /** * Defined by Zend\Filter\FilterInterface @@ -140,18 +24,22 @@ public function getFormatter() */ public function filter($value) { - $formatter = $this->getFormatter(); - $type = $this->getType(); + if (is_int($value) + || is_float($value)) { - if (is_int($value) || is_float($value)) { ErrorHandler::start(); - $result = $formatter->format($value, $type); + + $result = $this->getFormatter()->format( + $value, + $this->getType() + ); + ErrorHandler::stop(); + } else { - $value = str_replace(array("\xC2\xA0", ' '), '', $value); - ErrorHandler::start(); - $result = $formatter->parse($value, $type); - ErrorHandler::stop(); + + $result = parent::filter($value); + } if ($result === false) { diff --git a/src/Filter/NumberParse.php b/src/Filter/NumberParse.php index cabce4f8..7b58867e 100644 --- a/src/Filter/NumberParse.php +++ b/src/Filter/NumberParse.php @@ -9,11 +9,128 @@ namespace Zend\I18n\Filter; +use NumberFormatter; +use Traversable; use Zend\I18n\Exception; use Zend\Stdlib\ErrorHandler; -class NumberParse extends NumberFormat +class NumberParse extends AbstractLocale { + protected $options = array( + 'locale' => null, + 'style' => NumberFormatter::DEFAULT_STYLE, + 'type' => NumberFormatter::TYPE_DOUBLE + ); + + /** + * @var NumberFormatter + */ + protected $formatter = null; + + /** + * @param array|Traversable|string|null $localeOrOptions + * @param int $style + * @param int $type + */ + public function __construct( + $localeOrOptions = null, + $style = NumberFormatter::DEFAULT_STYLE, + $type = NumberFormatter::TYPE_DOUBLE) + { + parent::__construct(); + if ($localeOrOptions !== null) { + if ($localeOrOptions instanceof Traversable) { + $localeOrOptions = iterator_to_array($localeOrOptions); + } + + if (!is_array($localeOrOptions)) { + $this->setLocale($localeOrOptions); + $this->setStyle($style); + $this->setType($type); + } else { + $this->setOptions($localeOrOptions); + } + } + } + + /** + * @param string|null $locale + * @return NumberFormat + */ + public function setLocale($locale = null) + { + $this->options['locale'] = $locale; + $this->formatter = null; + return $this; + } + + /** + * @param int $style + * @return NumberFormat + */ + public function setStyle($style) + { + $this->options['style'] = (int) $style; + $this->formatter = null; + return $this; + } + + /** + * @return int + */ + public function getStyle() + { + return $this->options['style']; + } + + /** + * @param int $type + * @return NumberFormat + */ + public function setType($type) + { + $this->options['type'] = (int) $type; + return $this; + } + + /** + * @return int + */ + public function getType() + { + return $this->options['type']; + } + + /** + * @param NumberFormatter $formatter + * @return NumberFormat + */ + public function setFormatter(NumberFormatter $formatter) + { + $this->formatter = $formatter; + return $this; + } + + /** + * @return NumberFormatter + * @throws Exception\RuntimeException + */ + public function getFormatter() + { + if ($this->formatter === null) { + $formatter = NumberFormatter::create($this->getLocale(), $this->getStyle()); + if (!$formatter) { + throw new Exception\RuntimeException( + 'Can not create NumberFormatter instance; ' . intl_get_error_message() + ); + } + + $this->formatter = $formatter; + } + + return $this->formatter; + } + /** * Defined by Zend\Filter\FilterInterface From 68a68aa07d7028981234942cc2da5dbaa1f4fe8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Tue, 21 May 2013 16:37:46 +0200 Subject: [PATCH 05/21] Fix CS --- src/Filter/NumberFormat.php | 18 +++++++++--------- src/Filter/NumberParse.php | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Filter/NumberFormat.php b/src/Filter/NumberFormat.php index b1091854..59217fd9 100644 --- a/src/Filter/NumberFormat.php +++ b/src/Filter/NumberFormat.php @@ -24,8 +24,12 @@ class NumberFormat extends NumberParse */ public function filter($value) { - if (is_int($value) - || is_float($value)) { + if (!is_int($value) + && !is_float($value)) { + + $result = parent::filter($value); + + } else { ErrorHandler::start(); @@ -36,16 +40,12 @@ public function filter($value) ErrorHandler::stop(); - } else { - - $result = parent::filter($value); - } - if ($result === false) { - return $value; + if (false !== $result) { + return str_replace("\xC2\xA0", ' ', $result); } - return str_replace("\xC2\xA0", ' ', $result); + return $value; } } diff --git a/src/Filter/NumberParse.php b/src/Filter/NumberParse.php index 7b58867e..7e7db22a 100644 --- a/src/Filter/NumberParse.php +++ b/src/Filter/NumberParse.php @@ -159,6 +159,5 @@ public function filter($value) } return $value; - } } From a4c69b71108dac5c1f81646ebdbf07e9b95b888e Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Tue, 21 May 2013 19:17:13 +0200 Subject: [PATCH 06/21] moved include path restore to tearDown, reused stream_resolved_include_path result --- src/Translator/Loader/PhpArray.php | 6 +++--- test/Translator/Loader/PhpArrayTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Translator/Loader/PhpArray.php b/src/Translator/Loader/PhpArray.php index 9ac1f720..0ff8b41d 100644 --- a/src/Translator/Loader/PhpArray.php +++ b/src/Translator/Loader/PhpArray.php @@ -29,15 +29,15 @@ class PhpArray implements FileLoaderInterface */ public function load($locale, $filename) { - if (!stream_resolve_include_path($filename) && - (!is_file($filename) || !is_readable($filename))) { + $fromIncludePath = stream_resolve_include_path($filename); + if (!$fromIncludePath && (!is_file($filename) || !is_readable($filename))) { throw new Exception\InvalidArgumentException(sprintf( 'Could not open file %s for reading', $filename )); } - $messages = include $filename; + $messages = include ($fromIncludePath !== false) ? $fromIncludePath : $filename; if (!is_array($messages)) { throw new Exception\InvalidArgumentException(sprintf( diff --git a/test/Translator/Loader/PhpArrayTest.php b/test/Translator/Loader/PhpArrayTest.php index 7c639ddc..114d35ac 100644 --- a/test/Translator/Loader/PhpArrayTest.php +++ b/test/Translator/Loader/PhpArrayTest.php @@ -30,6 +30,9 @@ public function setUp() public function tearDown() { Locale::setDefault($this->originalLocale); + + // Restore original include path + restore_include_path(); } public function testLoaderFailsToLoadMissingFile() @@ -84,8 +87,5 @@ public function testLoaderLoadsFromIncludePath() $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); - - // Restore original include path - restore_include_path(); } } From 9182e7db43c31df7a53ee4812a9de0a128d893f3 Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Tue, 21 May 2013 22:11:22 +0200 Subject: [PATCH 07/21] backup original include path on setUp and restore on tearDown, unified loading --- src/Translator/Loader/PhpArray.php | 7 +++---- test/Translator/Loader/PhpArrayTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Translator/Loader/PhpArray.php b/src/Translator/Loader/PhpArray.php index 0ff8b41d..52b3f3ff 100644 --- a/src/Translator/Loader/PhpArray.php +++ b/src/Translator/Loader/PhpArray.php @@ -30,14 +30,13 @@ class PhpArray implements FileLoaderInterface public function load($locale, $filename) { $fromIncludePath = stream_resolve_include_path($filename); - if (!$fromIncludePath && (!is_file($filename) || !is_readable($filename))) { + if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( - 'Could not open file %s for reading', - $filename + 'Could not find or open file %s for reading', $filename )); } - $messages = include ($fromIncludePath !== false) ? $fromIncludePath : $filename; + $messages = include $fromIncludePath; if (!is_array($messages)) { throw new Exception\InvalidArgumentException(sprintf( diff --git a/test/Translator/Loader/PhpArrayTest.php b/test/Translator/Loader/PhpArrayTest.php index 114d35ac..b0033e69 100644 --- a/test/Translator/Loader/PhpArrayTest.php +++ b/test/Translator/Loader/PhpArrayTest.php @@ -18,6 +18,7 @@ class PhpArrayTest extends TestCase { protected $testFilesDir; protected $originalLocale; + protected $originalIncludePath; public function setUp() { @@ -25,20 +26,22 @@ public function setUp() Locale::setDefault('en_EN'); $this->testFilesDir = realpath(__DIR__ . '/../_files'); + + $this->originalIncludePath = get_include_path(); + set_include_path($this->testFilesDir); } public function tearDown() { Locale::setDefault($this->originalLocale); - // Restore original include path - restore_include_path(); + set_include_path($this->originalIncludePath); } public function testLoaderFailsToLoadMissingFile() { $loader = new PhpArrayLoader(); - $this->setExpectedException('Zend\I18n\Exception\InvalidArgumentException', 'Could not open file'); + $this->setExpectedException('Zend\I18n\Exception\InvalidArgumentException', 'Could not find or open file'); $loader->load('en_EN', 'missing'); } @@ -79,9 +82,6 @@ public function testLoaderLoadsPluralRules() public function testLoaderLoadsFromIncludePath() { - // Set test include path - set_include_path($this->testFilesDir); - $loader = new PhpArrayLoader(); $textDomain = $loader->load('en_EN', 'translation_en.php'); From d2897181f3b27895b90704320cb0ff448497bb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 22 May 2013 19:39:36 +0200 Subject: [PATCH 08/21] Fix name of test --- test/Filter/NumberParseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Filter/NumberParseTest.php b/test/Filter/NumberParseTest.php index 1cecbc7e..de643fae 100644 --- a/test/Filter/NumberParseTest.php +++ b/test/Filter/NumberParseTest.php @@ -13,7 +13,7 @@ use Zend\I18n\Filter\NumberParse as NumberParseFilter; use NumberFormatter; -class NumberTest extends TestCase +class NumberParseTest extends TestCase { public function testConstructWithOptions() { From 690cca872abe141f3f28fc1aacd5e206ed70b005 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 23 May 2013 11:36:25 -0500 Subject: [PATCH 09/21] [zendframework/zf2#4510] CS fixes - Move closing paren/opening brace to next line - constructor (multi-line definition) - if statement (multi-line conditional) --- src/Filter/NumberParse.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Filter/NumberParse.php b/src/Filter/NumberParse.php index 7e7db22a..d919158a 100644 --- a/src/Filter/NumberParse.php +++ b/src/Filter/NumberParse.php @@ -35,8 +35,8 @@ class NumberParse extends AbstractLocale public function __construct( $localeOrOptions = null, $style = NumberFormatter::DEFAULT_STYLE, - $type = NumberFormatter::TYPE_DOUBLE) - { + $type = NumberFormatter::TYPE_DOUBLE + ) { parent::__construct(); if ($localeOrOptions !== null) { if ($localeOrOptions instanceof Traversable) { @@ -142,8 +142,8 @@ public function getFormatter() public function filter($value) { if (!is_int($value) - && !is_float($value)) { - + && !is_float($value) + ) { ErrorHandler::start(); $result = $this->getFormatter()->parse( From 16fe38f79b32552b0fb278b80e76ade442c94166 Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Fri, 24 May 2013 09:05:49 +0200 Subject: [PATCH 10/21] added loading from include path feature to all translator loaders --- src/Translator/Loader/Gettext.php | 7 ++++--- src/Translator/Loader/Ini.php | 7 ++++--- src/Translator/Loader/PhpArray.php | 3 ++- test/Translator/Loader/GettextTest.php | 17 ++++++++++++++++- test/Translator/Loader/IniTest.php | 20 +++++++++++++++++++- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/Translator/Loader/Gettext.php b/src/Translator/Loader/Gettext.php index ca156526..91950b1b 100644 --- a/src/Translator/Loader/Gettext.php +++ b/src/Translator/Loader/Gettext.php @@ -44,9 +44,10 @@ class Gettext implements FileLoaderInterface */ public function load($locale, $filename) { - if (!is_file($filename) || !is_readable($filename)) { + $fromIncludePath = stream_resolve_include_path($filename); + if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( - 'Could not open file %s for reading', + 'Could not find or open file %s for reading', $filename )); } @@ -54,7 +55,7 @@ public function load($locale, $filename) $textDomain = new TextDomain(); ErrorHandler::start(); - $this->file = fopen($filename, 'rb'); + $this->file = fopen($fromIncludePath, 'rb'); $error = ErrorHandler::stop(); if (false === $this->file) { throw new Exception\InvalidArgumentException(sprintf( diff --git a/src/Translator/Loader/Ini.php b/src/Translator/Loader/Ini.php index 02a9ecac..037abb34 100644 --- a/src/Translator/Loader/Ini.php +++ b/src/Translator/Loader/Ini.php @@ -30,16 +30,17 @@ class Ini implements FileLoaderInterface */ public function load($locale, $filename) { - if (!is_file($filename) || !is_readable($filename)) { + $fromIncludePath = stream_resolve_include_path($filename); + if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( - 'Could not open file %s for reading', + 'Could not find or open file %s for reading', $filename )); } $messages = array(); $iniReader = new IniReader(); - $messagesNamespaced = $iniReader->fromFile($filename); + $messagesNamespaced = $iniReader->fromFile($fromIncludePath); $list = $messagesNamespaced; if (isset($messagesNamespaced['translation'])) { diff --git a/src/Translator/Loader/PhpArray.php b/src/Translator/Loader/PhpArray.php index 52b3f3ff..137f035a 100644 --- a/src/Translator/Loader/PhpArray.php +++ b/src/Translator/Loader/PhpArray.php @@ -32,7 +32,8 @@ public function load($locale, $filename) $fromIncludePath = stream_resolve_include_path($filename); if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( - 'Could not find or open file %s for reading', $filename + 'Could not find or open file %s for reading', + $filename )); } diff --git a/test/Translator/Loader/GettextTest.php b/test/Translator/Loader/GettextTest.php index d1c4c57c..5069d3b2 100644 --- a/test/Translator/Loader/GettextTest.php +++ b/test/Translator/Loader/GettextTest.php @@ -18,6 +18,7 @@ class GettextTest extends TestCase { protected $testFilesDir; protected $originalLocale; + protected $originalIncludePath; public function setUp() { @@ -25,17 +26,22 @@ public function setUp() Locale::setDefault('en_EN'); $this->testFilesDir = realpath(__DIR__ . '/../_files'); + + $this->originalIncludePath = get_include_path(); + set_include_path($this->testFilesDir); } public function tearDown() { Locale::setDefault($this->originalLocale); + + set_include_path($this->originalIncludePath); } public function testLoaderFailsToLoadMissingFile() { $loader = new GettextLoader(); - $this->setExpectedException('Zend\I18n\Exception\InvalidArgumentException', 'Could not open file'); + $this->setExpectedException('Zend\I18n\Exception\InvalidArgumentException', 'Could not find or open file'); $loader->load('en_EN', 'missing'); } @@ -80,4 +86,13 @@ public function testLoaderLoadsPluralRules() $this->assertEquals(1, $textDomain->getPluralRule()->evaluate(2)); $this->assertEquals(2, $textDomain->getPluralRule()->evaluate(10)); } + + public function testLoaderLoadsFromIncludePath() + { + $loader = new GettextLoader(); + $textDomain = $loader->load('en_EN', 'translation_en.mo'); + + $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); + $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); + } } diff --git a/test/Translator/Loader/IniTest.php b/test/Translator/Loader/IniTest.php index 3d7eee63..a88b76c4 100644 --- a/test/Translator/Loader/IniTest.php +++ b/test/Translator/Loader/IniTest.php @@ -18,16 +18,25 @@ class IniTest extends TestCase { protected $testFilesDir; protected $originalLocale; + protected $originalIncludePath; public function setUp() { $this->testFilesDir = realpath(__DIR__ . '/../_files'); + + $this->originalIncludePath = get_include_path(); + set_include_path($this->testFilesDir); + } + + public function tearDown() + { + set_include_path($this->originalIncludePath); } public function testLoaderFailsToLoadMissingFile() { $loader = new IniLoader(); - $this->setExpectedException('Zend\I18n\Exception\InvalidArgumentException', 'Could not open file'); + $this->setExpectedException('Zend\I18n\Exception\InvalidArgumentException', 'Could not find or open file'); $loader->load('en_EN', 'missing'); } @@ -91,4 +100,13 @@ public function testLoaderLoadsPluralRules() $this->assertEquals(1, $textDomain->getPluralRule()->evaluate(2)); $this->assertEquals(2, $textDomain->getPluralRule()->evaluate(10)); } + + public function testLoaderLoadsFromIncludePath() + { + $loader = new IniLoader(); + $textDomain = $loader->load('en_EN', 'translation_en.ini'); + + $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); + $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); + } } From 513999a0f0c795903dab63111a87ee5414fe129b Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Mon, 3 Jun 2013 15:32:21 +0200 Subject: [PATCH 11/21] fixed loading from phar --- src/Translator/Loader/Gettext.php | 3 ++- src/Translator/Loader/Ini.php | 3 ++- src/Translator/Loader/PhpArray.php | 3 ++- test/Translator/Loader/GettextTest.php | 11 ++++++++++- test/Translator/Loader/IniTest.php | 11 ++++++++++- test/Translator/Loader/PhpArrayTest.php | 11 ++++++++++- test/Translator/_files/phparray.phar | Bin 0 -> 7795 bytes test/Translator/_files/translations.phar | Bin 0 -> 9664 bytes 8 files changed, 36 insertions(+), 6 deletions(-) create mode 100755 test/Translator/_files/phparray.phar create mode 100644 test/Translator/_files/translations.phar diff --git a/src/Translator/Loader/Gettext.php b/src/Translator/Loader/Gettext.php index 91950b1b..87dd2593 100644 --- a/src/Translator/Loader/Gettext.php +++ b/src/Translator/Loader/Gettext.php @@ -44,7 +44,8 @@ class Gettext implements FileLoaderInterface */ public function load($locale, $filename) { - $fromIncludePath = stream_resolve_include_path($filename); + $resolvedIncludePath = stream_resolve_include_path($filename); + $fromIncludePath = ($resolvedIncludePath !== false) ? $resolvedIncludePath : $filename; if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( 'Could not find or open file %s for reading', diff --git a/src/Translator/Loader/Ini.php b/src/Translator/Loader/Ini.php index 037abb34..b81ebbf3 100644 --- a/src/Translator/Loader/Ini.php +++ b/src/Translator/Loader/Ini.php @@ -30,7 +30,8 @@ class Ini implements FileLoaderInterface */ public function load($locale, $filename) { - $fromIncludePath = stream_resolve_include_path($filename); + $resolvedIncludePath = stream_resolve_include_path($filename); + $fromIncludePath = ($resolvedIncludePath !== false) ? $resolvedIncludePath : $filename; if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( 'Could not find or open file %s for reading', diff --git a/src/Translator/Loader/PhpArray.php b/src/Translator/Loader/PhpArray.php index 137f035a..accdcb0e 100644 --- a/src/Translator/Loader/PhpArray.php +++ b/src/Translator/Loader/PhpArray.php @@ -29,7 +29,8 @@ class PhpArray implements FileLoaderInterface */ public function load($locale, $filename) { - $fromIncludePath = stream_resolve_include_path($filename); + $resolvedIncludePath = stream_resolve_include_path($filename); + $fromIncludePath = ($resolvedIncludePath !== false) ? $resolvedIncludePath : $filename; if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( 'Could not find or open file %s for reading', diff --git a/test/Translator/Loader/GettextTest.php b/test/Translator/Loader/GettextTest.php index 5069d3b2..d3c7f60f 100644 --- a/test/Translator/Loader/GettextTest.php +++ b/test/Translator/Loader/GettextTest.php @@ -28,7 +28,7 @@ public function setUp() $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); - set_include_path($this->testFilesDir); + set_include_path($this->testFilesDir.PATH_SEPARATOR.$this->testFilesDir.'/translations.phar'); } public function tearDown() @@ -95,4 +95,13 @@ public function testLoaderLoadsFromIncludePath() $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } + + public function testLoaderLoadsFromPhar() + { + $loader = new GettextLoader(); + $textDomain = $loader->load('en_EN', 'phar://'.$this->testFilesDir.'/translations.phar/translation_en.mo'); + + $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); + $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); + } } diff --git a/test/Translator/Loader/IniTest.php b/test/Translator/Loader/IniTest.php index a88b76c4..f7dad78d 100644 --- a/test/Translator/Loader/IniTest.php +++ b/test/Translator/Loader/IniTest.php @@ -25,7 +25,7 @@ public function setUp() $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); - set_include_path($this->testFilesDir); + set_include_path($this->testFilesDir.PATH_SEPARATOR.$this->testFilesDir.'/translations.phar'); } public function tearDown() @@ -109,4 +109,13 @@ public function testLoaderLoadsFromIncludePath() $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } + + public function testLoaderLoadsFromPhar() + { + $loader = new IniLoader(); + $textDomain = $loader->load('en_EN', 'phar://'.$this->testFilesDir.'/translations.phar/translation_en.ini'); + + $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); + $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); + } } diff --git a/test/Translator/Loader/PhpArrayTest.php b/test/Translator/Loader/PhpArrayTest.php index b0033e69..d248d145 100644 --- a/test/Translator/Loader/PhpArrayTest.php +++ b/test/Translator/Loader/PhpArrayTest.php @@ -28,7 +28,7 @@ public function setUp() $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); - set_include_path($this->testFilesDir); + set_include_path($this->testFilesDir.PATH_SEPARATOR.$this->testFilesDir.'/translations.phar'); } public function tearDown() @@ -88,4 +88,13 @@ public function testLoaderLoadsFromIncludePath() $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } + + public function testLoaderLoadsFromPhar() + { + $loader = new PhpArrayLoader(); + $textDomain = $loader->load('en_EN', 'phar://'.$this->testFilesDir.'/translations.phar/translation_en.php'); + + $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); + $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); + } } diff --git a/test/Translator/_files/phparray.phar b/test/Translator/_files/phparray.phar new file mode 100755 index 0000000000000000000000000000000000000000..e4036a0342b0acbb269cf597b636ffdd7937398a GIT binary patch literal 7795 zcmb_h&2t+`6%TMiRUF{Jx#OD6jAF|p$xgD^mSe|p64%;^*4BE9m@tfHTGFiNiBf&@yHrw_drrEO}~EM{rbJv-CIx7N!n-_ zmwd>2%q%iD&O^5dlGrJDUf4nG^Q%?hn4678Fk)5^J8qV_*Or-1+{|2Id6989a>l%H zE;Bbxd6rwvCVTLJd7+!<4!;WWBDc)GL~mp6^9BtzHiEd|na9)OMG*2A)7S&$W+Mlu zAojwk&z;mQCQ{OdZJTVBInIlN!+poWXMcC_$~oEZ?;h_C-W&r!D$Ecz!A(kndGuk$ z(=c3NWG$u?E)$l_^EZXS{V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pE>V(k~oGuPhwv&C8 zQ3T*1an)+n>dR8pHV(Uk5O<9pu0!8Ey2W+_r;>?%etw<_O!AVj4i1{JM76M)bQxk* z;Zy^DZgmrvJ>ci;_R$@-Cus#AIwcfKU5L@yt=|X$uNr!TpzdYKDyFy@$^is0AHL+( z(f=!e(eMjPRQ)nDi&9dAtSMXrcUT3aMiEJdm~kX^1E@L4xG|2jQsg9q!8p>YKpL}K zP293+?qh3SaUh}V&%mqa@NhbfyVU9Y8m7=++iGI{NF|C(uwb}imqef7qA8HJ}>jc ziv2a7ujBb69?HvqRqs#K``_yQA~OBA@clC0ALFs`d=u?|d|__x6}(?SMkYS5s`sLL zH`RL=?|bNf8*h-#flO2#FW?Q(+?Vjs@5}Nf8+TgLwGe(O^HdZlLQ zOR({avUTRrK{Zb|M`_QxafwG`_jqiz0w;8lpPKAO*GmnVKCQb{RiQ|dQR;tOQ^6WR ze}rgiwehb=F!$TmLC9S%wT?t;*pV7EnN(rSE5!PloA4b8&OD~rl%Xs04jH7frVK|} vb1cZrfM5D#5x+6lI{f{oM=$OF Date: Mon, 3 Jun 2013 15:34:31 +0200 Subject: [PATCH 12/21] removed unnecessary test file --- test/Translator/_files/phparray.phar | Bin 7795 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 test/Translator/_files/phparray.phar diff --git a/test/Translator/_files/phparray.phar b/test/Translator/_files/phparray.phar deleted file mode 100755 index e4036a0342b0acbb269cf597b636ffdd7937398a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7795 zcmb_h&2t+`6%TMiRUF{Jx#OD6jAF|p$xgD^mSe|p64%;^*4BE9m@tfHTGFiNiBf&@yHrw_drrEO}~EM{rbJv-CIx7N!n-_ zmwd>2%q%iD&O^5dlGrJDUf4nG^Q%?hn4678Fk)5^J8qV_*Or-1+{|2Id6989a>l%H zE;Bbxd6rwvCVTLJd7+!<4!;WWBDc)GL~mp6^9BtzHiEd|na9)OMG*2A)7S&$W+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m+x_WA>w@#meqP^8= zQ@12YfYYYU(E&}jxoJ`*Wz7}wV;~8g?Kq+7LS{_78j~&Xm=K=TZ^O~6*SFS zEz Date: Mon, 3 Jun 2013 15:47:28 +0200 Subject: [PATCH 13/21] CS fixes --- test/Translator/Loader/GettextTest.php | 4 ++-- test/Translator/Loader/IniTest.php | 4 ++-- test/Translator/Loader/PhpArrayTest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Translator/Loader/GettextTest.php b/test/Translator/Loader/GettextTest.php index d3c7f60f..703f5c84 100644 --- a/test/Translator/Loader/GettextTest.php +++ b/test/Translator/Loader/GettextTest.php @@ -28,7 +28,7 @@ public function setUp() $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); - set_include_path($this->testFilesDir.PATH_SEPARATOR.$this->testFilesDir.'/translations.phar'); + set_include_path($this->testFilesDir . PATH_SEPARATOR . $this->testFilesDir . '/translations.phar'); } public function tearDown() @@ -99,7 +99,7 @@ public function testLoaderLoadsFromIncludePath() public function testLoaderLoadsFromPhar() { $loader = new GettextLoader(); - $textDomain = $loader->load('en_EN', 'phar://'.$this->testFilesDir.'/translations.phar/translation_en.mo'); + $textDomain = $loader->load('en_EN', 'phar://' . $this->testFilesDir . '/translations.phar/translation_en.mo'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); diff --git a/test/Translator/Loader/IniTest.php b/test/Translator/Loader/IniTest.php index f7dad78d..650c9555 100644 --- a/test/Translator/Loader/IniTest.php +++ b/test/Translator/Loader/IniTest.php @@ -25,7 +25,7 @@ public function setUp() $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); - set_include_path($this->testFilesDir.PATH_SEPARATOR.$this->testFilesDir.'/translations.phar'); + set_include_path($this->testFilesDir . PATH_SEPARATOR . $this->testFilesDir . '/translations.phar'); } public function tearDown() @@ -113,7 +113,7 @@ public function testLoaderLoadsFromIncludePath() public function testLoaderLoadsFromPhar() { $loader = new IniLoader(); - $textDomain = $loader->load('en_EN', 'phar://'.$this->testFilesDir.'/translations.phar/translation_en.ini'); + $textDomain = $loader->load('en_EN', 'phar://' . $this->testFilesDir . '/translations.phar/translation_en.ini'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); diff --git a/test/Translator/Loader/PhpArrayTest.php b/test/Translator/Loader/PhpArrayTest.php index d248d145..be764153 100644 --- a/test/Translator/Loader/PhpArrayTest.php +++ b/test/Translator/Loader/PhpArrayTest.php @@ -28,7 +28,7 @@ public function setUp() $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); - set_include_path($this->testFilesDir.PATH_SEPARATOR.$this->testFilesDir.'/translations.phar'); + set_include_path($this->testFilesDir . PATH_SEPARATOR . $this->testFilesDir . '/translations.phar'); } public function tearDown() @@ -92,7 +92,7 @@ public function testLoaderLoadsFromIncludePath() public function testLoaderLoadsFromPhar() { $loader = new PhpArrayLoader(); - $textDomain = $loader->load('en_EN', 'phar://'.$this->testFilesDir.'/translations.phar/translation_en.php'); + $textDomain = $loader->load('en_EN', 'phar://' . $this->testFilesDir . '/translations.phar/translation_en.php'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); From 6d0c6aea2a7117003abd0796728312c80fa69f9f Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 1 Jul 2013 15:40:23 -0500 Subject: [PATCH 14/21] [zendframework/zf2#4766] Make include_path abilities opt-in in Translators - Created AbstractFileLoader, which provides implementation details for when/how to use the include_path to load translation file assets. - Updated INI, gettext, and PHP loaders to extend AbstractFileLoader. --- src/Translator/Loader/AbstractFileLoader.php | 82 ++++++++++++++++++++ src/Translator/Loader/Gettext.php | 9 +-- src/Translator/Loader/Ini.php | 2 +- src/Translator/Loader/PhpArray.php | 2 +- 4 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 src/Translator/Loader/AbstractFileLoader.php diff --git a/src/Translator/Loader/AbstractFileLoader.php b/src/Translator/Loader/AbstractFileLoader.php new file mode 100644 index 00000000..d2ec92f3 --- /dev/null +++ b/src/Translator/Loader/AbstractFileLoader.php @@ -0,0 +1,82 @@ +useIncludePath = (bool) $flag; + return $this; + } + + /** + * Are we using the include_path to resolve translation files? + * + * @return bool + */ + public function useIncludePath() + { + return $this->useIncludePath; + } + + /** + * Resolve a translation file + * + * Checks if the file exists and is readable, returning a boolean false if not; if the "useIncludePath" + * flag is enabled, it will attempt to resolve the file from the + * include_path if the file does not exist on the current working path. + * + * @param string $filename + * @return string|false + */ + protected function resolveFile($filename) + { + if (!is_file($filename) || !is_readable($filename)) { + if (!$this->useIncludePath()) { + return false; + } + return $this->resolveViaIncludePath($filename); + } + return $filename; + } + + /** + * Resolve a translation file via the include_path + * + * @param string $filename + * @return string|false + */ + protected function resolveViaIncludePath($filename) + { + $resolvedIncludePath = stream_resolve_include_path($filename); + if (!$resolvedIncludePath || !is_file($resolvedIncludePath) || !is_readable($resolvedIncludePath)) { + return false; + } + return $resolvedIncludePath; + } +} diff --git a/src/Translator/Loader/Gettext.php b/src/Translator/Loader/Gettext.php index 87dd2593..45d296db 100644 --- a/src/Translator/Loader/Gettext.php +++ b/src/Translator/Loader/Gettext.php @@ -17,7 +17,7 @@ /** * Gettext loader. */ -class Gettext implements FileLoaderInterface +class Gettext extends AbstractFileLoader { /** * Current file pointer. @@ -44,9 +44,8 @@ class Gettext implements FileLoaderInterface */ public function load($locale, $filename) { - $resolvedIncludePath = stream_resolve_include_path($filename); - $fromIncludePath = ($resolvedIncludePath !== false) ? $resolvedIncludePath : $filename; - if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { + $resolvedFile = $this->resolveFile($filename); + if (!$resolvedFile) { throw new Exception\InvalidArgumentException(sprintf( 'Could not find or open file %s for reading', $filename @@ -56,7 +55,7 @@ public function load($locale, $filename) $textDomain = new TextDomain(); ErrorHandler::start(); - $this->file = fopen($fromIncludePath, 'rb'); + $this->file = fopen($resolvedFile, 'rb'); $error = ErrorHandler::stop(); if (false === $this->file) { throw new Exception\InvalidArgumentException(sprintf( diff --git a/src/Translator/Loader/Ini.php b/src/Translator/Loader/Ini.php index b81ebbf3..93c33745 100644 --- a/src/Translator/Loader/Ini.php +++ b/src/Translator/Loader/Ini.php @@ -17,7 +17,7 @@ /** * PHP INI format loader. */ -class Ini implements FileLoaderInterface +class Ini extends AbstractFileLoader { /** * load(): defined by FileLoaderInterface. diff --git a/src/Translator/Loader/PhpArray.php b/src/Translator/Loader/PhpArray.php index accdcb0e..e00aa573 100644 --- a/src/Translator/Loader/PhpArray.php +++ b/src/Translator/Loader/PhpArray.php @@ -16,7 +16,7 @@ /** * PHP array loader. */ -class PhpArray implements FileLoaderInterface +class PhpArray extends AbstractFileLoader { /** * load(): defined by FileLoaderInterface. From 39b7edd7af9961cf2263ca04febf9f155b51f50c Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 1 Jul 2013 15:52:40 -0500 Subject: [PATCH 15/21] [zendframework/zf2#4766] Add docblock detailing how to set include_path flag - Added to translator loader plugin manager --- src/Translator/Loader/AbstractFileLoader.php | 24 +++++++------- src/Translator/LoaderPluginManager.php | 33 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/Translator/Loader/AbstractFileLoader.php b/src/Translator/Loader/AbstractFileLoader.php index d2ec92f3..19044e29 100644 --- a/src/Translator/Loader/AbstractFileLoader.php +++ b/src/Translator/Loader/AbstractFileLoader.php @@ -10,22 +10,22 @@ namespace Zend\I18n\Translator\Loader; /** - * Abstract file loader implementation; provides facilities around resolving + * Abstract file loader implementation; provides facilities around resolving * files via the include_path. */ abstract class AbstractFileLoader implements FileLoaderInterface { /** * Whether or not to consult the include_path when locating files - * + * * @var bool */ protected $useIncludePath = false; /** * Indicate whether or not to use the include_path to resolve translation files - * - * @param bool $flag + * + * @param bool $flag * @return self */ public function setUseIncludePath($flag = true) @@ -35,8 +35,8 @@ public function setUseIncludePath($flag = true) } /** - * Are we using the include_path to resolve translation files? - * + * Are we using the include_path to resolve translation files? + * * @return bool */ public function useIncludePath() @@ -47,11 +47,11 @@ public function useIncludePath() /** * Resolve a translation file * - * Checks if the file exists and is readable, returning a boolean false if not; if the "useIncludePath" - * flag is enabled, it will attempt to resolve the file from the + * Checks if the file exists and is readable, returning a boolean false if not; if the "useIncludePath" + * flag is enabled, it will attempt to resolve the file from the * include_path if the file does not exist on the current working path. - * - * @param string $filename + * + * @param string $filename * @return string|false */ protected function resolveFile($filename) @@ -67,8 +67,8 @@ protected function resolveFile($filename) /** * Resolve a translation file via the include_path - * - * @param string $filename + * + * @param string $filename * @return string|false */ protected function resolveViaIncludePath($filename) diff --git a/src/Translator/LoaderPluginManager.php b/src/Translator/LoaderPluginManager.php index a2df197b..5b911bfb 100644 --- a/src/Translator/LoaderPluginManager.php +++ b/src/Translator/LoaderPluginManager.php @@ -18,6 +18,39 @@ * Enforces that loaders retrieved are either instances of * Loader\FileLoaderInterface or Loader\RemoteLoaderInterface. Additionally, * it registers a number of default loaders. + * + * If you are wanting to use the ability to load translation files from the + * include_path, you will need to create a factory to override the defaults + * defined in this class. A simple factory might look like: + * + * + * function ($translators) { + * $adapter = new Gettext(); + * $adapter->setUseIncludePath(true); + * return $adapter; + * } + * + * + * You may need to override the Translator service factory to make this happen + * more easily. That can be done by extending it: + * + * + * use Zend\I18n\Translator\TranslatorServiceFactory; + * // or Zend\Mvc\I18n\TranslatorServiceFactory + * use Zend\ServiceManager\ServiceLocatorInterface; + * + * class MyTranslatorServiceFactory extends TranslatorServiceFactory + * { + * public function createService(ServiceLocatorInterface $services) + * { + * $translator = parent::createService($services); + * $translator->getLoaderPluginManager()->setFactory(...); + * return $translator; + * } + * } + * + * + * You would then specify your custom factory in your service configuration. */ class LoaderPluginManager extends AbstractPluginManager { From 3099ba9005380562375bd512e75b209716a4faa4 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Mon, 23 Sep 2013 12:05:51 +0200 Subject: [PATCH 16/21] Fix CS. --- test/Validator/PhoneNumberTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Validator/PhoneNumberTest.php b/test/Validator/PhoneNumberTest.php index 4df50dab..ec7adc64 100644 --- a/test/Validator/PhoneNumberTest.php +++ b/test/Validator/PhoneNumberTest.php @@ -3045,10 +3045,10 @@ public function testExampleNumbers() $this->assertTrue($this->validator->isValid($countryCodePrefixed)); // check fully qualified E.123/E.164 international variants - $fullyQualifiedDoubleO = '00'. $parameters['code'] . $value; + $fullyQualifiedDoubleO = '00' . $parameters['code'] . $value; $this->assertTrue($this->validator->isValid($fullyQualifiedDoubleO)); - $fullyQualifiedPlus = '+'. $parameters['code'] . $value; + $fullyQualifiedPlus = '+' . $parameters['code'] . $value; $this->assertTrue($this->validator->isValid($fullyQualifiedPlus)); } } From 416cf51d396e21c0b34f9b3634b3599d591b6e56 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Mon, 23 Sep 2013 12:12:04 +0200 Subject: [PATCH 17/21] Fix CS. --- src/Validator/PhoneNumber.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Validator/PhoneNumber.php b/src/Validator/PhoneNumber.php index 7b13deb2..980721ba 100644 --- a/src/Validator/PhoneNumber.php +++ b/src/Validator/PhoneNumber.php @@ -212,18 +212,17 @@ public function isValid($value = null, $context = null) $codeLength = strlen($countryPattern['code']); - // Check for existence of E.123/E.164 prefix + /* + * 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); - } - - // Check for existence of international double-O prefix - elseif (('00' . $countryPattern['code']) == substr($value, 0, $codeLength + 2)) { + } elseif (('00' . $countryPattern['code']) == substr($value, 0, $codeLength + 2)) { $valueNoCountry = substr($value, $codeLength + 2); - } - - // Check for existence of bare country prefix - elseif ($countryPattern['code'] == substr($value, 0, $codeLength)) { + } elseif ($countryPattern['code'] == substr($value, 0, $codeLength)) { $valueNoCountry = substr($value, $codeLength); } From 092e9935816ee3f4a65c14049c4157272562349c Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Mon, 23 Sep 2013 12:05:51 +0200 Subject: [PATCH 18/21] Fix CS. --- test/Validator/PhoneNumberTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Validator/PhoneNumberTest.php b/test/Validator/PhoneNumberTest.php index 3a9af33a..804035b9 100644 --- a/test/Validator/PhoneNumberTest.php +++ b/test/Validator/PhoneNumberTest.php @@ -3044,10 +3044,10 @@ public function testExampleNumbers() $this->assertTrue($this->validator->isValid($countryCodePrefixed)); // check fully qualified E.123/E.164 international variants - $fullyQualifiedDoubleO = '00'. $parameters['code'] . $value; + $fullyQualifiedDoubleO = '00' . $parameters['code'] . $value; $this->assertTrue($this->validator->isValid($fullyQualifiedDoubleO)); - $fullyQualifiedPlus = '+'. $parameters['code'] . $value; + $fullyQualifiedPlus = '+' . $parameters['code'] . $value; $this->assertTrue($this->validator->isValid($fullyQualifiedPlus)); } } From 08d26c4b85a212129fd107d628634f5950354ba2 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Mon, 23 Sep 2013 12:12:04 +0200 Subject: [PATCH 19/21] Fix CS. --- src/Validator/PhoneNumber.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Validator/PhoneNumber.php b/src/Validator/PhoneNumber.php index a358c4eb..12260edd 100644 --- a/src/Validator/PhoneNumber.php +++ b/src/Validator/PhoneNumber.php @@ -212,18 +212,17 @@ public function isValid($value = null, $context = null) $codeLength = strlen($countryPattern['code']); - // Check for existence of E.123/E.164 prefix + /* + * 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); - } - - // Check for existence of international double-O prefix - elseif (('00' . $countryPattern['code']) == substr($value, 0, $codeLength + 2)) { + } elseif (('00' . $countryPattern['code']) == substr($value, 0, $codeLength + 2)) { $valueNoCountry = substr($value, $codeLength + 2); - } - - // Check for existence of bare country prefix - elseif ($countryPattern['code'] == substr($value, 0, $codeLength)) { + } elseif ($countryPattern['code'] == substr($value, 0, $codeLength)) { $valueNoCountry = substr($value, $codeLength); } From c9ac507f0499cea161e9a874015e88f3fa5910c4 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 23 Oct 2013 14:18:16 -0500 Subject: [PATCH 20/21] [zendframework/zf2#5295] incorporate feedback - Use more reliable version comparison --- src/View/Helper/DateFormat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Helper/DateFormat.php b/src/View/Helper/DateFormat.php index 2a268127..ec4af321 100644 --- a/src/View/Helper/DateFormat.php +++ b/src/View/Helper/DateFormat.php @@ -134,7 +134,7 @@ public function setTimezone($timezone) $this->timezone = (string) $timezone; // The method setTimeZoneId is deprecated as of PHP 5.5.0 - $setTimeZoneMethodName = version_compare(PHP_VERSION, '5.5.0', '<') ? 'setTimeZoneId' : 'setTimeZone'; + $setTimeZoneMethodName = (PHP_VERSION_ID < '50500') ? 'setTimeZoneId' : 'setTimeZone'; foreach ($this->formatters as $formatter) { $formatter->$setTimeZoneMethodName($this->timezone); From 088bad2b8929c41d264007917774d9b411979f7b Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 23 Oct 2013 14:21:01 -0500 Subject: [PATCH 21/21] [zendframework/zf2#5295] consistent version checking - use PHP_VERSION_ID always - comparison should be against integers --- src/View/Helper/DateFormat.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/View/Helper/DateFormat.php b/src/View/Helper/DateFormat.php index ec4af321..c7dffb69 100644 --- a/src/View/Helper/DateFormat.php +++ b/src/View/Helper/DateFormat.php @@ -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(); } @@ -134,7 +134,7 @@ 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'; + $setTimeZoneMethodName = (PHP_VERSION_ID < 50500) ? 'setTimeZoneId' : 'setTimeZone'; foreach ($this->formatters as $formatter) { $formatter->$setTimeZoneMethodName($this->timezone);