feature #14693 [3.0][Translator] changed the visibility of the locale from protected to private. (aitboudad)
This PR was merged into the 3.0-dev branch.
Discussion
----------
[3.0][Translator] changed the visibility of the locale from protected to private.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | yes
| Deprecations? | yes
| Fixed tickets | ~
| Tests pass? | yes
| License | MIT
Commits
-------
94de779
[Translator] changed the visibility of the locale from protected to private.
This commit is contained in:
commit
dfb4ccfeda
@ -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
|
||||
|
@ -94,13 +94,14 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
||||
$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';
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.0.0
|
||||
-----
|
||||
|
||||
* Changed the visibility of the locale property in `Translator` from protected to private.
|
||||
|
||||
2.8.0
|
||||
-----
|
||||
|
||||
|
@ -34,7 +34,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $locale;
|
||||
private $locale;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
Reference in New Issue
Block a user