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:
Fabien Potencier 2015-06-18 17:06:02 +02:00
commit dfb4ccfeda
4 changed files with 46 additions and 5 deletions

View File

@ -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

View File

@ -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';
}
}

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
3.0.0
-----
* Changed the visibility of the locale property in `Translator` from protected to private.
2.8.0
-----

View File

@ -34,7 +34,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
/**
* @var string
*/
protected $locale;
private $locale;
/**
* @var array