src/Console.php
public function set($callback = null, $event = null)
    {
        if (!$callback) {
            throw new Exception('Please specify the $callback argument');
        }

        if (isset($event)) {
            $this->event = $event;
        }

        $this->sse = $this->add('jsSSE');
        $this->sse->set(function () use ($callback) {
            $this->sseInProgress = true;

            if (isset($this->app)) {
                $old_logger = $this->app->logger;
                $this->app->logger = $this;
            }

            try {
                ob_start(function ($content) {
                    if ($this->_output_bypass) {
                        return $content;
                    }

                    $output = '';
                    $this->sse->echoFunction = function ($str) use (&$output) {
                        $output .= $str;
                    };
                    $this->output($content);
                    $this->sse->echoFunction = false;

                    return $output;
                }, 2);

                call_user_func($callback, $this);
            } catch (\atk4\core\Exception $e) {
                $lines = explode("\n", $e->getHTMLText());

                foreach ($lines as $line) {
                    $this->outputHTML($line);
                }
            } catch (\Error $e) {
                $this->output('Error: '.$e->getMessage());
            } catch (\Exception $e) {
                $this->output('Exception: '.$e->getMessage());
            }

            if (isset($this->app)) {
                $this->app->logger = $old_logger;
            }

            $this->sseInProgress = false;
        });

        if ($this->event) {
            $this->js($this->event, $this->jsExecute());
        }

        return $this;
    }
public function set($callback = null, $event = null)
    {
        if (!$callback) {
            throw new Exception('Please specify the $callback argument');
        }

        if (isset($event)) {
            $this->event = $event;
        }

        $this->sse = $this->add('jsSSE');
        $this->sse->set(function () use ($callback) {
            $this->sseInProgress = true;

            if (isset($this->app)) {
                $old_logger = $this->app->logger;
                $this->app->logger = $this;
            }

            try {
                ob_start(function ($content) {
                    if ($this->_output_bypass) {
                        return $content;
                    }

                    $output = '';
                    $this->sse->echoFunction = function ($str) use (&$output) {
                        $output .= $str;
                    };
                    $this->output($content);
                    $this->sse->echoFunction = false;

                    return $output;
                }, 2);

                call_user_func($callback, $this);
            } catch (\atk4\core\Exception $e) {
                $lines = explode("\n", $e->getHTMLText());

                foreach ($lines as $line) {
                    $this->outputHTML($line);
                }
            } catch (\Error $e) {
                $this->output('Error: '.$e->getMessage());
            } catch (\Exception $e) {
                $this->output('Exception: '.$e->getMessage());
            }

            if (isset($this->app)) {
                $this->app->logger = $old_logger;
            }

            $this->sseInProgress = false;
        });

        if ($this->event) {
            $this->js($this->event, $this->jsExecute());
        }

        return $this;
    }
public function set ( $ callback = null , $ event = null ) { if ( ! $ callback ) { throw new Exception ( 'Please specify the $callback argument' ) ; } if ( isset ( $ event ) ) { $ this -> event = $ event ; } $ this -> sse = $ this -> add ( 'jsSSE' ) ; $ this -> sse -> set ( function ( ) use ( $ callback ) { $ this -> sseInProgress = true ; if ( isset ( $ this -> app ) ) { $ old_logger = $ this -> app -> logger ; $ this -> app -> logger = $ this ; } try { ob_start ( function ( $ content ) { if ( $ this -> _output_bypass ) { return $ content ; } $ output = '' ; $ this -> sse -> echoFunction = function ( $ str ) use ( & $ output ) { $ output .= $ str ; } ; $ this -> output ( $ content ) ; $ this -> sse -> echoFunction = false ; return $ output ; } , 2 ) ; call_user_func ( $ callback , $ this ) ; } catch ( \ atk4 \ core \ Exception $ e ) { $ lines = explode ( "\n" , $ e -> getHTMLText ( ) ) ; foreach ( $ lines as $ line ) { $ this -> outputHTML ( $ line ) ; } } catch ( \ Error $ e ) { $ this -> output ( 'Error: ' . $ e -> getMessage ( ) ) ; } catch ( \ Exception $ e ) { $ this -> output ( 'Exception: ' . $ e -> getMessage ( ) ) ; } if ( isset ( $ this -> app ) ) { $ this -> app -> logger = $ old_logger ; } $ this -> sseInProgress = false ; } ) ; if ( $ this -> event ) { $ this -> js ( $ this -> event , $ this -> jsExecute ( ) ) ; } return $ this ; }
Set a callback method which will be executed with the output sent back to the terminal.

Argument passed to your callback will be $this Console. You may perform calls
to methods such as

$console->output()
$console->outputHTML()

If you are using setModel, and if your model implements atk4\core\DebugTrait,
then you you will see debug information generated by $this->debug() or $this->log().

This intercepts default application logging for the duration of the process.

If you are using runCommand, then server command will be executed with it's output
(STDOUT and STDERR) redirected to the console.

While inside a callback you may execute runCommand or setModel multiple times.

@param callable    $callback callback which will be executed while displaying output inside console
@param bool|string $event    "true" would mean to execute on page load, string would indicate
js event. See first argument for View::js()

@return $this
Set a callback method which will be executed with the output sent back to the terminal .