[Translator] deprecate getMessages in favor of getCatalogue.

This commit is contained in:
Abdellatif Ait boudad 2015-05-04 14:40:06 +00:00
parent 197396089f
commit 2869a32cf1
4 changed files with 32 additions and 1 deletions

24
UPGRADE-2.8.md Normal file
View File

@ -0,0 +1,24 @@
UPGRADE FROM 2.7 to 2.8
=======================
Translator
----------
* The `getMessages()` method of the `Symfony\Component\Translation\Translator` was deprecated and will be removed in
Symfony 3.0. You should use the `getCatalogue()` method of the `Symfony\Component\Translation\TranslatorBagInterface`.
Before:
```php
$messages = $translator->getMessages();
```
After:
```php
$catalogue = $translator->getCatalogue($locale);
$messages = $catalogue->all();
while ($catalogue = $catalogue->getFallbackCatalogue()) {
$messages = array_replace_recursive($catalogue->all(), $messages);
}
```

View File

@ -1,6 +1,10 @@
CHANGELOG
=========
2.8.0
-----
* deprecated Translator::getMessages(), rely on the TranslatorBagInterface::getCatalogue() method instead.
2.7.0
-----

View File

@ -497,9 +497,10 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
}
/**
* @group legacy
* @dataProvider dataProviderGetMessages
*/
public function testGetMessages($resources, $locale, $expected)
public function testLegacyGetMessages($resources, $locale, $expected)
{
$locales = array_keys($resources);
$_locale = !is_null($locale) ? $locale : reset($locales);

View File

@ -292,6 +292,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
*/
public function getMessages($locale = null)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Rely on the TranslatorBagInterface::getCatalogue() method instead', E_USER_DEPRECATED);
$catalogues = array();
$catalogues[] = $catalogue = $this->getCatalogue($locale);
while ($catalogue = $catalogue->getFallbackCatalogue()) {