当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setHeader方法代码示例

本文整理汇总了PHP中Response::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setHeader方法的具体用法?PHP Response::setHeader怎么用?PHP Response::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Response的用法示例。


在下文中一共展示了Response::setHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDeleteHeader

 public function testDeleteHeader()
 {
     $this->object->setHeader('Sample', 'value');
     $this->assertThat($this->object->getHeader('sample'), $this->equalTo('value'));
     $this->object->deleteHeader('Sample');
     $this->assertThat($this->object->getHeader('sample'), $this->equalTo(null));
 }
开发者ID:juraj-blahunka,项目名称:Bachelor-Thesis,代码行数:7,代码来源:ResponseTest.php

示例2: __construct

 /**
  * @param string $message Message.
  * @param int $code Error code.
  * @param mixed $customMessages Additional information about error.
  *
  * @todo определиться с $customMessages: это mixed или array?
  */
 public function __construct($message, $code = self::ERR_CRITICAL, $customMessages = null)
 {
     $this->response = E()->getResponse();
     if (isset($customMessages)) {
         if (!is_array($customMessages)) {
             $this->customMessages = array($customMessages);
         } else {
             $this->customMessages = $customMessages;
         }
     }
     if ($code == self::ERR_LANG) {
         $this->response->setStatus(503);
         $this->response->setHeader('Retry-After', 20);
         $message = translate($message, E()->getLanguage()->getDefault());
     } elseif ($code == self::ERR_403) {
         $this->response->setStatus(403);
         $message = translate($message, E()->getLanguage()->getCurrent());
     } elseif ($code == self::ERR_404) {
         $this->response->setStatus(404);
         $message = translate($message, E()->getLanguage()->getCurrent());
     } elseif ($code != self::ERR_DB) {
         $message = translate($message, E()->getLanguage()->getCurrent());
     }
     $this->backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT, 5);
     parent::__construct($message, $code);
 }
开发者ID:energine-cmf,项目名称:energine,代码行数:33,代码来源:SystemException.php

示例3: dispatch

 public static function dispatch()
 {
     $url = new Url();
     $uri = $url->getPath();
     foreach (array_reverse(self::$routes, true) as $route => $class) {
         if (preg_match("~^{$route}\$~", $uri, $params)) {
             Router::$current = $class;
             $return = call_user_func_array(array('Controller', 'dispatch'), array_merge(array($class), array_slice($params, 1)));
             if (!(false === $return)) {
                 $vars = get_class_vars($class);
                 $type = 'text/html';
                 if (isset($vars['type'])) {
                     $type = $vars['type'];
                 }
                 # PHP >= 5.3
                 # if ( isset($class::$type) )
                 #     $type = $class::$type;
                 //Response::setHeader('Content-Type', 'application/xhtml+xml');
                 Response::setHeader('Content-Type', "{$type};charset=UTF-8");
                 Response::setBody($class, $return);
                 return;
             }
             Router::$current = null;
         }
     }
     if (Response::getHttpResponseCode() == 200) {
         $class = 'Error404';
         $return = Controller::dispatch($class);
         Response::setHeader('Content-Type', 'text/html;charset=UTF-8');
         Response::setBody($class, $return);
         //Response::setHeader('HTTP/1.0 404 Not Found');
         //Response::setHttpResponseCode(404);
         //Response::setBody('404', 'Error 404');
     }
 }
开发者ID:joksnet,项目名称:php-old,代码行数:35,代码来源:Router.php

示例4: instance

 public static function instance($className, $args = array())
 {
     global $root;
     settype($className, 'string');
     settype($args, 'array');
     $fileName = str_replace('_', DIRECTORY_SEPARATOR, $className);
     if (!is_readable("{$root}/bin/{$fileName}.php")) {
         return false;
     }
     include_once "{$root}/bin/{$fileName}.php";
     if (!class_exists($className, false)) {
         return false;
     }
     $reflection = new ReflectionClass($className);
     if ($reflection->getParentClass()->getName() != 'WebBase') {
         return false;
     }
     if (null === self::$match) {
         self::$match = $className;
     }
     $controller = call_user_func(array(&$reflection, 'newInstance'), $args);
     if ($controller->type && !empty($controller->type) && Response::canSendHeaders()) {
         Response::setHeader('Content-Type', $controller->type, true);
     }
     if (Request::isPost() && method_exists($controller, 'submit')) {
         $controller->submit();
     }
     if (Response::canSendHeaders()) {
         Response::sendResponse();
     }
     if (method_exists($controller, 'dispatch')) {
         $controller->dispatch();
     }
     return true;
 }
开发者ID:joksnet,项目名称:php-old,代码行数:35,代码来源:Web.php

