mirror of
https://github.com/flarum/core.git
synced 2025-07-13 12:56:26 +02:00
Performance: Cache translation catalogue to avoid reparsing YAML
This commit is contained in:
@ -46,6 +46,7 @@
|
|||||||
"nikic/fast-route": "^0.6",
|
"nikic/fast-route": "^0.6",
|
||||||
"oyejorge/less.php": "~1.5",
|
"oyejorge/less.php": "~1.5",
|
||||||
"psr/http-message": "^1.0",
|
"psr/http-message": "^1.0",
|
||||||
|
"symfony/config": "^2.7",
|
||||||
"symfony/console": "^2.7",
|
"symfony/console": "^2.7",
|
||||||
"symfony/http-foundation": "^2.7",
|
"symfony/http-foundation": "^2.7",
|
||||||
"symfony/translation": "^2.7",
|
"symfony/translation": "^2.7",
|
||||||
|
@ -14,35 +14,43 @@ namespace Flarum\Debug\Console;
|
|||||||
use Flarum\Admin\WebApp as AdminWebApp;
|
use Flarum\Admin\WebApp as AdminWebApp;
|
||||||
use Flarum\Console\Command\AbstractCommand;
|
use Flarum\Console\Command\AbstractCommand;
|
||||||
use Flarum\Forum\WebApp as ForumWebApp;
|
use Flarum\Forum\WebApp as ForumWebApp;
|
||||||
|
use Flarum\Foundation\Application;
|
||||||
use Illuminate\Contracts\Cache\Store;
|
use Illuminate\Contracts\Cache\Store;
|
||||||
|
|
||||||
class CacheClearCommand extends AbstractCommand
|
class CacheClearCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Contracts\Cache\Store
|
* @var Store
|
||||||
*/
|
*/
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Forum\WebApp
|
* @var ForumWebApp
|
||||||
*/
|
*/
|
||||||
protected $forum;
|
protected $forum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Admin\WebApp
|
* @var AdminWebApp
|
||||||
*/
|
*/
|
||||||
protected $admin;
|
protected $admin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Application
|
||||||
|
*/
|
||||||
|
protected $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Store $cache
|
* @param Store $cache
|
||||||
* @param ForumWebApp $forum
|
* @param ForumWebApp $forum
|
||||||
* @param AdminWebApp $admin
|
* @param AdminWebApp $admin
|
||||||
|
* @param Application $app
|
||||||
*/
|
*/
|
||||||
public function __construct(Store $cache, ForumWebApp $forum, AdminWebApp $admin)
|
public function __construct(Store $cache, ForumWebApp $forum, AdminWebApp $admin, Application $app)
|
||||||
{
|
{
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->forum = $forum;
|
$this->forum = $forum;
|
||||||
$this->admin = $admin;
|
$this->admin = $admin;
|
||||||
|
$this->app = $app;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@ -68,5 +76,9 @@ class CacheClearCommand extends AbstractCommand
|
|||||||
$this->admin->getAssets()->flush();
|
$this->admin->getAssets()->flush();
|
||||||
|
|
||||||
$this->cache->flush();
|
$this->cache->flush();
|
||||||
|
|
||||||
|
$storagePath = $this->app->storagePath();
|
||||||
|
array_map('unlink', glob($storagePath.'/formatter/*'));
|
||||||
|
array_map('unlink', glob($storagePath.'/locale/*'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class LocaleServiceProvider extends AbstractServiceProvider
|
|||||||
$this->app->singleton('translator', function () {
|
$this->app->singleton('translator', function () {
|
||||||
$defaultLocale = $this->getDefaultLocale();
|
$defaultLocale = $this->getDefaultLocale();
|
||||||
|
|
||||||
$translator = new Translator($defaultLocale, new MessageSelector());
|
$translator = new Translator($defaultLocale, null, $this->app->storagePath().'/locale', $this->app->inDebugMode());
|
||||||
$translator->setFallbackLocales([$defaultLocale, 'en']);
|
$translator->setFallbackLocales([$defaultLocale, 'en']);
|
||||||
$translator->addLoader('prefixed_yaml', new PrefixedYamlFileLoader());
|
$translator->addLoader('prefixed_yaml', new PrefixedYamlFileLoader());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user