thephpleague / climate

PHP's best friend for the terminal.
http://climate.thephpleague.com
MIT License
1.87k stars 126 forks source link

Fixed: systemHasAnsiSupport() throws an error when STDOUT is not defined #175

Closed RyanNerd closed 2 years ago

RyanNerd commented 3 years ago

Util/System/Linux::systemHasAnsiSupport() throws an error in the cases where the constant STDOUT is undefined. Fixed systemHasAnsiSupport() to return false in this instance.

Closes: #172 See: https://stackoverflow.com/questions/17769041/notice-use-of-undefined-constant-stdout-assumed-stdout/28898174

mario-deluna commented 2 years ago

Any chance this will get merged? We are running some cli commands in some cases in an HTTP context as it is super convenient.

Right now we have to make use of a separate logger to be able to forward output via HTTP, but being able to do something like this would be neat for our use case:


use \League\CLImate\CLImate;
use \League\CLImate\Util\Writer\WriterInterface;

class MyAction
{
    public function handle(Request $request) : Response
    {
        // do something with the request

        // create cli instance
        $cli = new CLImate;
        $cliLogger = new class implements WriterInterface {
            public array $log = [];
            public function write($content) {
                $this->log[] = ['message' => $content, 'time' => microtime(true)];
            }
        };

        $cli->output->add('logger', $cliLogger);
        $cli->output->defaultTo('logger');

        $registry = $this->container->get('command.registry');
        $registry->execute('myapp:something', '-f -i 50 --another-option', $cli);

        return new (Response())->json([
            'something_log' => $cliLogger->log,
        ]);
    }
}
duncan3dc commented 2 years ago

This should be available in 3.8.0 now