本文整理汇总了PHP中Zend\Http\Request::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getHeader方法的具体用法?PHP Request::getHeader怎么用?PHP Request::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Request
的用法示例。
在下文中一共展示了Request::getHeader方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: itemToString
/**
* Create script HTML
*
* @param mixed $item Item to convert
* @param string $indent String to add before the item
* @param string $escapeStart Starting sequence
* @param string $escapeEnd Ending sequence
*
* @return string
*/
public function itemToString($item, $indent, $escapeStart, $escapeEnd)
{
if (!empty($item->attributes['src'])) {
$ua = $this->request->getHeader('User-Agent');
$agent = $ua !== false ? $ua->toString() : '';
if (strstr($agent, 'MSIE 8.0') || strstr($agent, 'MSIE 7.0')) {
if ($item->attributes['src'] == 'vendor/jquery.min.js') {
$item->attributes['src'] = 'vendor/jquery-1.12.1.min.js';
}
}
}
return parent::itemToString($item, $indent, $escapeStart, $escapeEnd);
}
示例2: authenticate
/**
* @param Request $request
* @param Response $response
* @param MvcAuthEvent $mvcAuthEvent
* @return bool|AuthenticatedIdentity
*/
public function authenticate(Request $request, Response $response, MvcAuthEvent $mvcAuthEvent)
{
$apiUser = $request->getHeader('xapiuser', null);
$apiKey = $request->getHeader('xapikey', null);
if (null === $apiKey) {
return false;
}
if (null === $apiUser) {
return false;
}
if (true === array_key_exists($apiUser->getFieldValue(), $this->userConfig['users'])) {
if ($this->userConfig['users'][$apiUser->getFieldValue()] === $apiKey->getFieldValue()) {
return new AuthenticatedIdentity(new Identity());
}
}
return false;
}
示例3: getVersion
/**
* Get the API version from the Accept header
*
* @param Request $request
* @return integer
*/
protected function getVersion(Request $request)
{
$accept = $request->getHeader('Accept', false);
if (!$accept) {
return 1;
}
if (preg_match('/application\\/vnd\\.apigility\\.v(\\d+)\\+json/', $accept->getFieldValue(), $matches)) {
return (int) $matches[1];
}
return 1;
}
示例4: getTypeFromRequest
/**
* Determine if the incoming request provides either basic or digest
* credentials
*
* @param Request $request
* @return false|string
*/
public function getTypeFromRequest(Request $request)
{
$authorization = $request->getHeader('Authorization');
if (!$authorization) {
return false;
}
$authorization = trim($authorization->getFieldValue());
$type = $this->getTypeFromAuthorizationHeader($authorization);
if (!in_array($type, $this->authorizationTokenTypes)) {
return false;
}
return $type;
}
示例5: testParameterRetrievalDefaultValue
public function testParameterRetrievalDefaultValue()
{
$request = new Request();
$p = new \Zend\Stdlib\Parameters(array('foo' => 'bar'));
$request->setQuery($p);
$request->setPost($p);
$request->setFiles($p);
$default = 15;
$this->assertSame($default, $request->getQuery('baz', $default));
$this->assertSame($default, $request->getPost('baz', $default));
$this->assertSame($default, $request->getFiles('baz', $default));
$this->assertSame($default, $request->getHeaders('baz', $default));
$this->assertSame($default, $request->getHeader('baz', $default));
}
示例6: splitCssForIe
/**
* Check if request came from IE < 10 and too large CSS (> 4095 selectors).
* Split if necessary.
*
* @param \stdClass $item data item
* @param array $details Theme item details
*
* @return string
*/
protected function splitCssForIe(\stdClass $item, $details)
{
$file = $details['path'];
// Return right away if the file doesn't exist or is too small to
// be a problem, hopefully
if (!file_exists($file) || filesize($file) < 65535) {
return '';
}
$ua = $this->request->getHeader('User-Agent');
$agent = is_object($ua) ? $ua->toString() : '';
if (strstr($agent, 'MSIE 9.0') || strstr($agent, 'MSIE 8.0') || strstr($agent, 'MSIE 7.0')) {
$theme = $details['theme'];
$basename = basename($file);
$fileTime = filemtime($file);
$cache = $this->cacheManager->getCache('stylesheet')->getOptions()->getCacheDir();
if (!file_exists("{$cache}/{$theme}/{$basename}_part1.css") || filemtime("{$cache}/{$theme}/{$basename}_part1.css") < $fileTime) {
// Populate cache
if (!is_dir("{$cache}/{$theme}")) {
mkdir("{$cache}/{$theme}");
}
$handle = $this->acquireLock("{$cache}/{$theme}/lockfile");
array_map('unlink', glob("{$cache}/{$theme}/{$basename}_*") ?: []);
$css = file_get_contents($file);
$splitter = new \CssSplitter\Splitter($css);
$selectorCount = $splitter->countSelectors();
$partCount = ceil($selectorCount / 4095);
for ($part = 1; $part <= $partCount; $part++) {
file_put_contents("{$cache}/{$theme}/{$basename}_part{$part}.css", $splitter->split(null, $part));
}
$this->releaseLock($handle);
}
$result = [];
$urlHelper = $this->getView()->plugin('url');
$files = glob("{$cache}/{$theme}/{$basename}_part*");
foreach ($files as $css) {
$url = $urlHelper('home') . "themes/{$theme}/css/" . basename($css);
$url .= strstr($url, '?') ? '&_=' : '?_=';
$url .= filemtime($css);
$item->href = $url;
$result[] = parent::itemToString($item);
}
return implode("\n", $result);
}
return '';
}
示例7: authenticate
/**
* {@inhertidoc}
* @see \InoOicServer\Client\Authentication\Method\MethodInterface::authenticate()
*/
public function authenticate(Client\Authentication\Info $info, Http\Request $httpRequest)
{
/* @var $httpRequest \Zend\Http\Request */
$authorizationHeader = $httpRequest->getHeader('Authorization');
if (!$authorizationHeader) {
return $this->createFailureResult('Missing authorization header');
}
$value = $authorizationHeader->getFieldValue();
$parts = explode(' ', $value);
if ('basic' !== trim(strtolower($parts[0]))) {
return $this->createFailureResult(sprintf("Unsupported authorization '%s'", $parts[0]));
}
if (!isset($parts[1])) {
return $this->createFailureResult('Missing authorization hash');
}
$receivedHash = trim($parts[1]);
$clientHash = base64_encode(sprintf("%s:%s", $info->getClientId(), $info->getOption(self::AUTH_OPTION_SECRET)));
if ($receivedHash !== $clientHash) {
return $this->createFailureResult('Invalid authorization');
}
return $this->createSuccessResult();
}
示例8: processHttpRequest
private function processHttpRequest(Request $request, Collection $results)
{
$defaultAccept = new Accept();
$defaultAccept->addMediaType(self::CONTENT_TYPE_HTML);
$acceptHeader = $request->getHeader('Accept', $defaultAccept);
if ($acceptHeader->match(self::CONTENT_TYPE_HTML) || !$acceptHeader->match(self::CONTENT_TYPE_JSON)) {
// Display results as a web page
return new ViewModel(array('results' => $results));
}
return new JsonModel($this->getResultCollectionToArray($results));
}
示例9: it_should_fall_back_on_query_token_when_no_authentication_header_is_available
/**
* @param \Zend\Http\Request $request
*/
public function it_should_fall_back_on_query_token_when_no_authentication_header_is_available($request)
{
$request->getHeader('Authorization')->willReturn(null);
$request->getQuery('token', [])->willReturn(['token' => 'user_token_id', 'auth' => 'encrypted_auth']);
$this->setRequest($request);
$this->createToken()->shouldReturnAnInstanceOf('Phpro\\MvcAuthToken\\Token');
}
示例10: parse
/**
* Parse request
*
* @param \Zend\Http\Request $request
* @param \Zend\Http\Response $request
* @return string|null $error
*/
public function parse(Request $request, Response $response)
{
$this->request = $request;
$this->response = $response;
$response->getHeaders()->addHeaderLine('Content-Type', static::$responseMime . '; charset=utf-8');
$accept = $request->getHeader('Accept');
if (empty($accept)) {
return self::INVALID_REQUEST;
}
$requestMimes = implode('|', array(static::$requestMime, preg_quote('*/*', '#')));
foreach (explode(',', $accept->getFieldValue()) as $acceptType) {
if (preg_match('#^(' . $requestMimes . ')(;.*)?$#', trim($acceptType))) {
return null;
}
}
return self::INVALID_REQUEST;
}
示例11: getAllowedOriginValue
/**
* Get a single value for the "Access-Control-Allow-Origin" header
*
* According to the spec, it is not valid to set multiple origins separated by commas. Only accepted
* value are wildcard ("*"), an exact domain or a null string.
*
* @link http://www.w3.org/TR/cors/#access-control-allow-origin-response-header
* @param HttpRequest $request
* @return string
*/
protected function getAllowedOriginValue(HttpRequest $request)
{
$allowedOrigins = $this->options->getAllowedOrigins();
if (in_array('*', $allowedOrigins)) {
return '*';
}
$origin = $request->getHeader('Origin')->getFieldValue();
foreach ($allowedOrigins as $allowedOrigin) {
if (fnmatch($allowedOrigin, $origin)) {
return $origin;
}
}
return 'null';
}
示例12: _getHeader
/**
* Returns the required HTTP header.
*
* @param string $name
* @return \Zend\Http\Header\HeaderInterface|\ArrayIterator|null
*/
protected function _getHeader($name)
{
return $this->httpRequest->getHeader($name);
}
示例13: authenticate
/**
* Attempt to authenticate the current request.
*
* @param Request $request
* @param Response $response
* @param MvcAuthEvent $mvcAuthEvent
* @return false|Identity\IdentityInterface False on failure, IdentityInterface
* otherwise
*/
public function authenticate(Request $request, Response $response, MvcAuthEvent $mvcAuthEvent)
{
if (!$request->getHeader('Authorization', false)) {
// No credentials were present at all, so we just return a guest identity.
return new Identity\GuestIdentity();
}
$this->httpAuth->setRequest($request);
$this->httpAuth->setResponse($response);
$result = $this->authenticationService->authenticate($this->httpAuth);
$mvcAuthEvent->setAuthenticationResult($result);
if (!$result->isValid()) {
return false;
}
$resultIdentity = $result->getIdentity();
// Pass fully discovered identity to AuthenticatedIdentity instance
$identity = new Identity\AuthenticatedIdentity($resultIdentity);
// But determine the name separately
$name = $resultIdentity;
if (is_array($resultIdentity)) {
$name = isset($resultIdentity['username']) ? $resultIdentity['username'] : (string) array_shift($resultIdentity);
}
$identity->setName($name);
return $identity;
}
示例14: negotiateContent
/**
* Negotiates the request payload.
*
* @param \BedRest\Rest\Request\Request $restRequest
* @param \Zend\Http\Request $httpRequest
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
*/
protected function negotiateContent(RestRequest $restRequest, HttpRequest $httpRequest, ServiceLocatorInterface $serviceLocator)
{
$content = $httpRequest->getContent();
$contentType = $httpRequest->getHeader('Content-Type');
if (!empty($content) && !empty($contentType)) {
/** @var \BedRest\Content\Negotiation\Negotiator $negotiator */
$negotiator = $serviceLocator->get('BedRest.ContentNegotiator');
$restRequest->setContent($negotiator->decode($content, $contentType->value));
$restRequest->setContentType($contentType);
}
}