Finalize response
if output is string then append/prepend the response

@param  mixed  $output
@return ResponseInterface

@throws RuntimeException
352491
public function finalize($output=null)
	{
	    $response = $this->getResponse();
	    if ($output instanceof ResponseInterface) {
	        $response = $output;
	    } elseif (is_string($output) && !empty($output) && $response->getBody()->isWritable()) {
	        if (Config::getCommon('response.outputBuffering') === 'prepend') {
	            // prepend output buffer content
	            $body = new Body(fopen('php://temp', 'r+'));
	            $body->write($output . $response->getBody());
	            $response = $response->withBody($body);
	        } else {
	            // append output buffer content
	            $response->getBody()->write($output);
	        }
	    }
	    
	    // stop PHP sending a Content-Type automatically
	    ini_set('default_mimetype', '');
	    
	    if ($this->isEmptyResponse($response)) {
	        return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
	    }
	    
	    if (!$response->hasHeader('Content-Type')) {
	        $response = $response->withHeader('Content-Type', 'text/html; charset=UTF-8');
	    }
	    
	    // Add Content-Length header if `addContentLengthHeader` is set
	    if (Config::getCommon('response.addContentLengthHeader')) {
	        if (ob_get_length() > 0) {
	            throw new \RuntimeException("Unexpected data in output buffer. " .
	                "Maybe you have characters before an opening <?php tag?");
	        }
	        
	        $size = $response->getBody()->getSize();
	        if ($size !== null && !$response->hasHeader('Content-Length')) {
	            $response = $response->withHeader('Content-Length', (string) $size);
	        }
	    }
	    
	    return $response;
	}
888308
public function finalize($output)
    {
        $zipFileUrl = sys_get_temp_dir() . '/' . uniqid();

        $this->fillZipWithFileContents($zipFileUrl);
        if (!$this->zip->close()) {
            throw new \RuntimeException('Failed to close zip file!');
        }

        $this->copyToOutputAndCleanup($output, $zipFileUrl);
    }
1257311
public function executeCommand(&$output)
	{
		$descriptorspec = array(
			0 => array("pipe", "r"), // stdin is a pipe that the child will read from
			1 => array("pipe", "w"), // stdout is a pipe that the child will write to
			2 => array("pipe", "w") // stderr is a pipe that the child will write to
		);

		$process = proc_open($this->cmd . ' ' . $this->getParams() . ' ' . $this->getInputSource() . ' ' . $this->getPDFPath(), $descriptorspec, $pipes);

		$output = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);

		fclose($pipes[0]);
		fclose($pipes[1]);
		fclose($pipes[2]);

		return proc_close($process);
	}
28053
public static function format($output)
	{
		$output->addString('The profile log has the following format (');
		$output->addString('* indicates visible field', array('color'=>'blue'));
		$output->addLine('):');

		$i = 0;
		foreach (static::$fields as $field => $status)
		{
			if ($i != 0)
			{
				$output->addString(' ');
			}

			$output->addString('<');

			if ($i < 10)
			{
				$output->addString($i . ':');
			}

			if ($status)
			{
				$output->addString('*' . $field, array('color'=>'blue'));
			}
			else
			{
				$output->addString($field);
			}

			$output->addString('>');
			$i++;
		}

		$output->addSpacer()->addSpacer();
	}
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;
	}
87164
private function writeToOutputNow($output)
    {
        if ($this->sendHttpCode() && \Whoops\Util\Misc::canSendHeaders()) {
            $this->system->setHttpResponseCode(
                $this->sendHttpCode()
            );
        }

        echo $output;

        return $this;
    }
1200156
protected function cleanupOutput($output)
    {
        $lines = explode("\n", $output);
        foreach ($lines as $index => $line) {
            $line = trim(preg_replace('/^[-,]+/', '', $line, 1));
            $line = preg_replace('/\s\s+/', ' ', $line);
            $lines[$index] = $line;
        }
        // Remove empty lines.
        $lines = array_filter($lines);

        return implode("\n", $lines);
    }
740715
protected function _outputHandle($output=null)
    {
        if ($output === null) {
            // do nothing
        } elseif ($output instanceof ResponseInterface) {
            $this->response = $output;
        } elseif ($output) {
            if (is_scalar($output)) {
                $this->response = $this->renderText($output);
            } elseif (is_array($output)) {
                $this->response = $this->renderJson($output);
            } elseif ($output instanceof Collection) {
                $this->response = $this->renderJson($output->all());
            }
        }
        
        if ($data = $this->getRenderBuffer()) {
            $this->response->write($data);
        }
        
        return $this->response;
    }
41618
private function makeReplace($output){
		$replaced = $output;

		foreach($this->_direct_replace as $key => $val){
			$needle = '{' . strtoupper(trim($key, '{} ')) . '}';

			$replaced = str_replace($needle, $val, $replaced);
		}

		return $replaced;
	}
1343012
protected function ensureResponse($output)
    {
        if ($output instanceof Response)
        {
            return $output;
        }
        elseif (is_string($output))
        {
            return Response::create($output, 200);
        }
        else
        {
            $message = "Action response cannot be served.";
            throw new ApplicationException($message);
        }
    }
1037563
public function terminate($output = null)
    {
        if ($output !== null) {
            echo $output;
        }
        $this->run_called = true; // prevent shutdown function from triggering.
        $this->callExit();
    }
223810
private function sanitizeOutputParameter($output = null)
    {
        if ($output instanceof LiquibaseOutputOptions) {
            return new LiquibaseDOMDocumentOuput($output);
        } else if ($output instanceof LiquibaseOutput) {
            return $output;
        }
        return new LiquibaseDOMDocumentOuput();
    }
1324168
protected function wrapWithOutsideComponents($output)
    {
        return $this->renderComponents(self::SECTION_BEFORE)
        . $output
        . $this->renderComponents(self::SECTION_AFTER);
    }
287716
public function setOutput($output)
    {
        $this->output = $output;
        
        // Storing persistent opening
        if (true === $this->persistent) {
            self::$persistentBuffer[get_class($this).$this->binary.$this->movieFile] = $output;
        }
    }
31583
private function verifyOutput($output) {
        $output = trim($output);
        $result = 'unknown';
        if (preg_match('/: ([^:]+)$/', $output, $matches) ) {
            $result = $matches[1];
        }

        $this->message = $result;

        if (array_key_exists($result, $this->messageStatus) ) {
            $this->status = $this->messageStatus[$result];
        }
        else {
            $this->status = $this->messageStatus['unknown'];
        }

        return ($this->status === 0);
    }
448754
protected function response($result)
    {
        $response = $this->container->get(Application::RESPONSE);

        if ($result instanceof ResponseInterface)
        {
            return $result;
        }

        $response->stream()->write($result);

        return $response;
    }
1218738
protected function prepareHeaders($output)
    {
        $keys = $this->exportManager->getExport($this->exportAlias)->getQueryKeys($this->exportData);
        // we want to keep the order of the first row. So we will iterate on the first row of the results
        $first_row = count($this->result) > 0 ? $this->result[0] : array();
        $header_line = array();
        
        if ($this->formatterData['numerotation'] === true) {
                $header_line[] = $this->translator->trans('Number');
        }
        
        foreach ($first_row as $key => $value) {
            $header_line[] = $this->getLabel($key, '_header');
        }
        
        if (count($header_line) > 0) {
            fputcsv($output, $header_line);
        }
    }