mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 11:38:44 +02:00
N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)
* Update Symfony lib to version ~6.4.0 * Update code missing return type * Add an iTop general configuration entry to store application secret (Symfony mandatory parameter) * Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
@@ -14,6 +14,8 @@ namespace Symfony\Bundle\FrameworkBundle\Console;
|
||||
use Symfony\Component\Console\Application as BaseApplication;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Command\ListCommand;
|
||||
use Symfony\Component\Console\Command\TraceableCommand;
|
||||
use Symfony\Component\Console\Debug\CliRequest;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
@@ -29,9 +31,9 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
||||
*/
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
private $kernel;
|
||||
private $commandsRegistered = false;
|
||||
private $registrationErrors = [];
|
||||
private KernelInterface $kernel;
|
||||
private bool $commandsRegistered = false;
|
||||
private array $registrationErrors = [];
|
||||
|
||||
public function __construct(KernelInterface $kernel)
|
||||
{
|
||||
@@ -42,22 +44,18 @@ class Application extends BaseApplication
|
||||
$inputDefinition = $this->getDefinition();
|
||||
$inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
|
||||
$inputDefinition->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switch off debug mode.'));
|
||||
$inputDefinition->addOption(new InputOption('--profile', null, InputOption::VALUE_NONE, 'Enables profiling (requires debug).'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Kernel associated with this Console.
|
||||
*
|
||||
* @return KernelInterface
|
||||
*/
|
||||
public function getKernel()
|
||||
public function getKernel(): KernelInterface
|
||||
{
|
||||
return $this->kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset()
|
||||
public function reset(): void
|
||||
{
|
||||
if ($this->kernel->getContainer()->has('services_resetter')) {
|
||||
$this->kernel->getContainer()->get('services_resetter')->reset();
|
||||
@@ -69,7 +67,7 @@ class Application extends BaseApplication
|
||||
*
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
public function doRun(InputInterface $input, OutputInterface $output)
|
||||
public function doRun(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->registerCommands();
|
||||
|
||||
@@ -82,23 +80,55 @@ class Application extends BaseApplication
|
||||
return parent::doRun($input, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
|
||||
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$requestStack = null;
|
||||
$renderRegistrationErrors = true;
|
||||
|
||||
if (!$command instanceof ListCommand) {
|
||||
if ($this->registrationErrors) {
|
||||
$this->renderRegistrationErrors($input, $output);
|
||||
$this->registrationErrors = [];
|
||||
$renderRegistrationErrors = false;
|
||||
}
|
||||
|
||||
return parent::doRunCommand($command, $input, $output);
|
||||
}
|
||||
|
||||
$returnCode = parent::doRunCommand($command, $input, $output);
|
||||
if ($input->hasParameterOption('--profile')) {
|
||||
$container = $this->kernel->getContainer();
|
||||
|
||||
if ($this->registrationErrors) {
|
||||
if (!$this->kernel->isDebug()) {
|
||||
if ($output instanceof ConsoleOutputInterface) {
|
||||
$output = $output->getErrorOutput();
|
||||
}
|
||||
|
||||
(new SymfonyStyle($input, $output))->warning('Debug mode should be enabled when the "--profile" option is used.');
|
||||
} elseif (!$container->has('debug.stopwatch')) {
|
||||
if ($output instanceof ConsoleOutputInterface) {
|
||||
$output = $output->getErrorOutput();
|
||||
}
|
||||
|
||||
(new SymfonyStyle($input, $output))->warning('The "--profile" option needs the Stopwatch component. Try running "composer require symfony/stopwatch".');
|
||||
} elseif (!$container->has('.virtual_request_stack')) {
|
||||
if ($output instanceof ConsoleOutputInterface) {
|
||||
$output = $output->getErrorOutput();
|
||||
}
|
||||
|
||||
(new SymfonyStyle($input, $output))->warning('The "--profile" option needs the profiler integration. Try enabling the "framework.profiler" option.');
|
||||
} else {
|
||||
$command = new TraceableCommand($command, $container->get('debug.stopwatch'));
|
||||
|
||||
$requestStack = $container->get('.virtual_request_stack');
|
||||
$requestStack->push(new CliRequest($command));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$returnCode = parent::doRunCommand($command, $input, $output);
|
||||
} finally {
|
||||
$requestStack?->pop();
|
||||
}
|
||||
|
||||
if ($renderRegistrationErrors && $this->registrationErrors) {
|
||||
$this->renderRegistrationErrors($input, $output);
|
||||
$this->registrationErrors = [];
|
||||
}
|
||||
@@ -106,57 +136,49 @@ class Application extends BaseApplication
|
||||
return $returnCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find(string $name)
|
||||
public function find(string $name): Command
|
||||
{
|
||||
$this->registerCommands();
|
||||
|
||||
return parent::find($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get(string $name)
|
||||
public function get(string $name): Command
|
||||
{
|
||||
$this->registerCommands();
|
||||
|
||||
$command = parent::get($name);
|
||||
|
||||
if ($command instanceof ContainerAwareInterface) {
|
||||
trigger_deprecation('symfony/dependency-injection', '6.4', 'Relying on "%s" to get the container in "%s" is deprecated, register the command as a service and use dependency injection instead.', ContainerAwareInterface::class, get_debug_type($command));
|
||||
$command->setContainer($this->kernel->getContainer());
|
||||
}
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all(string $namespace = null)
|
||||
public function all(string $namespace = null): array
|
||||
{
|
||||
$this->registerCommands();
|
||||
|
||||
return parent::all($namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLongVersion()
|
||||
public function getLongVersion(): string
|
||||
{
|
||||
return parent::getLongVersion().sprintf(' (env: <comment>%s</>, debug: <comment>%s</>) <bg=#0057B7;fg=#FFDD00>#StandWith</><bg=#FFDD00;fg=#0057B7>Ukraine</> <href=https://sf.to/ukraine>https://sf.to/ukraine</>', $this->kernel->getEnvironment(), $this->kernel->isDebug() ? 'true' : 'false');
|
||||
}
|
||||
|
||||
public function add(Command $command)
|
||||
public function add(Command $command): ?Command
|
||||
{
|
||||
$this->registerCommands();
|
||||
|
||||
return parent::add($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function registerCommands()
|
||||
{
|
||||
if ($this->commandsRegistered) {
|
||||
@@ -197,7 +219,7 @@ class Application extends BaseApplication
|
||||
}
|
||||
}
|
||||
|
||||
private function renderRegistrationErrors(InputInterface $input, OutputInterface $output)
|
||||
private function renderRegistrationErrors(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
if ($output instanceof ConsoleOutputInterface) {
|
||||
$output = $output->getErrorOutput();
|
||||
|
||||
Reference in New Issue
Block a user