Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translation][FrameworkBundle] Fix resource loading order inconsistency reported in #23034 #23057

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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clean up and simplify lazy resource initialization
  • Loading branch information
mpdude committed Jun 8, 2017
commit 31c245dfd5e16395d116c158b9502d6d16ca8e4f
33 changes: 14 additions & 19 deletions 33 src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ class Translator extends BaseTranslator implements WarmableInterface
private $resourceLocales;

/**
* Holds parameters from addResource() calls so we can add these resources
* after the ones passed in the resource_files option (which are added
* lazily in loadResources() as well).
* Holds parameters from addResource() calls so we can defer the acutal
Copy link
Member

@nicolas-grekas nicolas-grekas Jun 8, 2017

Choose a reason for hiding this comment

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

typo: actual
let's rebase on 2.7 if it applies there

* parent::addResource() calls until initialize() is executed.
*
* @var array
*/
private $otherResources = array();
private $resources = array();

/**
* Constructor.
Expand Down Expand Up @@ -74,9 +73,7 @@ public function __construct(ContainerInterface $container, MessageSelector $sele

$this->options = array_merge($this->options, $options);
$this->resourceLocales = array_keys($this->options['resource_files']);
if (null !== $this->options['cache_dir'] && $this->options['debug']) {
$this->loadResources();
}
$this->addResourceFiles($this->options['resource_files']);

parent::__construct($container->getParameter('kernel.default_locale'), $selector, $this->options['cache_dir'], $this->options['debug']);
}
Expand Down Expand Up @@ -104,7 +101,7 @@ public function warmUp($cacheDir)

public function addResource($format, $resource, $locale, $domain = null)
{
$this->otherResources[] = array($format, $resource, $locale, $domain);
$this->resources[] = array($format, $resource, $locale, $domain);
}

/**
Expand All @@ -118,29 +115,27 @@ protected function initializeCatalogue($locale)

protected function initialize()
{
$this->loadResources();
foreach ($this->resources as $key => $params) {
list($format, $resource, $locale, $domain) = $params;
parent::addResource($format, $resource, $locale, $domain);
}
$this->resources = array();

foreach ($this->loaderIds as $id => $aliases) {
foreach ($aliases as $alias) {
$this->addLoader($alias, $this->container->get($id));
}
}
}

private function loadResources()
private function addResourceFiles($filesByLocale)
{
foreach ($this->options['resource_files'] as $locale => $files) {
foreach ($filesByLocale as $locale => $files) {
foreach ($files as $key => $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', basename($file), 3);
parent::addResource($format, $file, $locale, $domain);
unset($this->options['resource_files'][$locale][$key]);
$this->addResource($format, $file, $locale, $domain);
}
}

foreach ($this->otherResources as $key => $params) {
list($format, $resource, $locale, $domain) = $params;
parent::addResource($format, $resource, $locale, $domain);
unset($this->otherResources[$key]);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.