本文整理汇总了PHP中Slim\Http\Response::getMessageForCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getMessageForCode方法的具体用法?PHP Response::getMessageForCode怎么用?PHP Response::getMessageForCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Response
的用法示例。
在下文中一共展示了Response::getMessageForCode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
//set_error_handler(array('\Slim\Slim', 'handleErrors'));
//Fetch status, header, and body
list($status, $headers, $body) = $this->response->finalize();
// Serialize cookies (with optional encryption)
\Slim\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings);
//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', Config::get('http.version'), \Slim\Http\Response::getMessageForCode($status)));
}
//Send headers
foreach ($headers as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("{$name}: {$hVal}", false);
}
}
}
//Send body, but only if it isn't a HEAD request
if (!$this->request->isHead()) {
echo $body;
}
}
示例2: renderResponse
/**
* @param int $status
* @param string $body
* @param string[] $additionalHeaders
*
* @return void
*/
private function renderResponse($status = 500, $body = '', array $additionalHeaders = [])
{
$httpVersion = '1.1';
$httpStatus = Response::getMessageForCode($status) ?: 500;
$setHeader = is_callable($this->headerSetter) ? $this->headerSetter : '\\header';
if ($this->slim) {
$response = $this->slim->response();
$response->setBody($body);
$response->setStatus($status);
foreach ($additionalHeaders as $key => $value) {
$response->headers->set($key, $value);
}
list($httpStatus, $httpHeaders, $body) = $response->finalize();
$httpVersion = $this->slim->config('http.version');
} else {
$httpHeaders = $additionalHeaders;
http_response_code($status);
}
if (headers_sent() === false) {
// Send status
$setHeader(sprintf('HTTP/%s %s', $httpVersion, $httpStatus));
// Send headers
foreach ($httpHeaders as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
$setHeader(sprintf('%s: %s', $name, $hVal), false);
}
}
}
// do not set body for HEAD requests
if ($this->slim && $this->slim->request()->isHead()) {
return;
}
echo $body;
}
示例3: handleException
public function handleException(Exception $e)
{
$status = $e->getCode();
$statusText = \Slim\Http\Response::getMessageForCode($status);
if ($statusText === null) {
$status = 500;
$statusText = 'Internal Server Error';
}
$this->response->setStatus($status);
$this->response->headers->set('Content-Type', 'application/json');
$this->response->setBody(json_encode(array('status' => $status, 'statusText' => preg_replace('/^[0-9]+ (.*)$/', '$1', $statusText), 'description' => $e->getMessage())));
}
示例4: run
/**
* Redefine the run method
*
* We no need to use a Slim handler
*/
public function run()
{
//set_error_handler(array('\Slim\Slim', 'handleErrors')); //Espo: no needs to use this handler
//Apply final outer middleware layers
if ($this->config('debug')) {
//Apply pretty exceptions only in debug to avoid accidental information leakage in production
//$this->add(new \Slim\Middleware\PrettyExceptions()); //Espo: no needs to use this handler
}
//Invoke middleware and application stack
$this->middleware[0]->call();
//Fetch status, header, and body
list($status, $headers, $body) = $this->response->finalize();
// Serialize cookies (with optional encryption)
\Slim\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings);
//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 ($headers as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("{$name}: {$hVal}", false);
}
}
}
//Send body, but only if it isn't a HEAD request
if (!$this->request->isHead()) {
echo $body;
}
//restore_error_handler(); //Espo: no needs to use this handler
}
示例5: testMessageForCodeWithInvalidCode
public function testMessageForCodeWithInvalidCode()
{
$this->assertNull(\Slim\Http\Response::getMessageForCode(600));
}
示例6: outputError
/**
* Output a generic error page
*
* @param string $status The HTTP status code (eg 401, 404, 500)
* @param string $title Optional brief title of the page, used in HTML head etc
* @param string $summary Optional summary message describing the error
* @param string $extendedTitle Optional extended title, used at top of main content
* @param string $extendedDetails Optional extended details, conveying more details
*
* @throws \InvalidArgumentException if the status is not a valid HTTP status code
*/
protected function outputError($status, $title = null, $summary = '', $extendedTitle = '', $extendedDetails = '')
{
if (!is_integer($status)) {
throw new \InvalidArgumentException('The $status parameter must be a valid integer HTTP status code');
}
$this->app->response->setStatus($status);
// slim does not set the response code in this function
// setting it manually
if (!headers_sent()) {
http_response_code($status);
// PHP 5.4+
}
if (is_null($title)) {
$title = 'Error ' . $status;
}
if ($extendedTitle === '') {
$defaultMsg = \Slim\Http\Response::getMessageForCode($status);
if ($defaultMsg !== null) {
$extendedTitle = substr($defaultMsg, 4);
} else {
$extendedTitle = $title;
}
}
// Content negotiation for the error message
// callbackCheckFormats() middleware does the content negotiation.
// But it was not executed, yet. Call it now to get the mime type.
$route = $this->app->router()->getCurrentRoute();
if ($route) {
$this->mimeBest = $this->callbackCheckFormats($route);
}
// if (!$this->store) {
// $this->store = $route->getParam('store');
// }
// display name of store in titlebar
if (isset($this->storeOptions[$this->store]['shortName'])) {
$u = $this->app->request()->getRootUri() . '/datasets/' . $this->store;
$this->app->view()->set('titleSupplementary', '<a href="' . htmlspecialchars($u, ENT_QUOTES) . '" class="navbar-brand supplementary">' . htmlspecialchars($this->storeOptions[$this->store]['shortName']) . '</a>');
}
switch ($this->mimeBest) {
case 'text/plain':
$error = "status => {$status}" . PHP_EOL;
$error .= "title => {$extendedTitle}" . PHP_EOL;
if ($summary) {
$error .= "summary => {$summary}" . PHP_EOL;
}
if ($extendedDetails) {
$error .= "details => " . preg_replace('~[\\n]+|[\\s]{2,}~', ' ', $extendedDetails);
}
// setBody does not work in this function
$this->app->response->setBody($error);
// render a blank template instead
// $this->app->render('blank.twig', [ 'content' => $error ] );
break;
case 'text/csv':
case 'text/tab-separated-values':
if ($this->mimeBest === 'text/csv') {
$delimiter = ',';
} else {
$delimiter = "\t";
}
$error = [array("status", $status), array("title", $extendedTitle)];
if ($summary) {
$error[] = array("summary", $summary);
}
if ($extendedDetails) {
$error[] = array("details", preg_replace('~[\\n]+|[\\s]{2,}~', ' ', $extendedDetails));
}
ob_start();
$out = fopen('php://output', 'w');
foreach ($error as $err) {
fputcsv($out, $err, $delimiter);
}
fclose($out);
$out = ob_get_contents();
ob_end_clean();
// setBody does not work in this function
$this->app->response->setBody($out);
// render a blank template instead
// $this->app->render('blank.twig', [ 'content' => $out ] );
break;
case 'application/rdf+xml':
case 'application/x-turtle':
case 'text/turtle':
case 'application/json':
$json_error = array('status' => $status, 'title' => $extendedTitle);
if ($summary) {
$json_error['summary'] = $summary;
}
if ($extendedDetails) {
//.........这里部分代码省略.........
示例7: 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();
}
示例8: 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 time zone for log and message queue message body
* @author Mustafa Zeynel Dağlı
*/
date_default_timezone_set($this->container['settings']['time.zone']);
/**
* if rest service entry logging conf. true, publish to message queue
* @author Mustafa Zeynel Dağlı
*/
if ($this->container['settings']['restEntry.rabbitMQ'] == true) {
$this->publishMessage();
}
set_error_handler(array('\\Slim\\Slim', 'handleErrors'));
//Apply final outer middleware layers
if ($this->config('debug')) {
//Apply pretty exceptions only in debug to avoid accidental information leakage in production
$this->add(new \Slim\Middleware\PrettyExceptions());
}
/**
* zeynel dağlı
*/
if ($this->container['settings']['log.level'] <= \Slim\Log::ERROR) {
//print_r('--slim run kontrolor--');
$this->add(new \Slim\Middleware\PrettyExceptions());
}
//Invoke middleware and application stack
$this->middleware[0]->call();
//print_r('--slim run kontrolor2--');
//Fetch status, header, and body
list($status, $headers, $body) = $this->response->finalize();
// Serialize cookies (with optional encryption)
\Slim\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings);
//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 ($headers as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("{$name}: {$hVal}", false);
}
}
}
//Send body, but only if it isn't a HEAD request
if (!$this->request->isHead()) {
echo $body;
}
$this->applyHook('slim.after');
restore_error_handler();
}
示例9: 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();
}
示例10: 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 time zone for log and message queue message body
* @author Mustafa Zeynel Dağlı
*/
date_default_timezone_set($this->container['settings']['time.zone']);
/**
* MQMAnager middle ware katmanından önce inject
* ediliyor/ test amaçlı değiştirilecek
*/
$MQManagerConfigObject = new \Utill\MQ\MQManagerConfig();
$managerConfig = new \Zend\ServiceManager\Config($MQManagerConfigObject->getConfig());
$MQManager = new \Utill\MQ\MQManager($managerConfig);
$MQManager->setService('slimApp', $this);
$this->setMQManager($MQManager);
set_error_handler(array('\\Slim\\Slim', 'handleErrors'));
/**
* MQmanager exceptions has been tested by changing error handler function
* @author Zeynel Dağlı
* @todo first tests did not work, after further tests if not work
* this code can be removed
*/
//set_error_handler(array($this, 'handleErrorsCustom'));
//Apply final outer middleware layers
if ($this->config('debug')) {
//Apply pretty exceptions only in debug to avoid accidental information leakage in production
$this->add(new \Slim\Middleware\PrettyExceptions());
}
/**
* zeynel dağlı
*/
if ($this->container['settings']['log.level'] <= \Slim\Log::ERROR) {
//print_r('--slim run kontrolor--');
$this->add(new \Slim\Middleware\PrettyExceptions());
}
//Invoke middleware and application stack
$this->middleware[0]->call();
//print_r('--slim run kontrolor2--');
/**
* if rest service entry logging conf. true, publish to message queue
* @since 07/12/2015 this functionality is being called from MQ manager
* @author Mustafa Zeynel Dağlı
*/
//if($this->container['settings']['restEntry.rabbitMQ'] == true) $this->publishMessage();
if ($this->container['settings']['restEntry.rabbitMQ'] == true) {
$this->getMQManager()->get('MQRestCallLog');
}
//Fetch status, header, and body
list($status, $headers, $body) = $this->response->finalize();
// Serialize cookies (with optional encryption)
\Slim\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings);
//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 ($headers as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("{$name}: {$hVal}", false);
}
}
}
//Send body, but only if it isn't a HEAD request
if (!$this->request->isHead()) {
echo $body;
}
$this->applyHook('slim.after');
restore_error_handler();
}
示例11: _handleException
/**
* Return HTTP status code and message to requester.
*
* @param Exception $exception Thrown exception
*
* @return mixed
*/
private function _handleException(Exception $exception)
{
$status = $exception->getCode();
$statusText = \Slim\Http\Response::getMessageForCode($status);
if ($statusText === null) {
$status = 500;
$statusText = 'Internal Server Error';
}
//Get app environment variables
$env = $this->app->environment;
$this->app->response->setStatus($status);
if (isset($env['auth.JSONerrors']) && $env['auth.JSONerrors'] == true) {
$this->app->response->headers->set('Content-Type', 'application/json');
$this->app->response->setBody(json_encode(['status' => $status < 500 ? 'fail' : 'error', 'data' => ['status' => $status, 'statusText' => preg_replace('/^[0-9]+ (.*)$/', '$1', $statusText), 'description' => $exception->getMessage()]]));
} else {
$this->app->response->setBody('<h1>' . $statusText . '</h1><h4>' . $exception->getMessage() . '</h4>');
}
$this->app->response()->finalize();
return $this->app->response();
}
示例12: run
/**
* This function is overridden to prevent slim from adding
* its own exception handler (PrettyExceptions, rockers exception handler
* is pretty enough). If updating to a newer version of slim make sure you
* take a look in case this function have changed
*/
public function run()
{
// Base path of the API requests
$basePath = trim($this->settings['application.path']);
if ($basePath != '/') {
$basePath = '/' . trim($basePath, '/') . '/';
}
// Setup dynamic routing
$this->map($basePath . ':args+', array($this, 'dispatch'))->via('GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'OPTIONS');
//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
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}", true);
}
}
}
// Send body
echo $body;
}