Author: fabien
Date: 2010-05-19 13:47:08 +0200 (Wed, 19 May 2010)
New Revision: 29520
Modified:
branches/1.3/lib/i18n/sfI18N.class.php
branches/1.4/lib/i18n/sfI18N.class.php
Log:
[1.3, 1.4] fixed warnings issued by the invalid array_flip() usage in sfI18N
(refs #8522)
Modified: branches/1.3/lib/i18n/sfI18N.class.php
===================================================================
--- branches/1.3/lib/i18n/sfI18N.class.php 2010-05-19 11:24:13 UTC (rev
29519)
+++ branches/1.3/lib/i18n/sfI18N.class.php 2010-05-19 11:47:08 UTC (rev
29520)
@@ -328,7 +328,7 @@
*
* @return array An array with the hour and minute
*/
- public function getTimeForCulture($time, $culture)
+ public function getTimeForCulture($time, $culture = null)
{
if (!$time) return 0;
@@ -341,23 +341,29 @@
$timeRegexp = preg_replace(array('/[hm]+/i', '/a/'), array('(\d+)',
'(\w+)'), preg_quote($timeFormat));
// We parse time format to see where things are (h, m)
- $a = array(
+ $timePositions = array(
'h' => strpos($timeFormat, 'H') !== false ? strpos($timeFormat, 'H') :
strpos($timeFormat, 'h'),
'm' => strpos($timeFormat, 'm'),
'a' => strpos($timeFormat, 'a')
);
- $tmp = array_flip($a);
- ksort($tmp);
+ asort($timePositions);
$i = 0;
- $c = array();
- foreach ($tmp as $value) $c[++$i] = $value;
- $timePositions = array_flip($c);
+ // normalize positions to 0, 1, ...
+ // positions that don't exist in the pattern remain false
+ foreach ($timePositions as $key => $value)
+ {
+ if ($value !== false)
+ {
+ $timePositions[$key] = ++$i;
+ }
+ }
+
// We find all elements
if (preg_match("~$timeRegexp~", $time, $matches))
{
// repect am/pm setting if present
- if (isset($timePositions['a']))
+ if ($timePositions['a'] !== false)
{
if (strcasecmp($matches[$timePositions['a']],
$timeFormatInfo->getAMDesignator()) == 0)
{
Modified: branches/1.4/lib/i18n/sfI18N.class.php
===================================================================
--- branches/1.4/lib/i18n/sfI18N.class.php 2010-05-19 11:24:13 UTC (rev
29519)
+++ branches/1.4/lib/i18n/sfI18N.class.php 2010-05-19 11:47:08 UTC (rev
29520)
@@ -328,7 +328,7 @@
*
* @return array An array with the hour and minute
*/
- public function getTimeForCulture($time, $culture)
+ public function getTimeForCulture($time, $culture = null)
{
if (!$time) return 0;
@@ -341,23 +341,29 @@
$timeRegexp = preg_replace(array('/[hm]+/i', '/a/'), array('(\d+)',
'(\w+)'), preg_quote($timeFormat));
// We parse time format to see where things are (h, m)
- $a = array(
+ $timePositions = array(
'h' => strpos($timeFormat, 'H') !== false ? strpos($timeFormat, 'H') :
strpos($timeFormat, 'h'),
'm' => strpos($timeFormat, 'm'),
'a' => strpos($timeFormat, 'a')
);
- $tmp = array_flip($a);
- ksort($tmp);
+ asort($timePositions);
$i = 0;
- $c = array();
- foreach ($tmp as $value) $c[++$i] = $value;
- $timePositions = array_flip($c);
+ // normalize positions to 0, 1, ...
+ // positions that don't exist in the pattern remain false
+ foreach ($timePositions as $key => $value)
+ {
+ if ($value !== false)
+ {
+ $timePositions[$key] = ++$i;
+ }
+ }
+
// We find all elements
if (preg_match("~$timeRegexp~", $time, $matches))
{
// repect am/pm setting if present
- if (isset($timePositions['a']))
+ if ($timePositions['a'] !== false)
{
if (strcasecmp($matches[$timePositions['a']],
$timeFormatInfo->getAMDesignator()) == 0)
{
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.