Skip to content

Commit 5498935

Browse files
Jakub Červenkaf3l1x
authored andcommitted
Add console Application to DI container exported types
1 parent 859f08c commit 5498935

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/DI/ConsoleExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public function loadConfiguration(): void
123123

124124
$applicationDef->addSetup('setCommandLoader', ['@' . $this->prefix('commandLoader')]);
125125
}
126+
127+
// Export types
128+
$this->compiler->addExportedType(Application::class);
126129
}
127130

128131
/**

tests/cases/DI/ConsoleExtension.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use Nette\Bridges\HttpDI\HttpExtension;
1111
use Nette\DI\Compiler;
1212
use Nette\DI\Container;
1313
use Nette\DI\ContainerLoader;
14+
use Nette\DI\Extensions\DIExtension;
1415
use Nette\DI\MissingServiceException;
1516
use Nette\DI\ServiceCreationException;
1617
use Symfony\Component\Console\Command\Command;
@@ -166,3 +167,23 @@ test(function (): void {
166167
}, [getmypid(), 7]);
167168
}, ServiceCreationException::class, 'Command "Tests\Fixtures\NoNameCommand" missing tag "console.command[name]" or variable "$defaultName".');
168169
});
170+
171+
// Always exported
172+
test(function (): void {
173+
$loader = new ContainerLoader(TEMP_DIR, true);
174+
$class = $loader->load(function (Compiler $compiler): void {
175+
$compiler->addExtension('console', new ConsoleExtension(true));
176+
$compiler->addExtension('di', new DIExtension());
177+
$compiler->loadConfig(FileMock::create('
178+
di:
179+
export:
180+
types: null
181+
', 'neon'));
182+
}, [getmypid(), 8]);
183+
184+
/** @var Container $container */
185+
$container = new $class();
186+
187+
$application = $container->getByType(Application::class);
188+
Assert::type(Application::class, $application);
189+
});

0 commit comments

Comments
 (0)