示例5: getCurlResponse

 protected function getCurlResponse(Request $curl, $source)
 {
     $cresp = new Response();
     $header = substr($source, 0, $curl->getHeaderSize());
     $source = substr($source, $curl->getHeaderSize());
     $cresp->setHeader($header)->setUrl($curl->getLastUrl())->setHeaderSize($curl->getHeaderSize())->setResponse($source)->setStatusCode($curl->getStatusCode());
     return $cresp;
 }
开发者ID:oksuz,项目名称:curl,代码行数:8,代码来源:Runner.php

示例6: setFileHeaders

 /**
  * Sets response headers for a file sending
  * 
  * @param array $params
  * @return void
  */
 private function setFileHeaders($params = array())
 {
     $disposition = $params['disposition'];
     if (isset($params['filename'])) {
         $disposition .= '; filename=' . $params['filename'];
     }
     $headers = array('Content-Length' => $params['length'], 'Content-Type' => $params['type'], 'Content-Disposition' => $disposition, 'Content-Transfer-Encoding' => 'binary');
     foreach ($headers as $k => $v) {
         $this->response->setHeader($k, $v);
     }
 }
开发者ID:vincenta,项目名称:stato,代码行数:17,代码来源:Controller.php

示例7: _auth

 protected function _auth($user, $pass)
 {
     if (!Session::exists("auth")) {
         $auth = Request::auth();
         if (is_null($auth) || $auth["user"] !== $user || $auth["pass"] !== $pass) {
             Response::setHeader('WWW-Authenticate: Basic realm="' . Config::$realm . '"');
             return false;
         }
         Session::set("auth", true);
     }
     return true;
 }
开发者ID:rolandrajko,项目名称:BREAD,代码行数:12,代码来源:BaseController.php

示例8: getResponse

 public function getResponse()
 {
     $headers = array('X-Shop: ' . $this->shopId, 'X-Key: ' . $this->apiKey);
     $content = json_encode($this->data);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->apiUrl . '/' . $this->resource . $this->getQueryString());
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->type);
     if ($this->type === 'POST') {
         curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
     }
     $response = curl_exec($ch);
     $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     $header = substr($response, 0, $header_size);
     $jsonBody = substr($response, $header_size);
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $error = curl_error($ch);
     curl_close($ch);
     $response = new Response();
     if ($error) {
         $response->addError(new Error($code, $error));
         return $response;
     }
     if (!preg_match("/2../", $code)) {
         $body = json_decode($jsonBody, true);
         if (isset($body['errors'])) {
             foreach ($body['errors'] as $error) {
                 $response->addError(new Error($error['code'], $error['description']));
             }
             return $response;
         } else {
             $response->addError(new Error($code, 'Unknown error.'));
             return $response;
         }
     }
     $response->setHttpCode($code);
     $response->setHeader($header);
     $response->setJsonBody($jsonBody);
     return $response;
 }
开发者ID:bigpetecz,项目名称:ulozenka-api-v3,代码行数:44,代码来源:Request.php

示例9: set_etag_headers

 private function set_etag_headers($text)
 {
     $this->response->setHeader('ETag', md5($text));
     $this->logger->debug(sprintf('[Medick] >> ETag set to %s.', md5($text)));
     // get around PHP session
     $this->response->setHeader('Cache-Control', null, false);
     $this->response->setHeader('Expires', null, false);
     $this->response->setHeader('Pragma', null, false);
 }
开发者ID:BackupTheBerlios,项目名称:medick-svn,代码行数:9,代码来源:Base.php

示例10: wrapResponseOutput

 /**
  * The return data type.
  *
  * @param array  $data
  * @param string $format
  * @param string $ContentType
  *
  * @return string
  */
 public function wrapResponseOutput($data, $format = 'json', $ContentType = 'application')
 {
     Response::setHeader('Content-type', $ContentType . '/' . $format);
     if ($format == 'xml') {
         return Tools::xmlEncode($data);
     } else {
         return json_encode($data);
     }
 }
开发者ID:panada,项目名称:panada,代码行数:18,代码来源:Rest.php

示例11: challenge

 static function challenge()
 {
     $response = new Response('Please provide your credentials.', Response::UNAUTHORIZED);
     $response->setHeader('WWW-Authenticate', 'Basic realm="' . self::$realm . '"');
     die($response);
 }
开发者ID:runderwood,项目名称:redberry,代码行数:6,代码来源:class.doorman.php

示例12: redirect

 /**
  * Redirect to a new location
  *
  * @param string $location 
  * @param array $options 
  * @return void
  */
 public function redirect($location, $status = 302)
 {
     $this->response->setStatus($status);
     $this->response->setHeader('Location: ' . $location);
     $this->response->finish();
 }
