Skip to content
Permalink
Browse files

FormRendererExtension: compatibility with Nette 3

  • Loading branch information...
xificurk committed Nov 30, 2018
1 parent 21254bb commit 0ed16752fdbf41def58267907db0a3b624975c44
Showing with 26 additions and 9 deletions.
  1. +7 −0 phpstan.neon.dist
  2. +19 −9 src/Bridges/FormRendererDI/FormRendererExtension.php
@@ -13,3 +13,10 @@ parameters:
uncheckedExceptions:
- LogicException
- Nette\InvalidStateException

ignoreErrors:
-
message: "#Call to function method_exists\\(\\) with Nette\\\\DI\\\\ContainerBuilder and 'addFactoryDefinition' will always evaluate to true#" # BC with Nette 2.4
path: %currentWorkingDirectory%/src/Bridges/FormRendererDI/FormRendererExtension.php

reportUnmatchedIgnoredErrors: false # BC with Nette 2.4, see above
@@ -30,23 +30,33 @@ public function loadConfiguration(): void
$config = $this->validateConfig($this->defaults);
$container = $this->getContainerBuilder();
$defaultRendererFactory = $container->addDefinition($this->prefix('defaultRendererFactory'))
->setImplement(ITemplateRendererFactory::class);
if (method_exists($container, 'addFactoryDefinition')) { // Nette 3.0
$defaultRendererFactory = $container->addFactoryDefinition($this->prefix('defaultRendererFactory'));
$defaultRendererFactoryResultDefinition = $defaultRendererFactory->getResultDefinition();
$bootstrap3RendererFactory = $container->addFactoryDefinition($this->prefix('bootstrap3RendererFactory'));
$bootstrap3RendererFactoryResultDefinition = $bootstrap3RendererFactory->getResultDefinition();
} else { // Nette 2.4 BC
$defaultRendererFactory = $container->addDefinition($this->prefix('defaultRendererFactory'));
$defaultRendererFactoryResultDefinition = $defaultRendererFactory;
$bootstrap3RendererFactory = $container->addDefinition($this->prefix('bootstrap3RendererFactory'));
$bootstrap3RendererFactoryResultDefinition = $bootstrap3RendererFactory;
}
$defaultRendererFactory->setImplement(ITemplateRendererFactory::class);
foreach ($config['default']['imports'] as $templateFile) {
$defaultRendererFactory->addSetup('importTemplate', [$templateFile]);
$defaultRendererFactoryResultDefinition->addSetup('importTemplate', [$templateFile]);
}
$bootstrap3RendererFactory = $container->addDefinition($this->prefix('bootstrap3RendererFactory'))
->setImplement(IBootstrap3RendererFactory::class);
$bootstrap3RendererFactory->setImplement(IBootstrap3RendererFactory::class);
foreach ($config['bootstrap3']['imports'] as $templateFile) {
$bootstrap3RendererFactory->addSetup('importTemplate', [$templateFile]);
$bootstrap3RendererFactoryResultDefinition->addSetup('importTemplate', [$templateFile]);
}
if ($config['bootstrap3']['mode'] === Bootstrap3Renderer::MODE_HORIZONTAL) {
$bootstrap3RendererFactory->addSetup('setHorizontalMode');
$bootstrap3RendererFactoryResultDefinition->addSetup('setHorizontalMode');
} elseif ($config['bootstrap3']['mode'] === Bootstrap3Renderer::MODE_INLINE) {
$bootstrap3RendererFactory->addSetup('setInlineMode');
$bootstrap3RendererFactoryResultDefinition->addSetup('setInlineMode');
} elseif ($config['bootstrap3']['mode'] === Bootstrap3Renderer::MODE_BASIC) {
$bootstrap3RendererFactory->addSetup('setBasicMode');
$bootstrap3RendererFactoryResultDefinition->addSetup('setBasicMode');
} else {
throw new \InvalidArgumentException("Unsupported bootstrap 3 renderer mode '{$config['bootstrap3']['mode']}'.");
}

0 comments on commit 0ed1675

Please sign in to comment.
You can’t perform that action at this time.