8000 [3.0][Translator] changed the visibility of the locale from protected to private. by aitboudad · Pull Request #14693 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[3.0][Translator] changed the visibility of the locale from protected to private. #14693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -302,8 +303,8 @@ class TranslatorWithInvalidLocale extends Translator
/**
* {@inheritdoc}
*/
public function setLocale($locale)
public function getLocale()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this tests? a custom translator can still return an invalid locale if it overwrites getLocale instead (or getLocale and setLocale).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

$this->locale = $locale;
return 'invalid locale';
}
}
5 changes: 5 additions & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.0.0
-----

* Changed the visibility of the locale property in `Translator` from protected to private.

2.8.0
-----

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
/**
* @var string
*/
protected $locale;
private $locale;

/**
* @var array
Expand Down
0