Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Commit

Permalink
TemplateFactoryExtension: fix compatibility with Nette 3
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Apr 8, 2019
1 parent c41201d commit c4fe994
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ parameters:
uncheckedExceptions:
- LogicException
- Nette\InvalidStateException

ignoreErrors:
-
message: '#Call to an undefined method Nette\\DI\\Definitions\\Definition::addSetup\(\)#' # it's actually ServiceDefinition, cannot use phpdoc hint because of BC with Nette 2.4
path: %currentWorkingDirectory%/src/Bridges/TemplateFactoryDI/TemplateFactoryExtension.php

reportUnmatchedIgnoredErrors: false # BC with Nette 2.4, see above
10 changes: 6 additions & 4 deletions src/Bridges/TemplateFactoryDI/TemplateFactoryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public function loadConfiguration(): void
$container = $this->getContainerBuilder();

$container->addDefinition($this->prefix('templateConfigurator'))
->setClass(TemplateFactory\TemplateConfigurator::class)
->setType(TemplateFactory\TemplateConfigurator::class)
->addSetup('setTranslator');
}

public function beforeCompile(): void
{
$container = $this->getContainerBuilder();
/** @var mixed[] $config */
$config = $this->getConfig();

$templateFactory = $container->getDefinitionByType(Nette\Application\UI\ITemplateFactory::class);
$templateFactory->addSetup(
Expand All @@ -38,15 +40,15 @@ public function beforeCompile(): void

$templateConfigurator = $container->getDefinition($this->prefix('templateConfigurator'));

foreach ($this->config['parameters'] as $name => $value) {
foreach ($config['parameters'] as $name => $value) {
$templateConfigurator->addSetup('addParameter', [$name, $value]);
}

foreach ($this->config['providers'] as $name => $value) {
foreach ($config['providers'] as $name => $value) {
$templateConfigurator->addSetup('addProvider', [$name, $value]);
}

foreach ($this->config['filters'] as $name => $filter) {
foreach ($config['filters'] as $name => $filter) {
$templateConfigurator->addSetup('addFilter', [$name, $filter]);
}
}
Expand Down

0 comments on commit c4fe994

Please sign in to comment.