spiral/framework

newLine() does not exist in console app

lifewcody opened this issue · 3 comments

Description

protected function alert(string $string): void

in HelpersTrait.php calls the following:

$this->newLine();

Which calls $this->output->newLine($count);

Which returns:

[Error]
Call to undefined method Symfony\Component\Console\Output\ConsoleOutput::newLine()
in vendor/spiral/framework/src/Console/src/Traits/HelpersTrait.php:197

How To Reproduce

In the console application, set to production/prod and call $this->alert(),

Additional Info

Q A
Framework Version 3.11
PHP version 8.3.1
Operating system Linux

@lifewcody Hi, I installed a clean installation of spiral/app (in the installer I selected the console application) and added the call to the example console command:

namespace App\Endpoint\Console;

use Spiral\Console\Attribute\AsCommand;
use Spiral\Console\Command;

#[AsCommand(name: 'do-nothing', description: 'The command does nothing.')]
final class DoNothing extends Command
{
    public function perform(): int
    {
        $this->alert('test');  // <----

        return self::SUCCESS;
    }
}

And it worked correctly for me. Screenshot:

22

In the base class, in the execute method on the 87 line, the prepareOutput method is called, which for $this->output creates a SymfonyStyle object that has the desired method:
https://github.com/spiral/framework/blob/3.11.1/src/Console/src/Command.php#L87

Did you make any changes in your console command that might break this? Can you provide an example code for the console command that causes the error?

I should have been more specific; It's only when calling confirmToProceed()

But then I'm not sure why alert works but not in confirmToProceed()

if (!$confirmation->confirmToProceed()) {
            return self::FAILURE;
        }

Hi @lifewcody, thank you for the bug report! Yes, I was able to reproduce the problem. We will fix it soon.