Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

RyanNerd
Copy link
Contributor

@RyanNerd RyanNerd commented May 1, 2021

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
Copy link

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 duncan3dc merged commit 643a560 into thephpleague:master Jan 22, 2022
@duncan3dc
Copy link
Member

This should be available in 3.8.0 now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow CLImate to be used in a web context
3 participants