This function can be registered as event handler for response/preoutput
(mandatory since ezp 5.0 LS and later, as OutputFilter has been removed).
NB: it only fires once, even if called many times

@param string $output
@param int $returnCode
420979
static public function preoutput( $output, $returnCode=null )
    {
        if ( !self::$has_run )
        {
            return self::filter( $output, $returnCode );
        }
        return $output;
    }
340624
private function handleOutput(string $output): self
    {
        $this->output .= $output;

        if (!self::inTest()) {
            echo $output;
        }

        return $this;
    }
963741
public function execute($code = null) {

		if(null !== $code && false === ('-' . intval($code) == '-' . $code)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($code)), E_USER_ERROR);
		}

		$this -> setUrl();

		if(null !== $this -> seconds) {
			return Response :: addHeader('refresh', sprintf('%d;url=%s', $this -> seconds, $this -> url), $code);
		}

		Response :: addHeader('Location', $this -> url, $code);
	}
208934
public function XmlResponse ($output = '', $terminate = TRUE) {
		if (!$this->response->HasHeader('Content-Type'))
			$this->response->SetHeader('Content-Type', 'application/xml');
		$this->response
			->SetCode(\MvcCore\IResponse::OK)
			->SetBody($output);
		if ($terminate) $this->Terminate();
	}
1173248
public function returnError(int $code)
    {
        if (isset($this->errors[$code])) {
            self::response()->setStatus($code);

            return $this->callController($this->errors[$code], []);
        } else {
            return '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . "\n" .
                '<html><head>' . "\n" .
                '<title>' . self::response()->getStatusString($code) . '</title>' . "\n" .
                '</head><body>' . "\n" .
                '<h1>' . self::response()->getStatusString($code) . '</h1>' . "\n" .
                '</body></html>';
        }
    }
549859
public function handle($input, $output = null)
	{
		try
		{
			$this->bootstrap();

			return $this->getArtisan()->run($input, $output);
		}
		catch (Exception $e)
		{
			$this->reportException($e);

			$this->renderException($output, $e);

			return 1;
		}
	}
901879
public function execute($exitCode = false): int
	{
		$migrations = $this->getOutstanding();

		if(($count = count($migrations)) > 0)
		{
			$message = $count === 1 ? 'There is %s outstanding migration:' : 'There are %s outstanding migrations:';

			$this->write(vsprintf($message, ['<yellow>' . $count . '</yellow>']) . PHP_EOL);

			$this->outputMigrationList($migrations);
		}
		else
		{
			$this->write('<green>There are no outstanding migrations.</green>');
		}

		return ($exitCode && $count > 0) ? static::STATUS_ERROR : static::STATUS_SUCCESS;
	}
1171153
public static function fire($code)
	{
		if ($code == 0) {
			return new LogicException('Error code 0 means upload was successful');
		}

		if ( ! in_array($code, array_keys(self::$messages))) {
			return new self(self::$default, self::UPPLOAD_ERR_DEFAULT);
		}

		return new self(self::$messages[$code], $code);
	}
797554
private function _processReturn() {
		// If not an empty return (no value before the semicolon)
		if (!$this->tokenizer->checkNextValidToken(T_SEMICOLON)) {
			// Remember that the current function does return something (for PHPDoc)
			$this->_functionReturns = true;
		}

		// Search for unused code after the return
		$this->_checkUnusedCode('RETURN');
	}
702215
private function connectOutputToEvents(OutputInterface $output)
    {
        $this->getHelper('phpdocumentor_logger')->connectOutputToLogging($output, $this);

        Dispatcher::getInstance()->addListener(
            Transformer::EVENT_PRE_TRANSFORM,
            function (PreTransformEvent $event) use ($output) {
                $transformations = $event->getSubject()->getTemplates()->getTransformations();
                $output->writeln(sprintf("\nApplying %d transformations", count($transformations)));
            }
        );
        Dispatcher::getInstance()->addListener(
            Transformer::EVENT_PRE_INITIALIZATION,
            function (WriterInitializationEvent $event) use ($output) {
                $output->writeln('  Initialize writer "' . get_class($event->getWriter()) . '"');
            }
        );
        Dispatcher::getInstance()->addListener(
            Transformer::EVENT_PRE_TRANSFORMATION,
            function (PreTransformationEvent $event) use ($output) {
                $output->writeln(
                    '  Execute transformation using writer "' . $event->getTransformation()->getWriter() . '"'
                );
            }
        );
    }
