Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9895c3d

Browse files
committed
[Translator] changed the visibility of the locale from protected to private.
1 parent a2bdc72 commit 9895c3d

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

UPGRADE-3.0.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,41 @@ UPGRADE FROM 2.x to 3.0
604604
* The `Translator::setFallbackLocale()` method has been removed in favor of
605605
`Translator::setFallbackLocales()`.
606606

607+
* The visibility of the `locale` property has been changed from protected to private. Rely on `getLocale` and `setLocale`
608+
instead.
609+
610+
Before:
611+
612+
```php
613+
class CustomTranslator extends Translator
614+
{
615+
public function fooMethod()
616+
{
617+
// get locale
618+
$locale = $this->locale;
619+
620+
// update locale
621+
$this->locale = $locale;
622+
}
623+
}
624+
```
625+
626+
After:
627+
628+
```php
629+
class CustomTranslator extends Translator
630+
{
631+
public function fooMethod()
632+
{
633+
// get locale
634+
$locale = $this->getLocale();
635+
636+
// update locale
637+
$this->setLocale($locale);
638+
}
639+
}
640+
```
641+
607642
### Twig Bridge
608643

609644
* The `twig:lint` command has been deprecated since Symfony 2.7 and will be

src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ public function testTransWithCaching()
9494
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
9595
}
9696

97+
/**
98+
* @expectedException \InvalidArgumentException
99+
*/
97100
public function testTransWithCachingWithInvalidLocale()
98101
{
99102
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
100-
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir), 'loader', '\Symfony\Bundle\FrameworkBundle\Tests\Translation\TranslatorWithInvalidLocale');
103+
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
101104
$translator->setLocale('invalid locale');
102-
103-
$this->setExpectedException('\InvalidArgumentException');
104-
$translator->trans('foo');
105105
}
106106

107107
public function testLoadResourcesWithCaching()
@@ -296,14 +296,3 @@ private function createTranslator($loader, $options, $translatorClass = '\Symfon
296296
);
297297
}
298298
}
299-
300-
class TranslatorWithInvalidLocale extends Translator
301-
{
302-
/**
303-
* {@inheritdoc}
304-
*/
305-
public function setLocale($locale)
306-
{
307-
$this->locale = $locale;
308-
}
309-
}

src/Symfony/Component/Translation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.0.0
5+
-----
6+
7+
* Changed the visibility of the locale property in `Translator` from protected to private.
8+
49
2.8.0
510
-----
611

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
3434
/**
3535
* @var string
3636
*/
37-
protected $locale;
37+
private $locale;
3838

3939
/**
4040
* @var array

0 commit comments

Comments
 (0)