Skip to content

Commit

Permalink
PHPStan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleš committed Mar 29, 2019
1 parent f4e4ceb commit db44b94
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/di/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,32 @@ public function beforeCompile(): void
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults, $this->config);

/** @var Nette\DI\Definitions\ServiceDefinition $translator */
$translator = $builder->getDefinition($this->prefix('translator'));
$whitelistRegexp = Translette\Translation\Helpers::whitelistRegexp($config['locales']['whitelist']);

if ($config['debug']) {
/** @var Nette\DI\Definitions\ServiceDefinition $tracyPanel */
$tracyPanel = $builder->getDefinition($this->prefix('tracyPanel'));
}

$templateFactoryName = $builder->getByType(Nette\Application\UI\ITemplateFactory::class);

if ($templateFactoryName !== null) {
$builder->getDefinition($templateFactoryName)
->addSetup('
/** @var Nette\DI\Definitions\ServiceDefinition $templateFactory */
$templateFactory = $builder->getDefinition($templateFactoryName);

$templateFactory->addSetup('
$service->onCreate[] = function (Nette\\Bridges\\ApplicationLatte\\Template $template): void {
$template->setTranslator(?);
};', [$translator]);
}

if ($builder->hasDefinition('latte.latteFactory')) {
$builder->getDefinition('latte.latteFactory')
->getResultDefinition()
/** @var Nette\DI\Definitions\FactoryDefinition $latteFactory */
$latteFactory = $builder->getDefinition('latte.latteFactory');

$latteFactory->getResultDefinition()
->addSetup('?->onCompile[] = function (Latte\\Engine $engine): void { ?::install($engine->getCompiler()); }', ['@self', new Nette\PhpGenerator\PhpLiteral(Translette\Translation\Latte\Macros::class)])
->addSetup('addProvider', ['translator', $builder->getDefinition($this->prefix('translator'))]);
}
Expand Down

0 comments on commit db44b94

Please # to comment.