Merge pull request #759 from rectorphp/style-doucpled

Add SymfonyStyleFactory to remove memory-lock dependency on Application run()
This commit is contained in:
Tomáš Votruba 2018-11-03 10:58:43 +01:00 committed by GitHub
commit 01b5ebfdad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 14 deletions

View File

@ -3,8 +3,6 @@
use Psr\Container\ContainerInterface;
use Rector\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symplify\PackageBuilder\Console\ThrowableRenderer;
// Performance boost
@ -17,12 +15,8 @@ try {
/** @var ContainerInterface $container */
$container = require_once __DIR__ . '/container.php';
/** this calls @see \Symfony\Component\Console\Application::configureIO() and configure Input + Output services */
$input = $container->get(InputInterface::class);
$output = $container->get(OutputInterface::class);
$application = $container->get(Application::class);
exit($application->run($input, $output));
exit($application->run());
} catch (Throwable $throwable) {
(new ThrowableRenderer())->render($throwable);
exit($throwable->getCode());

View File

@ -0,0 +1,33 @@
<?php declare(strict_types=1);
namespace Rector\Console\Style;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\PackageBuilder\Reflection\PrivatesCaller;
final class SymfonyStyleFactory
{
/**
* @var PrivatesCaller
*/
private $privatesCaller;
public function __construct(PrivatesCaller $privatesCaller)
{
$this->privatesCaller = $privatesCaller;
}
public function create(): SymfonyStyle
{
$input = new ArgvInput();
$output = new ConsoleOutput();
// to configure all -v, -vv, -vvv options without memory-lock to Application run() arguments
$this->privatesCaller->callPrivateMethod(new Application(), 'configureIO', $input, $output);
return new SymfonyStyle($input, $output);
}
}

View File

@ -20,13 +20,8 @@ services:
Symfony\Component\Filesystem\Filesystem: ~
# Symfony\Console
Symfony\Component\Console\Style\SymfonyStyle: ~
Symfony\Component\Console\Input\ArgvInput: ~
Symfony\Component\Console\Input\InputInterface:
alias: 'Symfony\Component\Console\Input\ArgvInput'
Symfony\Component\Console\Output\ConsoleOutput: ~
Symfony\Component\Console\Output\OutputInterface:
alias: 'Symfony\Component\Console\Output\ConsoleOutput'
Symfony\Component\Console\Style\SymfonyStyle:
factory: ['@Rector\Console\Style\SymfonyStyleFactory', 'create']
Symplify\PackageBuilder\FileSystem\FileSystem: ~
Symplify\PackageBuilder\FileSystem\FinderSanitizer: ~