Skip to content

Commit d3e208c

Browse files
committed
fixed some issues.
1 parent 87d3d0a commit d3e208c

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

src/Symfony/Component/Translation/Formatter/DefaultMessageFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DefaultMessageFormatter implements MessageFormatterInterface
2121
/**
2222
* @var MessageSelector
2323
*/
24-
protected $selector;
24+
private $selector;
2525

2626
/**
2727
* @param MessageSelector $selector Message selector to choose pluralization messages.
@@ -36,9 +36,7 @@ public function __construct(MessageSelector $selector = null)
3636
*/
3737
public function format($locale, $id, $number = null, array $arguments = array())
3838
{
39-
$pattern = ($number !== null)
40-
? $this->selector->choose($id, (int) $number, $locale)
41-
: $id;
39+
$pattern = null !== $number ? $this->selector->choose($id, (int) $number, $locale) : $id;
4240

4341
return strtr($pattern, $arguments);
4442
}

src/Symfony/Component/Translation/Formatter/IntlMessageFormatter.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,20 @@ class IntlMessageFormatter implements MessageFormatterInterface
2121
*/
2222
public function format($locale, $id, $number = null, array $arguments = array())
2323
{
24-
if ($number !== null) {
24+
if (null !== $number) {
2525
array_unshift($arguments, $number);
2626
}
2727

2828
$formatter = new \MessageFormatter($locale, $id);
2929

3030
if (null === $formatter) {
31-
throw new \InvalidArgumentException(
32-
sprintf(
33-
'Invalid message format. Reason: %s (error #%d)',
34-
intl_get_error_message(),
35-
intl_get_error_code()
36-
)
37-
);
31+
throw new \InvalidArgumentException(sprintf('Invalid message format. Reason: %s (error #%d)', intl_get_error_message(), intl_get_error_code()));
3832
}
3933

4034
$message = $formatter->format($arguments);
4135

4236
if ($formatter->getErrorCode() !== U_ZERO_ERROR) {
43-
throw new \InvalidArgumentException(
44-
sprintf(
45-
'Unable to format message. Reason: %s (error #%s)',
46-
$formatter->getErrorMessage(),
47-
$formatter->getErrorCode()
48-
)
49-
);
37+
throw new \InvalidArgumentException(sprintf('Unable to format message. Reason: %s (error #%s)', $formatter->getErrorMessage(), $formatter->getErrorCode()));
5038
}
5139

5240
return $message;

src/Symfony/Component/Translation/IdentityTranslator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function __construct($formatter = null)
3939
}
4040

4141
$this->formatter = $formatter ?: new DefaultMessageFormatter();
42+
if (!$this->formatter instanceof MessageFormatterInterface) {
43+
throw new \InvalidArgumentException(sprintf('The message formatter "%s" must implement MessageFormatterInterface.', get_class($this->formatter)));
44+
}
4245
}
4346

4447
/**

src/Symfony/Component/Translation/Tests/Formatter/IntlMessageFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function testFormat($expected, $message, $number, $arguments)
3636

3737
public function testFormatWithNamedArguments()
3838
{
39-
if (version_compare(PHP_VERSION, '5.5.0', '<') || version_compare(INTL_ICU_VERSION, '4.8', '<')) {
40-
$this->markTestSkipped('Format with named arguments can only be run with ICU 4.8 or higher');
39+
if (PHP_VERSION_ID < 50500 || version_compare(INTL_ICU_VERSION, '4.8', '<')) {
40+
$this->markTestSkipped('Format with named arguments can only be run with ICU 4.8 or higher and PHP >= 5.5');
4141
}
4242

4343
$chooseMessage = <<<_MSG_

src/Symfony/Component/Translation/Translator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ public function __construct($locale, $formatter = null, $cacheDir = null, $debug
9393
@trigger_error('Passing a MessageSelector instance into the '.__METHOD__.' as a second argument is deprecated since version 2.8 and will be removed in 3.0. Inject a MessageFormatterInterface instance instead.', E_USER_DEPRECATED);
9494
$formatter = new DefaultMessageFormatter($formatter);
9595
}
96+
9697
$this->formatter = $formatter ?: new DefaultMessageFormatter();
98+
if (!$this->formatter instanceof MessageFormatterInterface) {
99+
throw new \InvalidArgumentException(sprintf('The message formatter "%s" must implement MessageFormatterInterface.', get_class($this->formatter)));
100+
}
97101

98102
$this->cacheDir = $cacheDir;
99103
$this->debug = $debug;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy