From 94de7792962d795732a1bcf56bc3f7bacfc034a3 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Thu, 18 Jun 2015 12:28:38 +0000 Subject: [PATCH] [Translator] changed the visibility of the locale from protected to private. --- UPGRADE-3.0.md | 35 +++++++++++++++++++ .../Tests/Translation/TranslatorTest.php | 9 ++--- .../Component/Translation/CHANGELOG.md | 5 +++ .../Component/Translation/Translator.php | 2 +- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index c20bb51c579a6..af7663afe79cf 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -604,6 +604,41 @@ UPGRADE FROM 2.x to 3.0 * The `Translator::setFallbackLocale()` method has been removed in favor of `Translator::setFallbackLocales()`. + * The visibility of the `locale` property has been changed from protected to private. Rely on `getLocale` and `setLocale` + instead. + + Before: + + ```php + class CustomTranslator extends Translator + { + public function fooMethod() + { + // get locale + $locale = $this->locale; + + // update locale + $this->locale = $locale; + } + } + ``` + + After: + + ```php + class CustomTranslator extends Translator + { + public function fooMethod() + { + // get locale + $locale = $this->getLocale(); + + // update locale + $this->setLocale($locale); + } + } + ``` + ### Twig Bridge * The `twig:lint` command has been deprecated since Symfony 2.7 and will be diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php index c7b61cb88170e..37dc97b931673 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php @@ -94,13 +94,14 @@ public function testTransWithCaching() $this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax')); } + /** + * @expectedException \InvalidArgumentException + */ public function testTransWithCachingWithInvalidLocale() { $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir), 'loader', '\Symfony\Bundle\FrameworkBundle\Tests\Translation\TranslatorWithInvalidLocale'); - $translator->setLocale('invalid locale'); - $this->setExpectedException('\InvalidArgumentException'); $translator->trans('foo'); } @@ -302,8 +303,8 @@ class TranslatorWithInvalidLocale extends Translator /** * {@inheritdoc} */ - public function setLocale($locale) + public function getLocale() { - $this->locale = $locale; + return 'invalid locale'; } } diff --git a/src/Symfony/Component/Translation/CHANGELOG.md b/src/Symfony/Component/Translation/CHANGELOG.md index 8b2661e9ba437..52bf4606209d6 100644 --- a/src/Symfony/Component/Translation/CHANGELOG.md +++ b/src/Symfony/Component/Translation/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +3.0.0 +----- + + * Changed the visibility of the locale property in `Translator` from protected to private. + 2.8.0 ----- diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index a7594dfe20c05..e4c09f413e745 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -34,7 +34,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface /** * @var string */ - protected $locale; + private $locale; /** * @var array