Skip to content

[FrameworkBundle][Translation] moved cache to Translation component (new PR) #11373

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 2 commits into from
Sep 5, 2014
Merged

[FrameworkBundle][Translation] moved cache to Translation component (new PR) #11373

merged 2 commits into from
Sep 5, 2014

Conversation

OwlyCode
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #10628
License MIT
Doc PR

This supersedes the PR #11197 (while including the changes made by it). I removed the $options argument for Symfony\Component\Translation\Translator and replaced it by a public method enableCache($cacheDir, $debug = false). It aims to solve what @fabpot said about passing an array of options in #11197 while not modifying the existing constructors.

@ClementGautier
Copy link
Contributor

@OwlyCode Squash your commits please

@jderusse
Copy link
Member

Given the security issue: http://symfony.com/blog/security-releases-cve-2014-4931-symfony-2-3-18-2-4-8-and-2-5-2-released, you have to rebase this PR and re-apply modifications on Translator: 06a80fb#diff-abaa70edd88fdf9fbf5f2ab72ab89891R100

@OwlyCode
Copy link
Contributor Author

I rebased the commits on master so they benefit from the security release and are ready to be merged. All tests on Translator are green on my machine. @jeremy-derusse is it ok for you ?

@jderusse
Copy link
Member

@OwlyCode sounds good.
I think, you can also copy new tests into TranslatorCacheTest.php (06a80fb#diff-990df0e8238847f8ae54e8227f295c22R48)
to avoid regression on #11093

And fix the Coding Standard: http://fabbot.io/report/symfony/symfony/11373/4022cb2c12d8ef7a24773e09430e200459a9bdb2

* Constructor.
*
* @param string $locale The locale
* @param MessageSelector|null $selector The message selector for pluralization
* @param string $cacheDir The directory to use for the cache
Copy link
Contributor

Choose a reason for hiding this comment

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

string|null

@Tobion
Copy link
Contributor

Tobion commented Jul 17, 2014

If there is a cache within a component it should be a generic CacheInterface injected and one implementation by using the filesystem. As it has been refactored in twig.
See fabpot/Twig#1421

@fabpot
Copy link
Member

fabpot commented Jul 18, 2014

The cache only makes sense if this a PHP file that PHP itself is able to "optimize". There is indeed a PR on Twig, but I'm still not in favor of it. I can understand some usages, but people should not use it blindly.

So, we can indeed provide a cache interface, but we need to make it clear that we will only ever support the PHP implementation and document the limitation of the other possible implementations.

{
$translator = $this->getTranslator($this->getLoader());
$translator->setLocale('fr');
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR'));
Copy link
Member

Choose a reason for hiding this comment

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

Can you add tests for locales with . and @ from FrameworkBundle? https://github.com/symfony/symfony/pull/11403/files#diff-990df0e8238847f8ae54e8227f295c22R48

@fabpot
Copy link
Member

fabpot commented Sep 5, 2014

Can you rebase this PR on current master. Be careful as we made several security issue fixes.

[Translation][Cache] removed accessors for options.
@OwlyCode
Copy link
Contributor Author

OwlyCode commented Sep 5, 2014

I rebased master, the security fixes didn't conflict but the assertValidLocale call added by 9e1bc22 did. This is fixed and tested, but I left assertValidLocale as protected even if not needed anymore to avoid BC break.

@fabpot
Copy link
Member

fabpot commented Sep 5, 2014

@jeremy-derusse Can you review this one?

@@ -1,6 +1,10 @@
CHANGELOG
=========

2.6.0
-----
Copy link
Member

Choose a reason for hiding this comment

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

missing blank line below

@jderusse
Copy link
Member

jderusse commented Sep 5, 2014

Can you add (or move) new tests added on https://github.com/symfony/symfony/pull/11830/files ?

@OwlyCode
Copy link
Contributor Author

OwlyCode commented Sep 5, 2014

I fixed the issues reported by @fabpot and @jeremy-derusse on this PR.

…ator

Fixed phpdoc

Aligned variables and description

Removed enableCache and added cache setup in constructor

Added tests for locales with . and @ with caching
@fabpot
Copy link
Member

fabpot commented Sep 5, 2014

Is it mergeable now?

@stof
Copy link
Member

stof commented Sep 5, 2014

👍

@fabpot
Copy link
Member

fabpot commented Sep 5, 2014

@OwlyCode Can you fix the CS issue reported by fabbot?

@OwlyCode
Copy link
Contributor Author

OwlyCode commented Sep 5, 2014

I'm not sure on the way to solve this as the use statement causing the CS issue is inside an heredoc string (it is the content of a generated file).

@stof
Copy link
Member

stof commented Sep 5, 2014

Indeed. It looks like a false positive of the PHP-CS-Fixer here. I suspect fabbot is running the stable release for now, while the dev version should be fixed for this case

@fabpot
Copy link
Member

fabpot commented Sep 5, 2014

👍

@fabpot
Copy link
Member

fabpot commented Sep 5, 2014

Thank you @OwlyCode.

@fabpot fabpot merged commit 30fed6a into symfony:master Sep 5, 2014
fabpot added a commit that referenced this pull request Sep 5, 2014
…ion component (new PR) (aitboudad, OwlyCode)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[FrameworkBundle][Translation] moved cache to Translation component (new PR)

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10628
| License       | MIT
| Doc PR        |

This supersedes the PR #11197 (while including the changes made by it). I removed the `$options` argument for `Symfony\Component\Translation\Translator` and replaced it by a public method `enableCache($cacheDir, $debug = false)`. It aims to solve what @fabpot said about passing an array of options in #11197 <s>while not modifying the existing constructors</s>.

Commits
-------

30fed6a [Translation][Cache] Removed the options from the arguments of Translator
8b2d9a8 [FrameworkBundle][Translation] moved cache to Translation component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants