• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP SS_HTTPResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: 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


示例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: postRequest

 public function postRequest(\SS_HTTPRequest $request, \SS_HTTPResponse $response, \DataModel $model)
 {
     if ($this->convertUrls && $response && $response->getStatusCode() == 200) {
         // only convert if we have an HTML content type response
         $body = $response->getBody();
         // find urls inserted in content
         if (strpos($body, 'cdnfileid') > 0 && preg_match_all('/data-cdnfileid="(\\d+)"/', $body, $matches)) {
             $files = CdnImage::get()->filter('ID', $matches[1]);
             $fileIds = array();
             foreach ($files as $file) {
                 $url = $file->getUrl();
                 $filename = $file->Filename;
                 $body = str_replace("src=\"{$filename}\"", "src=\"{$url}\"", $body);
                 $fileIds[] = $file->ID;
             }
             $assets = ContentServiceAsset::get()->filter('SourceID', $matches[1]);
             foreach ($assets as $asset) {
                 $url = $asset->getUrl();
                 $filename = $asset->Filename;
                 // note the extra forward slash here, image_cached inserts it
                 $body = str_replace("src=\"/{$filename}\"", "src=\"{$url}\"", $body);
             }
             $response->setBody($body);
         }
     }
 }
开发者ID:stephenmcm,项目名称:silverstripe-cdncontent,代码行数:26,代码来源:AssetUrlConversionFilter.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: handleRequest

 public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL)
 {
     $body = null;
     $lang = i18n::get_locale();
     $path = Config::inst()->get('UniversalErrorPage', 'DefaultPath');
     if (!$path) {
         $path = $this->defaultErrorPagePath;
     }
     $forCode = Config::inst()->get('UniversalErrorPage', $this->ErrorCode);
     $localeForCode = preg_replace('/\\.([a-z]+)$/i', '-' . $lang . '.$1', $forCode);
     $errorPages = array($localeForCode, $forCode, $path . "error-{$this->ErrorCode}-{$lang}.html", $path . "error-{$this->ErrorCode}-{$lang}.php", $path . "error-{$lang}.html", $path . "error-{$lang}.php", $path . 'error.html', $path . 'error.php');
     $this->extend('updateHandleRequest', $errorPages);
     // now check if any of the pages exist
     foreach ($errorPages as $errorPage) {
         if (!$body && file_exists($errorPage)) {
             $ext = pathinfo($errorPage, PATHINFO_EXTENSION);
             if ($ext == 'php') {
                 ob_start();
                 include $errorPage;
                 $body = ob_get_clean();
             } else {
                 $body = file_get_contents($errorPage);
             }
             break;
         }
     }
     if ($body) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode($this->ErrorCode);
         $response->setBody($body);
         return $response;
     }
     return parent::handleRequest($request, $model);
 }
开发者ID:Marketo,项目名称:SilverStripe-UniversalErrorPage,代码行数:34,代码来源:UniversalErrorPage.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: 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


示例9: postRequest

 public function postRequest(\SS_HTTPRequest $request, \SS_HTTPResponse $response, \DataModel $model)
 {
     if (defined('PROXY_CACHE_GENERATING') || isset($GLOBALS['__cache_publish']) || strpos($request->getURL(), 'admin/') !== false) {
         return;
     }
     $this->database = Db::getConn();
     $queries = $this->database->queryRecord;
     $dupes = $this->database->getDuplicateQueries();
     $str = "\n<!-- Total queries: " . count($queries) . "-->\n";
     $str .= "\n<!-- Duplicate queries: " . count($dupes) . "-->\n";
     $b = $response->getBody();
     if (strpos($b, '</html>')) {
         if (count($queries) > $this->queryThreshold) {
             // add a floating div with info about the stuff
             $buildQueryList = function ($source, $class) {
                 $html = '';
                 foreach ($source as $sql => $info) {
                     $html .= "\n<p class='{$class}' style='display: none; border-top: 1px dashed #000;'>{$info->count} : {$info->query}</p>\n";
                     if ($info->source) {
                         $html .= "\n<p class='{$class}' style='color: #a00; display: none; '>Last called from {$info->source}</p>\n";
                     }
                 }
                 return $html;
             };
             $html = $buildQueryList($queries, 'debug-query');
             $html .= $buildQueryList($dupes, 'debug-dupe-query');
             $div = '<div id="query-stat-debugger" ' . 'style="position: fixed; bottom: 0; right: 0; border: 2px solid red; background: #fff; ' . 'font-size: 8px; font-family: sans-serif; width: 100px; z-index: 2000; padding: 1em;' . 'overflow: auto; max-height: 500px;">' . '<p id="debug-all-queries-list">Total of ' . count($queries) . ' queries</p>' . '<p id="debug-dupe-queries-list">Total of ' . count($dupes) . ' duplicates</p>' . $html . '<script>' . 'jQuery("#debug-all-queries-list").click(function () {' . 'var elems = jQuery(this).parent().find(".debug-query");' . 'jQuery(this).parent().css("width", "40%");' . 'elems.toggle();' . '}); ' . 'jQuery("#debug-dupe-queries-list").click(function () {' . 'var elems = jQuery(this).parent().find(".debug-dupe-query");' . 'jQuery(this).parent().css("width", "40%");' . 'elems.toggle();' . '}); ' . '' . '' . '</script>' . '</div>';
             $b = str_replace('</body>', "{$div}</body>", $b);
         }
         $b = str_replace('</html>', "{$str}</html>", $b);
         $response->setBody($b);
     }
 }
开发者ID:silverstripe-australia,项目名称:ssautesting,代码行数:33,代码来源:QueryDisplayFilter.php


示例10: 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


示例11: 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


示例12: 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


示例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: 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


示例15: getResponse

 /**
  * @param \SS_HTTPRequest $request
  * @return null|\SS_HTTPResponse
  */
 public function getResponse(\SS_HTTPRequest $request)
 {
     if ($redirect = $this->getRedirectForRequest($request)) {
         $response = new \SS_HTTPResponse();
         $response->redirect($redirect->getTo(), $redirect->getStatusCode());
         return $response;
     }
     return null;
 }
开发者ID:helpfulrobot,项目名称:heyday-silverstripe-redirects,代码行数:13,代码来源:Redirector.php


示例16: postRequest

 public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     if (!$response->isError() && !Director::is_ajax()) {
         // Find or create the visitor record
         $visitor = Visitor::initVisitor();
         // Log the arrival of this visitor to this page
         $visitor->logPageArrival();
     }
 }
开发者ID:helpfulrobot,项目名称:nrsutton-visitor-tracker,代码行数:9,代码来源:VisitorExtension.php


示例17: postRequest

 /**
  * Filter executed AFTER a request
  *
  * @param SS_HTTPRequest $request Request container object
  * @param SS_HTTPResponse $response Response output object
  * @param DataModel $model Current DataModel
  * @return boolean Whether to continue processing other filters. Null or true will continue processing (optional)
  */
 public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     if (!self::isEnabled()) {
         return true;
     }
     $body = $response->getBody();
     $response->setBody(self::replaceCDN($body));
     return true;
 }
开发者ID:helpfulrobot,项目名称:wernerkrauss-cdnrewrite,代码行数:17,代码来源:CDNRewriteRequestFilter.php


示例18: 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


示例19: 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


示例20: requireLogin

 /**
  * Require basic authentication.  Will request a username and password if none is given.
  *
  * Used by {@link Controller::init()}.
  *
  * @throws SS_HTTPResponse_Exception
  *
  * @param string $realm
  * @param string|array $permissionCode Optional
  * @param boolean $tryUsingSessionLogin If true, then the method with authenticate against the
  *  session log-in if those credentials are disabled.
  * @return Member $member
  */
 public static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true)
 {
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     if (!Security::database_is_ready() || Director::is_cli() && !$isRunningTests) {
         return true;
     }
     /*
      * Enable HTTP Basic authentication workaround for PHP running in CGI mode with Apache
      * Depending on server configuration the auth header may be in HTTP_AUTHORIZATION or
      * REDIRECT_HTTP_AUTHORIZATION
      *
      * The follow rewrite rule must be in the sites .htaccess file to enable this workaround
      * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
      */
     $authHeader = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) ? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] : null);
     $matches = array();
     if ($authHeader && preg_match('/Basic\\s+(.*)$/i', $authHeader, $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     $member = null;
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $member = MoreAdminsAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null);
     }
     if (!$member && $tryUsingSessionLogin) {
         $member = Member::currentUser();
     }
     // If we've failed the authentication mechanism, then show the login form
     if (!$member) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised"));
         } else {
             $response->setBody(_t('BasicAuth.ENTERINFO', "Please enter a username and password."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     return $member;
 }
开发者ID:helpfulrobot,项目名称:level51-more-admins,代码行数:68,代码来源:MoreAdminsBasicAuth.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP SS_List类代码示例发布时间:2022-05-23
下一篇:
PHP SS_HTTPRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap