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


PHP SS_HTTPRequest::getHeader方法代码示例

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


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

示例1: placeOrder

 public function placeOrder(SS_HTTPRequest $request)
 {
     $eventbrite_event_header = $request->getHeader('X-Eventbrite-Event');
     if (!$eventbrite_event_header) {
         return $this->httpError(403);
     }
     if ($eventbrite_event_header !== 'order.placed') {
         return $this->httpError(403);
     }
     if (!$this->isJson()) {
         return $this->httpError(403);
     }
     $json_request = $this->getJsonRequest();
     if (!isset($json_request['config']) || !isset($json_request['api_url'])) {
         return $this->httpError(403);
     }
     $config = $json_request['config'];
     if (!isset($config['action']) || $config['action'] !== 'order.placed') {
         return $this->httpError(403);
     }
     $current_local_url = Controller::join_links(Director::absoluteBaseURL(), $request->getURL());
     if (!isset($config['endpoint_url']) || $config['endpoint_url'] !== $current_local_url) {
         return $this->httpError(403);
     }
     try {
         $this->manager->registerEvent('ORDER_PLACED', $json_request['api_url']);
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->httpError(500);
     }
     return true;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:32,代码来源:EventbriteOrderPlacedEndpoint.php

示例2: respond

 /**
  * Out of the box, the handler "CurrentForm" value, which will return the rendered form.  
  * Non-Ajax calls will redirect back.
  * 
  * @param SS_HTTPRequest $request 
  * @param array $extraCallbacks List of anonymous functions or callables returning either a string
  * or SS_HTTPResponse, keyed by their fragment identifier. The 'default' key can
  * be used as a fallback for non-ajax responses.
  * @param array $fragmentOverride Change the response fragments.
  * @return SS_HTTPResponse
  */
 public function respond(SS_HTTPRequest $request, $extraCallbacks = array())
 {
     // Prepare the default options and combine with the others
     $callbacks = array_merge($this->callbacks, $extraCallbacks);
     $response = $this->getResponse();
     $responseParts = array();
     if (isset($this->fragmentOverride)) {
         $fragments = $this->fragmentOverride;
     } elseif ($fragmentStr = $request->getHeader('X-Pjax')) {
         $fragments = explode(',', $fragmentStr);
     } else {
         if ($request->isAjax()) {
             throw new SS_HTTPResponse_Exception("Ajax requests to this URL require an X-Pjax header.", 400);
         }
         $response->setBody(call_user_func($callbacks['default']));
         return $response;
     }
     // Execute the fragment callbacks and build the response.
     foreach ($fragments as $fragment) {
         if (isset($callbacks[$fragment])) {
             $res = call_user_func($callbacks[$fragment]);
             $responseParts[$fragment] = $res ? (string) $res : $res;
         } else {
             throw new SS_HTTPResponse_Exception("X-Pjax = '{$fragment}' not supported for this URL.", 400);
         }
     }
     $response->setBody(Convert::raw2json($responseParts));
     $response->addHeader('Content-Type', 'text/json');
     return $response;
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:41,代码来源:PjaxResponseNegotiator.php

示例3: getToken

 protected function getToken(SS_HTTPRequest $request)
 {
     $token = $request->requestVar('token');
     if (!$token) {
         $token = $request->getHeader('X-Auth-Token');
     }
     return $token;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-webservices,代码行数:8,代码来源:WebserviceAuthenticator.php

示例4: getPulledRegionIDs

 /**
  * Looks first for the X-Pull-Regions header and then for a __regions__ get/post var.
  * @return array
  */
 protected function getPulledRegionIDs()
 {
     if (!$this->request) {
         return array();
     }
     $header = $this->request->getHeader(self::PULL_HEADER);
     if (!empty($header)) {
         return explode(',', $header);
     }
     $param = $this->request->requestVar(self::PULL_PARAM);
     if (!empty($param)) {
         return explode(',', $param);
     }
     return array();
 }
开发者ID:markguinn,项目名称:silverstripe-ajax,代码行数:19,代码来源:AjaxHttpResponse.php

示例5: isRequsetBot

 /**
  * Determins if the given request is from a bot
  *
  * Google ranks sites with the same content on different URLs lower.
  * This makes the site deliver single pages to bots
  *
  * @link http://www.beautifulcoding.com/snippets/178/a-simple-php-bot-checker-are-you-human/
  * @return boolean
  */
 public static function isRequsetBot(\SS_HTTPRequest $request)
 {
     $bots = Config::inst()->get('AllInOnePage', 'Bots');
     $result = $request->getVar("mockBot") == "true";
     if (!$result) {
         foreach ($bots as $spider) {
             //If the spider text is found in the current user agent, then return true
             if (stripos($request->getHeader("User-Agent"), $spider) !== false) {
                 $result = true;
             }
         }
     }
     //        echo '<pre class="debug"> "$result"' . PHP_EOL . print_r($result ? "yes" : "no", true) . PHP_EOL . '</pre>';
     return $result || $request->getVar("mockBot") == "true";
 }
开发者ID:ramana-devasani,项目名称:silverstripe-all-in-one-page,代码行数:24,代码来源:AllInOneHelper.php

示例6: getCountryForRequest

 /**
  * @param \SS_HTTPRequest $request
  * @return \Heystack\Ecommerce\Locale\Interfaces\CountryInterface|null
  */
 public function getCountryForRequest(\SS_HTTPRequest $request)
 {
     $location = false;
     if ($this->isAllowedUserAgent($request->getHeader('User-Agent'))) {
         $ip = static::parseIP($request->getIP());
         if (!$ip) {
             return null;
         }
         $fp = fopen(sprintf('https://geoip.maxmind.com/a?l=%s&i=%s', $this->key, $ip), 'r', null, stream_context_create(['https' => ['timeout' => $this->timeout]]));
         if (is_resource($fp)) {
             $location = stream_get_contents($fp);
             fclose($fp);
         }
     }
     return $location ? $this->localeService->getCountry(new Identifier($location)) : null;
 }
开发者ID:heyday,项目名称:heystack-ecommerce-maxmindlocaledetector,代码行数:20,代码来源:MaxMindLocaleDetector.php

示例7: validateHmac

 /**
  * Verify whether the given user/request has a valid HMAC header
  * 
  * HMAC should be calculated as a concatenation of 
  * 
  * service name
  * method called
  * gmdate in format YmdH
  * 
  * So an example before hashing would be
  * 
  * product-getPrice-20130225
  * 
  * The key used for signing should come from the user's "AuthPrivateKey" field
  * 
  * The validator will accept an hour either side of 'now'
  * 
  * @param type $user
  * @param SS_HTTPRequest $request
  * @return boolean
  */
 public function validateHmac($user, SS_HTTPRequest $request)
 {
     $service = $request->param('Service');
     $method = $request->param('Method');
     $hmac = $request->getHeader('X-Silverstripe-Hmac');
     $key = $user->AuthPrivateKey;
     if (!strlen($key)) {
         return false;
     }
     $times = array(gmdate('YmdH', strtotime('-1 hour')), gmdate('YmdH'), gmdate('YmdH', strtotime('+1 hour')));
     foreach ($times as $time) {
         $message = $this->generateHmac(array($service, $method, $time), $key);
         if ($message == $hmac) {
             return true;
         }
     }
     return false;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-webservices,代码行数:39,代码来源:WebserviceMethodHmacValidator.php

示例8: redirectBack

 /**
  * Redirect back. Uses either the HTTP_REFERER or a manually set request-variable called
  * _REDIRECT_BACK_URL.
  * This variable is needed in scenarios where not HTTP-Referer is sent (
  * e.g when calling a page by location.href in IE).
  * If none of the two variables is available, it will redirect to the base
  * URL (see {@link Director::baseURL()}).
  * @uses redirect()
  */
 function redirectBack()
 {
     if ($this->request->requestVar('_REDIRECT_BACK_URL')) {
         $url = $this->request->requestVar('_REDIRECT_BACK_URL');
     } else {
         if ($this->request->getHeader('Referer')) {
             $url = $this->request->getHeader('Referer');
         } else {
             $url = Director::baseURL();
         }
     }
     // absolute redirection URLs not located on this site may cause phishing
     if (Director::is_site_url($url)) {
         return $this->redirect($url);
     } else {
         return false;
     }
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:27,代码来源:Controller.php

示例9: respond

	/**
	 * Out of the box, the handler "CurrentForm" value, which will return the rendered form.  
	 * Non-Ajax calls will redirect back.
	 * 
	 * @param SS_HTTPRequest $request 
	 * @param array $extraCallbacks List of anonymous functions or callables returning either a string
	 * or SS_HTTPResponse, keyed by their fragment identifier. The 'default' key can
	 * be used as a fallback for non-ajax responses.
	 * @return SS_HTTPResponse
	 */
	public function respond(SS_HTTPRequest $request, $extraCallbacks = array()) {
		// Prepare the default options and combine with the others
		$callbacks = array_merge(
			array_change_key_case($this->callbacks, CASE_LOWER),
			array_change_key_case($extraCallbacks, CASE_LOWER)
		);
		
		if($fragment = $request->getHeader('X-Pjax')) {
			$fragment = strtolower($fragment);
			if(isset($callbacks[$fragment])) {
				return call_user_func($callbacks[$fragment]);
			} else {
				throw new SS_HTTPResponse_Exception("X-Pjax = '$fragment' not supported for this URL.", 400);
			}
		} else {
			if($request->isAjax()) throw new SS_HTTPResponse_Exception("Ajax requests to this URL require an X-Pjax header.", 400);
			return call_user_func($callbacks['default']);
		}
		
	}
开发者ID:redema,项目名称:sapphire,代码行数:30,代码来源:PjaxResponseNegotiator.php

示例10: incoming

 /**
  * Handle incoming webhook
  *
  * @link https://developers.sparkpost.com/api/#/reference/webhooks/create-a-webhook
  * @link https://www.sparkpost.com/blog/webhooks-beyond-the-basics/
  * @link https://support.sparkpost.com/customer/portal/articles/1976204-webhook-event-reference
  * @param SS_HTTPRequest $req
  */
 public function incoming(SS_HTTPRequest $req)
 {
     // Each webhook batch contains the header X-MessageSystems-Batch-ID,
     // which is useful for auditing and prevention of processing duplicate batches.
     $batchId = $req->getHeader('X-MessageSystems-Batch-ID');
     $json = file_get_contents('php://input');
     // By default, return a valid response
     $response = $this->getResponse();
     $response->setStatusCode(200);
     $response->setBody('NO DATA');
     if (!$json) {
         return $response;
     }
     $payload = json_decode($json, JSON_OBJECT_AS_ARRAY);
     try {
         $this->processPayload($payload, $batchId);
     } catch (Exception $ex) {
         // Maybe processing payload will create exceptions, but we
         // catch them to send a proper response to the API
     }
     $response->setBody('OK');
     return $response;
 }
开发者ID:lekoala,项目名称:silverstripe-sparkpost,代码行数:31,代码来源:SparkPostController.php

示例11: preRequest

 public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     $headerName = Config::inst()->get('ApiKeyRequestFilter', 'header_name');
     if ($key = $request->getHeader($headerName)) {
         try {
             $matchingKey = MemberApiKey::findByKey($key);
         } catch (LogicException $e) {
         }
         if ($matchingKey) {
             // Log-in can't have session injected, we need to to push $session into the global state
             $controller = new Controller();
             $controller->setSession($session);
             $controller->pushCurrent();
             $matchingKey->Member()->logIn();
             // Undo our global state manipulation
             $controller->popCurrent();
             $matchingKey->markUsed();
         } else {
             throw new SS_HTTPResponse_Exception("Bad X-API-Key", 400);
         }
     }
     return true;
 }
开发者ID:sminnee,项目名称:silverstripe-apikey,代码行数:23,代码来源:ApiKeyRequestFilter.php

示例12: get_token

 /**
  * Returns the token from the request.
  *
  * Silverstripe doesn't include Authorization header in its requests. We should check it, because we can use the
  * mechanism in the tests.
  * @param \SS_HTTPRequest $request
  * @return String the token
  * @throws \Exception
  */
 public static function get_token($request)
 {
     // try to get the token from request object
     $tokenStrFromHeader = $request->getHeader('Authorization');
     $tokenStrFromVar = $request->requestVar('access_token');
     if (!empty($tokenStrFromHeader)) {
         // string must have format: type token
         return explode(' ', $tokenStrFromHeader)[1];
     } else {
         if (!empty($tokenStrFromVar)) {
             // try variables
             return $tokenStrFromVar;
         } else {
             if (function_exists('getallheaders')) {
                 // get all headers from apache server
                 $headers = getallheaders();
                 if (isset($headers['Authorization'])) {
                     return explode(' ', $headers['Authorization'])[1];
                 }
             }
         }
     }
     throw new \Exception("Token can't be read or was not specified");
 }
开发者ID:notthatbad,项目名称:silverstripe-rest-api,代码行数:33,代码来源:AuthFactory.php

示例13: gridFieldAlterAction

	/**
	 * This is the action that gets executed when a GridField_AlterAction gets clicked.
	 *
	 * @param array $data
	 * @return string 
	 */
	public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request) {
		$html = '';
		$data = $request->requestVars();
		$fieldData = @$data[$this->getName()];

		// Update state from client
		$state = $this->getState(false);
		if(isset($fieldData['GridState'])) $state->setValue($fieldData['GridState']);

		// Try to execute alter action
		foreach($data as $k => $v) {
			if(preg_match('/^action_gridFieldAlterAction\?StateID=(.*)/', $k, $matches)) {
				$id = $matches[1];
				$stateChange = Session::get($id);
				$actionName = $stateChange['actionName'];
				$args = isset($stateChange['args']) ? $stateChange['args'] : array();
				$html = $this->handleAction($actionName, $args, $data);
				// A field can optionally return its own HTML
				if($html) return $html;
			}
		}
		
		switch($request->getHeader('X-Pjax')) {
			case 'CurrentField':
				return $this->FieldHolder();
				break;

			case 'CurrentForm':
				return $form->forTemplate();
				break;

			default:
				return $form->forTemplate();
				break;
		}
	}
开发者ID:redema,项目名称:sapphire,代码行数:42,代码来源:GridField.php

示例14: gridFieldAlterAction

 /**
  * @param array $data
  * @param Form $form
  * @param SS_HTTPRequest $request
  * @return HTML|HTMLText|mixed
  */
 public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request)
 {
     $data = $request->requestVars();
     $stateHash = $this->getStateHash();
     // Check if we have encountered a reset action. We need to clear the state here before
     // the other components start accessing it.
     foreach ($data as $dataKey => $dataValue) {
         if (preg_match('/^action_gridFieldAlterAction\\?StateID=(.*)/', $dataKey, $matches)) {
             $stateChange = Session::get($matches[1]);
             $actionName = $stateChange['actionName'];
             if ($actionName === 'ResetState') {
                 Session::set($stateHash, null);
                 $this->state = new GridState($this);
             }
         }
     }
     foreach ($data as $dataKey => $dataValue) {
         if (preg_match('/^action_gridFieldAlterAction\\?StateID=(.*)/', $dataKey, $matches)) {
             $stateChange = Session::get($matches[1]);
             $actionName = $stateChange['actionName'];
             $arguments = array();
             if (isset($stateChange['args'])) {
                 $arguments = $stateChange['args'];
             }
             $html = $this->handleAlterAction($actionName, $arguments, $data);
             if ($html) {
                 return $html;
             }
         }
     }
     // The state is stored in the session so that we can access it on the next page load
     $this->setStateHash($this->state->Value());
     if ($request->getHeader('X-Pjax') === 'CurrentField') {
         return $this->FieldHolder();
     }
     return $form->forTemplate();
 }
开发者ID:helpfulrobot,项目名称:littlegiant-silverstripe-persistentgridfield,代码行数:43,代码来源:PersistentGridField.php

示例15: readCampaign

 /**
  * REST endpoint to get a campaign.
  *
  * @param SS_HTTPRequest $request
  *
  * @return SS_HTTPResponse
  */
 public function readCampaign(SS_HTTPRequest $request)
 {
     $response = new SS_HTTPResponse();
     if ($request->getHeader('Accept') == 'text/json') {
         $response->addHeader('Content-Type', 'application/json');
         if (!$request->param('Name')) {
             return new SS_HTTPResponse(null, 400);
         }
         /** @var ChangeSet $changeSet */
         $changeSet = ChangeSet::get()->byID($request->param('ID'));
         if (!$changeSet) {
             return new SS_HTTPResponse(null, 404);
         }
         if (!$changeSet->canView()) {
             return new SS_HTTPResponse(null, 403);
         }
         $body = Convert::raw2json($this->getChangeSetResource($changeSet));
         return (new SS_HTTPResponse($body, 200))->addHeader('Content-Type', 'application/json');
     } else {
         return $this->index($request);
     }
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:29,代码来源:CampaignAdmin.php


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