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


PHP SS_HTTPResponse::addHeader方法代码示例

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


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

示例1: jsonResponse

 /**
  * Handles returning a JSON response, makes sure Content-Type header is set
  *
  * @param array $array
  * @param bool $isJson Is the passed string already a json string
  * @return SS_HTTPResponse
  */
 public function jsonResponse($array, $isJson = false)
 {
     $json = $array;
     if (!$isJson) {
         $json = Convert::raw2json($array);
     }
     $response = new SS_HTTPResponse($json);
     $response->addHeader('Content-Type', 'application/json');
     $response->addHeader('Vary', 'Accept');
     return $response;
 }
开发者ID:webtorque7,项目名称:inpage-modules,代码行数:18,代码来源:ModuleController.php

示例2: getGoogleMapPin

 public function getGoogleMapPin(SS_HTTPRequest $request)
 {
     $color = Convert::raw2sql($request->param('Color'));
     $path = ASSETS_PATH . '/maps/pins';
     // create folder on assets if does not exists ....
     if (!is_dir($path)) {
         mkdir($path, $mode = 0775, $recursive = true);
     }
     // if not get it from google (default)
     $ping_url = "http://chart.apis.google.com/chart?cht=mm&chs=32x32&chco=FFFFFF,{$color},000000&ext=.png";
     $write_2_disk = true;
     if (file_exists($path . '/pin_' . $color . '.jpg')) {
         // if we have the file on assets use it
         $ping_url = $path . '/pin_' . $color . '.jpg';
         $write_2_disk = false;
     }
     $body = file_get_contents($ping_url);
     if ($write_2_disk) {
         file_put_contents($path . '/pin_' . $color . '.jpg', $body);
     }
     $ext = 'jpg';
     $response = new SS_HTTPResponse($body, 200);
     $response->addHeader('Content-Type', 'image/' . $ext);
     return $response;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:25,代码来源:GoogleImagesApi.php

示例3: testAddCacheHeaders

 public function testAddCacheHeaders()
 {
     $body = "<html><head></head><body><h1>Mysite</h1></body></html>";
     $response = new SS_HTTPResponse($body, 200);
     $this->assertEmpty($response->getHeader('Cache-Control'));
     HTTP::set_cache_age(30);
     HTTP::add_cache_headers($response);
     $this->assertNotEmpty($response->getHeader('Cache-Control'));
     // Ensure max-age is zero for development.
     Config::inst()->update('Director', 'environment_type', 'dev');
     $response = new SS_HTTPResponse($body, 200);
     HTTP::add_cache_headers($response);
     $this->assertContains('max-age=0', $response->getHeader('Cache-Control'));
     // Ensure max-age setting is respected in production.
     Config::inst()->update('Director', 'environment_type', 'live');
     $response = new SS_HTTPResponse($body, 200);
     HTTP::add_cache_headers($response);
     $this->assertContains('max-age=30', explode(', ', $response->getHeader('Cache-Control')));
     $this->assertNotContains('max-age=0', $response->getHeader('Cache-Control'));
     // Still "live": Ensure header's aren't overridden if already set (using purposefully different values).
     $headers = array('Vary' => '*', 'Pragma' => 'no-cache', 'Cache-Control' => 'max-age=0, no-cache, no-store');
     $response = new SS_HTTPResponse($body, 200);
     foreach ($headers as $name => $value) {
         $response->addHeader($name, $value);
     }
     HTTP::add_cache_headers($response);
     foreach ($headers as $name => $value) {
         $this->assertEquals($value, $response->getHeader($name));
     }
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:30,代码来源:HTTPTest.php

示例4: httpError

 public function httpError($code, $message = null)
 {
     $response = new SS_HTTPResponse();
     $response->setStatusCode($code);
     $response->addHeader('Content-Type', 'text/html');
     return $response;
 }
开发者ID:Thingee,项目名称:openstack-org,代码行数:7,代码来源:SurveyPage.php

示例5: upload

 /**
  * Action to handle upload of a single file
  *
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  * @return SS_HTTPResponse
  */
 public function upload(SS_HTTPRequest $request)
 {
     if ($this->isDisabled() || $this->isReadonly() || !$this->canUpload()) {
         return $this->httpError(403);
     }
     // Protect against CSRF on destructive action
     $token = $this->getForm()->getSecurityToken();
     if (!$token->checkRequest($request)) {
         return $this->httpError(400);
     }
     // Get form details
     $name = $this->getName();
     $postVars = $request->postVar($name);
     // Save the temporary file into a File object
     $uploadedFiles = $this->extractUploadedFileData($postVars);
     $firstFile = reset($uploadedFiles);
     $file = $this->saveTemporaryFile($firstFile, $error);
     if (empty($file)) {
         $return = array('error' => $error);
     } else {
         $return = $this->encodeFileAttributes($file);
     }
     // Format response with json
     $response = new SS_HTTPResponse(Convert::raw2json(array($return)));
     $response->addHeader('Content-Type', 'text/plain');
     if (!empty($return['error'])) {
         $response->setStatusCode(200);
     }
     return $response;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:37,代码来源:CustomUploadField.php

示例6: count

 /**
  * Returns the unread count in a JSONobject
  * 
  * @return SS_HTTPResponse
  */
 public function count()
 {
     $notifications = TimelineEvent::get_unread(Member::currentUser());
     $response = new SS_HTTPResponse(json_encode(array('count' => $notifications->count())), 200);
     $response->addHeader('Content-Type', 'application/json');
     return $response;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-timeline,代码行数:12,代码来源:Timeline.php

示例7: load

 public function load($request)
 {
     $response = new SS_HTTPResponse();
     $response->addHeader('Content-Type', 'application/json');
     $response->setBody(Convert::array2json(array("_memberID" => Member::currentUserID())));
     return $response;
 }
开发者ID:spekulatius,项目名称:silverstripe-bootstrap_extra_fields,代码行数:7,代码来源:KeepAliveField.php

示例8: load

 public function load($request)
 {
     $response = new SS_HTTPResponse();
     $response->addHeader('Content-Type', 'application/json');
     $response->setBody(Convert::array2json(call_user_func($this->source, $request->getVar('val'))));
     return $response;
 }
开发者ID:spekulatius,项目名称:silverstripe-bootstrap_extra_fields,代码行数:7,代码来源:BootstrapTypeaheadField.php

示例9: curlRequest

 /**
  * Use cURL to request a URL, and return a SS_HTTPResponse object.
  */
 protected function curlRequest($url, $method, $data = null, $headers = null, $curlOptions = array())
 {
     $ch = curl_init();
     $timeout = 5;
     $ssInfo = new SapphireInfo();
     $useragent = 'SilverStripe/' . $ssInfo->version();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     if ($headers) {
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     }
     // Add fields to POST and PUT requests
     if ($method == 'POST') {
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     } elseif ($method == 'PUT') {
         $put = fopen("php://temp", 'r+');
         fwrite($put, $data);
         fseek($put, 0);
         curl_setopt($ch, CURLOPT_PUT, 1);
         curl_setopt($ch, CURLOPT_INFILE, $put);
         curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
     }
     // Follow redirects
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
     // Set any custom options passed to the request() function
     curl_setopt_array($ch, $curlOptions);
     // Run request
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $fullResponseBody = curl_exec($ch);
     $curlError = curl_error($ch);
     list($responseHeaders, $responseBody) = preg_split('/(\\n\\r?){2}/', $fullResponseBody, 2);
     if (preg_match("#^HTTP/1.1 100#", $responseHeaders)) {
         list($responseHeaders, $responseBody) = preg_split('/(\\n\\r?){2}/', $responseBody, 2);
     }
     $responseHeaders = explode("\n", trim($responseHeaders));
     array_shift($responseHeaders);
     $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($curlError !== '' || $statusCode == 0) {
         $statusCode = 500;
     }
     $response = new SS_HTTPResponse($responseBody, $statusCode);
     foreach ($responseHeaders as $headerLine) {
         if (strpos($headerLine, ":") !== false) {
             list($headerName, $headerVal) = explode(":", $headerLine, 2);
             // This header isn't relevant outside of curlRequest
             if (strtolower($headerName) == 'transfer-encoding') {
                 continue;
             }
             $response->addHeader(trim($headerName), trim($headerVal));
         }
     }
     curl_close($ch);
     return $response;
 }
开发者ID:adrexia,项目名称:deploynaut,代码行数:62,代码来源:GraphiteProxy.php

示例10: index

 /**
  * Creates and return the editing interface
  * 
  * @return string Form's HTML
  */
 public function index()
 {
     $form = $this->listForm();
     $form->setTemplate('LeftAndMain_EditForm');
     $form->addExtraClass('center cms-content');
     $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
     if ($this->request->isAjax()) {
         $response = new SS_HTTPResponse(Convert::raw2json(array('Content' => $form->forAjaxTemplate()->getValue())));
         $response->addHeader('X-Pjax', 'Content');
         $response->addHeader('Content-Type', 'text/json');
         $response->addHeader('X-Title', 'SilverStripe - Bulk ' . $this->gridField->list->dataClass . ' Editing');
         return $response;
     } else {
         $controller = $this->getToplevelController();
         return $controller->customise(array('Content' => $form));
     }
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-contacts,代码行数:22,代码来源:BulkActionAssignToList.php

示例11: Places

 function Places()
 {
     $Places = DataObject::get("Place");
     $body = $this->owner->customise(array('Places' => $Places))->renderWith("KMLPlaces");
     $response = new SS_HTTPResponse($body, 200);
     $response->addHeader('Content-type', "application/vnd.google-earth.kml+xml");
     return $response;
 }
开发者ID:ruffox,项目名称:geo,代码行数:8,代码来源:MapsDecorator.php

示例12: unLink

 /**
  * Unlink the selected records passed from the unlink bulk action.
  * 
  * @param SS_HTTPRequest $request
  *
  * @return SS_HTTPResponse List of affected records ID
  */
 public function unLink(SS_HTTPRequest $request)
 {
     $ids = $this->getRecordIDList();
     $this->gridField->list->removeMany($ids);
     $response = new SS_HTTPResponse(Convert::raw2json(array('done' => true, 'records' => $ids)));
     $response->addHeader('Content-Type', 'text/json');
     return $response;
 }
开发者ID:sumitnis,项目名称:GridFieldBulkEditingTools,代码行数:15,代码来源:GridFieldBulkActionUnlinkHandler.php

示例13: suggest

 /**
  * Returns a JSON string of tags, for lazy loading.
  *
  * @param SS_HTTPRequest $request
  *
  * @return SS_HTTPResponse
  */
 public function suggest(SS_HTTPRequest $request)
 {
     $members = $this->getMembers($request->getVar('term'));
     $response = new SS_HTTPResponse();
     $response->addHeader('Content-Type', 'application/json');
     $response->setBody(json_encode($members));
     return $response;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:15,代码来源:MemberAutoCompleteField.php

示例14: applyToResponse

 /**
  * @param Object $originator
  * @param SS_HTTPRequest $request
  * @param SS_HTTPResponse $response
  * @param DataModel $model
  */
 public function applyToResponse($originator, SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     foreach ($this->headers as $key => $value) {
         if ($value !== "") {
             $response->addHeader($key, $value);
         } else {
             $response->removeHeader($key);
         }
     }
 }
开发者ID:mateusz,项目名称:controllerpolicy,代码行数:16,代码来源:CustomHeaderPolicy.php

示例15: postRequest

 public function postRequest(\SS_HTTPRequest $request, \SS_HTTPResponse $response, \DataModel $model)
 {
     $time = sprintf('%.3f ms', microtime(true) - $this->start);
     $response->addHeader('X-SilverStripe-Time', $time);
     $b = $response->getBody();
     if (strpos($b, '</html>')) {
         $b = str_replace('</html>', "\n<!-- Generated in {$time} -->\n</html>", $b);
         $response->setBody($b);
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-ssautesting,代码行数:10,代码来源:RequestTimerFilter.php


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