870043
private function assertValidReturnCode($returnCode, $fromPacket = true)
    {
        if (!in_array($returnCode, [0, 1, 2, 128])) {
            $this->throwException(
                sprintf('Malformed return code %02x.', $returnCode),
                $fromPacket
            );
        }
    }
1057988
protected function output($message, $data = [], $code = 0)
    {
        JsonOutput::output($message, $data, $code);
        $this->getApp()->end();
    }
1061407
public static function logRequest(OutputInterface $output, int $responseCode, ServerRequestInterface $request): void
    {
        $wrapOpen  = '';
        $wrapClose = '';

        if ($responseCode >= 400) {
            $wrapOpen  = '<comment>';
            $wrapClose = '</comment>';
        }

        $output->writeln(
            sprintf(
                '%s[%s] "%s %s HTTP/%s" %s%s',
                $wrapOpen,
                date("d/M/Y H:i:s"),
                $request->getMethod(),
                $request->getUri()->getPath(),
                $request->getProtocolVersion(),
                $responseCode,
                $wrapClose
            )
        );
    }
749883
private function abort_default($code) {
		extract(self::get_header_string($code));
		static::start_header($code);
		$uri = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);
		echo "<!doctype html>
<html>
	<head>
		<meta charset=utf-8>
		<meta name=viewport
			content='width=device-width, initial-scale=1.0,
				user-scalable=yes'>
		<title>$code $msg</title>
		<style>
			body {background-color: #eee; font-family: sans-serif;}
			div  {background-color: #fff; border: 1px solid #ddd;
			      padding: 25px; max-width:800px;
			      margin:20vh auto 0 auto; text-align:center;}
		</style>
	</head>
	<body>
		<div>
			<h1>$code $msg</h1>
			<p>The URL <tt>&#039;<a href='$uri'>$uri</a>&#039;</tt>
			   caused an error.</p>
		</div>
	</body>
</html>";
		static::halt();
	}
630221
private function box($method, $returnValue)
    {
        set_error_handler(__CLASS__.'::onInternalError');

        try {
            $args = func_get_args();
            unset($args[0], $args[1]);
            $this->debug('Boxing '.$method);
            $returnValue = call_user_func_array(array($this, $method), $args);
        } catch (Exception $e) {
            $this->warn(get_class($e).': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine());
            restore_error_handler();
            $this->profilerDisable();
            $this->responseLine = 'Blackfire-Error: 101 '.rawurlencode($e->getMessage().' in '.$e->getFile().':'.$e->getLine());
        }

        self::restoreErrorHandler();

        return $returnValue;
    }
15079
public function processOutput($output)
	{
		if($this->hasEventHandler('onProcessOutput'))
		{
			$event=new COutputEvent($this,$output);
			$this->onProcessOutput($event);
			if(!$event->handled)
				echo $output;
		}
		else
			echo $output;
	}
305915
private function createErrorResponse(int $code, Socket $socket): \Generator
    {
        try {
            yield from $this->log->log(
                Log::NOTICE,
                'Error reading request from %s:%d (Status Code: %d)',
                $socket->getRemoteAddress(),
                $socket->getRemotePort(),
                $code
            );

            $response = $this->handler->onError($code, $socket);

            if ($response instanceof \Generator) {
                $response = yield from $response;
            } elseif ($response instanceof Awaitable) {
                $response = yield $response;
            }

            if (!$response instanceof Response) {
                throw new InvalidResultError(sprintf(
                    'A %s object was not returned from %::onError().',
                    Response::class,
                    get_class($this->handler)
                ), $response);
            }
        } catch (Throwable $exception) {
            yield from $this->log->log(
                Log::ERROR,
                "Uncaught exception when creating response to an error from %s:%d on %s:%d in file %s on line %d: %s",
                $socket->getRemoteAddress(),
                $socket->getRemotePort(),
                $socket->getLocalAddress(),
                $socket->getLocalPort(),
                $exception->getFile(),
                $exception->getLine(),
                $exception->getMessage()
            );
            $response = yield from $this->createDefaultErrorResponse(500);
        }

        return $response;
    }