本文整理汇总了PHP中Slim\Http\Response::finalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::finalize方法的具体用法?PHP Response::finalize怎么用?PHP Response::finalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Response
的用法示例。
在下文中一共展示了Response::finalize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run
*
* This method invokes the middleware stack, including the core Slim application;
* the result is an array of HTTP status, header, and body. These three items
* are returned to the HTTP client.
*/
public function run()
{
set_error_handler(array('\\Slim\\Slim', 'handleErrors'));
//Apply final outer middleware layers
$this->add(new \Slim\Middleware\PrettyExceptions());
//Invoke middleware and application stack
$this->middleware[0]->call();
//Fetch status, header, and body
list($status, $header, $body) = $this->response->finalize();
//Send headers
if (headers_sent() === false) {
//Send status
if (strpos(PHP_SAPI, 'cgi') === 0) {
header(sprintf('Status: %s', \Slim\Http\Response::getMessageForCode($status)));
} else {
header(sprintf('HTTP/%s %s', $this->config('http.version'), \Slim\Http\Response::getMessageForCode($status)));
}
//Send headers
foreach ($header as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("{$name}: {$hVal}", false);
}
}
}
//Send body
echo $body;
restore_error_handler();
}
示例2: finalize
public function finalize()
{
if (!empty($this->parameters)) {
$body = $this->getBody();
if (!empty($body)) {
throw new \Exception("Params where added to the response, but other output was found also");
}
$this->body(json_encode($this->parameters));
$this->addHttpHeaders(array("Content-Type" => 'application/json'));
}
return parent::finalize();
}
示例3: run
/**
* Run
*
* This method invokes the middleware stack, including the core Slim application;
* the result is an array of HTTP status, header, and body. These three items
* are returned to the HTTP client.
*/
public function run()
{
set_error_handler(array('\\Slim\\Slim', 'handleErrors'));
//Apply final outer middleware layers
$this->add(new \Slim\Middleware\PrettyExceptions());
//Invoke middleware and application stack
$this->middleware[0]->call();
//Fetch status, header, and body
list($status, $header, $body) = $this->response->finalize();
//Send headers
if (headers_sent() === false) {
//Send status
if (strpos(PHP_SAPI, 'cgi') === 0) {
header(sprintf('Status: %s', \Slim\Http\Response::getMessageForCode($status)));
} else {
header(sprintf('HTTP/%s %s', $this->config('http.version'), \Slim\Http\Response::getMessageForCode($status)));
}
//Send headers
foreach ($header as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("{$name}: {$hVal}", false);
}
}
}
//Send body
echo $body;
// <statamic>
// debug panel
$end = microtime(true);
global $is_debuggable_route;
if ($is_debuggable_route && \Config::get('_display_debug_panel')) {
$html = '<style>';
$html .= '#statamic_debug {font-size:16px !important; overflow:hidden !important; line-height:1.6 !important; margin:0 !important; border-top:3px solid #222 !important; background:#f6f6f3 !important; color:#222 !important; padding:20px 16px 24px !important;} ';
$html .= '#statamic_debug .statamic_debug_wrapper {margin:0 auto !important; width:100% !important; max-width:870px !important;} ';
$html .= '#statamic_debug h2 {margin:0 !important; font-size:1.25em !important; font-weight:bold !important;} ';
$html .= '#statamic_debug p {margin:1em 0 0 !important;} ';
$html .= '#statamic_debug p:first-child {margin-top:0 !important;} ';
$html .= '#statamic_debug p.statamic_debug_note {color:#858582 !important; font-style:italic !important; border-bottom:1px solid #d4d4d1 !important; padding-bottom:0.5em !important; margin: 0.25em 0 0 !important; font-size: 0.875em;} ';
$html .= '#statamic_debug pre, #statamic_debug code {margin:0 !important; font-style:normal !important; padding:0 !important; font-size:14px !important; background:none !important; color:inherit !important; border:none !important;} ';
$html .= '#statamic_debug .statamic_debug_header {padding-top: 1em !important;} ';
$html .= '#statamic_debug .statamic_debug_details {float:left !important; overflow: hidden !important;} ';
$html .= '#statamic_debug .statamic_debug_set {width:285px !important; float:left !important; padding-top:1em !important;} ';
$html .= '#statamic_debug .statamic_debug_set em {font-style: normal !important; color: #858582 !important;} ';
$html .= '#statamic_debug .statamic_debug_set em span {color: #cfcfc9 !important;} ';
$html .= '#statamic_debug .statamic_debug_set_0 {width:245px !important; overflow:hidden !important;} ';
$html .= '#statamic_debug .statamic_debug_set_2 {width:340px !important;} ';
$html .= '</style>';
$html .= '<div id="statamic_debug"><div class="statamic_debug_wrapper">';
$html .= '<h2>Statamic Debug Panel</h2>';
$html .= '<p class="statamic_debug_note">You’re seeing this panel because <code>_display_debug_panel</code> is <code>true</code> in your site settings.</p>';
$debug_vars = \Debug::getAll();
unset($debug_vars['time_logs']);
$set_1 = $debug_vars;
unset($set_1['counts']);
unset($set_1['timeline']);
$set_1a = array('activity' => $debug_vars['time_spent']);
unset($set_1['time_spent']);
$set_2 = array('counts' => $debug_vars['counts']);
$set_3 = array_intersect_key($debug_vars, array('timeline' => '1'));
$set_3['timeline'][number_format($end - STATAMIC_START, 4) . 's'] = '<em>---------</em> end';
$dumper = new \Modifier_dump();
$dump_1 = $dumper->index($set_1);
$dump_1a = preg_replace("/([\n]?)^([^:\\s]+:)/im", "\$1\$1<strong>\$2</strong>", $dumper->index($set_1a));
$dump_1a = preg_replace("/([^\\s])\n\\s{2}(\\S)/im", "\$1\n\n \$2", $dump_1a);
$dump_2 = preg_replace("/([\n]?)^([^:\\s]+:)/im", "\$1\$1<strong>\$2</strong>", $dumper->index($set_2));
$dump_3 = $dumper->index($set_3);
$dump_3 = preg_replace("/([\n]?)^([^:\\s]+:)/im", "\$1\$1<strong>\$2</strong>", $dump_3);
// build html
$html .= '<div class="statamic_debug_header"><p>Page rendered in: <code style="font-size: 20px !important; display: inline-block; font-weight: bold !important; padding:0 10px !important; margin-left:4px !important; background: #ffc !important;">' . number_format($end - STATAMIC_START, 6) . 's</code></p></div><div class="statamic_debug_set statamic_debug_set_0"><pre><code>';
$html .= preg_replace("/([\n]?)^([^:\\s]+:)/im", "\$1\$1<strong>\$2</strong>", $dump_1);
$html .= "\n\n" . preg_replace("/([^\\s])\n\\s{2}(\\S)/im", "\$1\n\n \$2", $dump_2);
$html .= '</code></pre></div>';
$html .= '<div class="statamic_debug_details">';
$html .= '<div class="statamic_debug_set statamic_debug_set_1"><pre><code>';
$html .= preg_replace("/^\\s{4}\\d+_/m", ' ', $dump_1a);
$html .= '</code></pre></div>';
$html .= '<div class="statamic_debug_set statamic_debug_set_2"><pre><code>';
$html .= preg_replace("/^\\s{2}\\d+_/m", ' ', $dump_3);
$html .= '</code></pre></div>';
$html .= '</div></div></div>';
echo $html;
}
// </statamic>
restore_error_handler();
}