开发者ID:niceboy120,项目名称:verbier,代码行数:13,代码来源:Application.php

示例13: __invoke

 public function __invoke(Request $request, Response $response, ...$args)
 {
     if ($request->getMethod() !== "GET") {
         $response->setStatus(HTTP_STATUS["METHOD_NOT_ALLOWED"]);
         $response->setHeader("Allow", "GET");
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
         return;
     }
     if ($request->getProtocolVersion() !== "1.1") {
         $response->setStatus(HTTP_STATUS["HTTP_VERSION_NOT_SUPPORTED"]);
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
         return;
     }
     $body = $request->getBody();
     if (!$body instanceof NullBody) {
         $response->setStatus(HTTP_STATUS["BAD_REQUEST"]);
         $response->setReason("Bad Request: Entity body disallowed for websocket endpoint");
         $response->setHeader("Connection", "close");
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
         return;
     }
     $hasUpgradeWebsocket = false;
     foreach ($request->getHeaderArray("Upgrade") as $value) {
         if (strcasecmp($value, "websocket") === 0) {
             $hasUpgradeWebsocket = true;
             break;
         }
     }
     if (empty($hasUpgradeWebsocket)) {
         $response->setStatus(HTTP_STATUS["UPGRADE_REQUIRED"]);
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
         return;
     }
     $hasConnectionUpgrade = false;
     foreach ($request->getHeaderArray("Connection") as $value) {
         $values = array_map("trim", explode(",", $value));
         foreach ($values as $token) {
             if (strcasecmp($token, "Upgrade") === 0) {
                 $hasConnectionUpgrade = true;
                 break;
             }
         }
     }
     if (empty($hasConnectionUpgrade)) {
         $response->setStatus(HTTP_STATUS["UPGRADE_REQUIRED"]);
         $response->setReason("Bad Request: \"Connection: Upgrade\" header required");
         $response->setHeader("Upgrade", "websocket");
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
         return;
     }
     if (!($acceptKey = $request->getHeader("Sec-Websocket-Key"))) {
         $response->setStatus(HTTP_STATUS["BAD_REQUEST"]);
         $response->setReason("Bad Request: \"Sec-Websocket-Key\" header required");
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
         return;
     }
     if (!in_array("13", $request->getHeaderArray("Sec-Websocket-Version"))) {
         $response->setStatus(HTTP_STATUS["BAD_REQUEST"]);
         $response->setReason("Bad Request: Requested Websocket version unavailable");
         $response->setHeader("Sec-WebSocket-Version", "13");
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
         return;
     }
     $handshaker = new Handshake($response, $acceptKey);
     $onHandshakeResult = $this->application->onHandshake($request, $handshaker, ...$args);
     if ($onHandshakeResult instanceof \Generator) {
         $onHandshakeResult = (yield from $onHandshakeResult);
     }
     $request->setLocalVar("aerys.websocket", $onHandshakeResult);
     $handshaker->end();
 }
开发者ID:staabm,项目名称:aerys,代码行数:78,代码来源:Rfc6455Endpoint.php

示例14: delete

 public function delete($params)
 {
     if (PatientRepo::delete($params['id_patient']) !== FALSE) {
         $_status = 'success';
         $_title = 'Patient supprimé!';
         $_message = 'Le patient a bien été supprimé de la base de données!';
         if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
             Response::quickResponse(200, json_encode(['status' => $_status, 'title' => $_title, 'message' => $_message]));
         } else {
             $response = new Response();
             $response->setHeader('Location', 'http://' . $_SERVER['HTTP_HOST'] . '/Patients.php?status=' . $_status . '&title=' . $_title . '&message=' . $_message);
             $response->send();
         }
     } else {
         $_status = 'error';
         $_title = 'Erreur de suppression!';
         $_message = 'Erreur lors de la suppression. Réessayez!';
         if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
             Response::quickResponse(200, json_encode(['status' => $_status, 'title' => $_title, 'message' => $_message]));
         } else {
             $response = new Response();
             $response->setHeader('Location', 'http://' . $_SERVER['HTTP_HOST'] . '/Patients.php?status=' . $_status . '&title=' . $_title . '&message=' . $_message);
             $response->send();
         }
     }
 }
开发者ID:xdrm-brackets,项目名称:projetphp,代码行数:26,代码来源:Patient.class.php

示例15: testSetContentTypeHeader

 public function testSetContentTypeHeader()
 {
     $response = new Response(200);
     $response->setHeader('Content-type', 'text/html');
     assertThat($this->readAttribute($response, 'headers'), is(equalTo(['Content-type' => 'text/html'])));
 }
开发者ID:eddmann,项目名称:rootr,代码行数:6,代码来源:ResponseTest.php


注:本文中的Response::setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。