8000 [Translator] changed the visibility of the locale from protected to p… · symfony/symfony@1eb844a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1eb844a

Browse files
committed
[Translator] changed the visibility of the locale from protected to private.
1 parent 16eeebc commit 1eb844a

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
@@ -584,6 +584,41 @@ UPGRADE FROM 2.x to 3.0
584584
* The `Translator::setFallbackLocale()` method has been removed in favor of
585585
`Translator::setFallbackLocales()`.
586586

587+
* The visibility of the `locale` property has been changed from protected to private. Rely on `getLocale` and `setLocale`
588+
instead.
589+
590+
Before:
591+
592+
```php
593+
class CustomTranslator extends Translator
594+
{
595+
public function fooMethod()
596+
{
597+
// get locale
598+
$locale = $this->locale;
599+
600+
// update locale
601+
$this->locale = $locale;
602+
}
603+
}
604+
```
605+
606+
After:
607+
608+
```php
609+
class CustomTranslator extends Translator
610+
{
611+
public function fooMethod()
612+
{
613+
// get locale
614+
$locale = $this->getLocale();
615+
616+
// update locale
617+
$this->setLocale($locale);
618+
}
619+
}
620+
```
621+
587622
### Twig Bridge
588623

589624
* The `render` tag is deprecated in favor of the `render` function.

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)
0