mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Merge pull request #759 from rectorphp/style-doucpled
Add SymfonyStyleFactory to remove memory-lock dependency on Application run()
This commit is contained in:
commit
01b5ebfdad
@ -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());
|
||||
|
33
src/Console/Style/SymfonyStyleFactory.php
Normal file
33
src/Console/Style/SymfonyStyleFactory.php
Normal 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);
|
||||
}
|
||||
}
|
@ -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: ~
|
||||
|
Loading…
x
Reference in New Issue
Block a user