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


PHP Http\Headers类代码示例

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


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

示例1: indexAction

 /**
  * {@inheritDoc}
  *
  * @return Stream|Response
  */
 public function indexAction()
 {
     $response = $this->getResponse();
     $params = $this->params()->fromRoute();
     if ($params['path'] === '') {
         $response->setStatusCode(404);
         return $response;
     }
     $info = pathinfo($params['path']);
     if ($info['dirname'] === '.') {
         $info['dirname'] = '';
     }
     /* @var $folder \CmsFile\Mapping\FolderInterface */
     $folder = $this->getFolderService()->getMapper()->findOneByPath('/' . trim($info['dirname'], '/'));
     if (!$folder) {
         $response->setStatusCode(404);
         return $response;
     }
     $file = $folder->getFile($info['basename']);
     if (!$file) {
         $response->setStatusCode(404);
         return $response;
     }
     $response = new Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', $file->getType())->addHeaderLine('Content-Disposition', 'attachment; filename="' . $file->getTitle() . '"')->addHeaderLine('Content-Length', filesize($file));
     $response->setHeaders($headers);
     return $response;
 }
开发者ID:coolms,项目名称:file,代码行数:36,代码来源:IndexController.php

示例2: disableHttpCache

 /**
  * Prepare cache-busting headers for GET requests
  *
  * Invoked from the onFinish() method for GET requests to disable client-side HTTP caching.
  *
  * @param Headers $headers
  */
 protected function disableHttpCache(Headers $headers)
 {
     $headers->addHeader(new GenericHeader('Expires', '0'));
     $headers->addHeader(new GenericMultiHeader('Cache-Control', 'no-store, no-cache, must-revalidate'));
     $headers->addHeader(new GenericMultiHeader('Cache-Control', 'post-check=0, pre-check=0'));
     $headers->addHeaderLine('Pragma', 'no-cache');
 }
开发者ID:zfcampus,项目名称:zf-apigility-admin,代码行数:14,代码来源:DisableHttpCacheListener.php

示例3: sendRequest

 /**
  * {@inheritdoc}
  */
 public function sendRequest(RequestInterface $request)
 {
     $request = $this->sanitizeRequest($request);
     $headers = new Headers();
     foreach ($request->getHeaders() as $key => $value) {
         $headers->addHeader(new GenericHeader($key, $request->getHeaderLine($key)));
     }
     $zendRequest = new Request();
     $zendRequest->setMethod($request->getMethod());
     $zendRequest->setUri((string) $request->getUri());
     $zendRequest->setHeaders($headers);
     $zendRequest->setContent($request->getBody()->getContents());
     $options = ['httpversion' => $request->getProtocolVersion()];
     if (extension_loaded('curl')) {
         $options['curloptions'] = [CURLOPT_HTTP_VERSION => $this->getProtocolVersion($request->getProtocolVersion())];
     }
     $this->client->setOptions($options);
     if ($this->client->getAdapter() instanceof ZendClient\Adapter\Curl && $request->getMethod()) {
         $request = $request->withHeader('Content-Length', '0');
     }
     try {
         $zendResponse = $this->client->send($zendRequest);
     } catch (RuntimeException $exception) {
         throw new NetworkException($exception->getMessage(), $request, $exception);
     }
     return $this->responseFactory->createResponse($zendResponse->getStatusCode(), $zendResponse->getReasonPhrase(), $zendResponse->getHeaders()->toArray(), $zendResponse->getContent(), $zendResponse->getVersion());
 }
开发者ID:php-http,项目名称:zend-adapter,代码行数:30,代码来源:Client.php

示例4: get

 public function get($id)
 {
     $headers = new Headers();
     $headers->addHeaderLine('Access-Control-Allow-Origin', '*');
     $json = new JsonModel(array('data' => $this->listadoCursos($id)));
     return $json;
 }
开发者ID:sebaxplace,项目名称:skilla-local,代码行数:7,代码来源:EjemploServidorRestfulController.php

示例5: prepareResponseHeaders

 /**
  * Normalize headers to use with HeaderAwareResponseInterface.
  *
  * Ensures multi-value headers are represented as a single string, via
  * comma concatenation.
  *
  * @param Headers $headers
  * @return array
  */
 private function prepareResponseHeaders(Headers $headers)
 {
     $normalized = [];
     foreach ($headers->toArray() as $name => $value) {
         $normalized[$name] = is_array($value) ? implode(', ', $value) : $value;
     }
     return $normalized;
 }
开发者ID:DenLilleMand,项目名称:christianssite,代码行数:17,代码来源:ZendHttpClientDecorator.php

示例6: __invoke

 /**
  * Retrieve Mobile-detect service
  * @param \Zend\Http\Headers $oHeaders
  * @return \Mobile_Detect
  */
 public function __invoke(\Zend\Http\Headers $oHeaders = null)
 {
     $oMobileDetect = $this->getServiceLocator()->getServiceLocator()->get('MobileDetect');
     if ($oHeaders) {
         $oMobileDetect->setHttpHeaders($oHeaders->toArray());
         $oMobileDetect->setUserAgent($oHeaders->get('user-agent')->getFieldValue());
     }
     return $oMobileDetect;
 }
开发者ID:zhangyuxiao,项目名称:qoros,代码行数:14,代码来源:MobileDetectHelper.php

示例7:

 function it_should_be_use_constant(Headers $headers)
 {
     $headers->clearHeaders()->shouldBeCalledTimes(1);
     $headers->addHeaderLine("Content-Type", "application/json")->shouldBeCalledTimes(1);
     $headers->addHeaderLine("Authorization", "token token")->shouldBeCalledTimes(1);
     $this->setHeaders($headers);
     $this->setStatusFor("aaa", ["state" => \Gstatus\Request\Status::FAILURE]);
     $this->prepareRequest("token");
     $this->getContent()->shouldBe('{"state":"failure"}');
 }
开发者ID:gianarb,项目名称:gstatus,代码行数:10,代码来源:StatusSpec.php

示例8: getHeadersFromResponse

 /**
  * @param \Zend_Controller_Response_Abstract $response
  * @return \Zend\Http\Headers
  */
 protected function getHeadersFromResponse(\Zend_Controller_Response_Abstract $response)
 {
     $headers = new HttpHeaders();
     foreach ($response->getRawHeaders() as $header) {
         $headers->addHeaderLine($header);
     }
     foreach ($response->getHeaders() as $header) {
         $headers->addHeaderLine($header['name'], $header['value']);
     }
     return $headers;
 }
开发者ID:xemlock,项目名称:Zf1Module,代码行数:15,代码来源:RenderListener.php

示例9: testClearHeaderAndHeaderNotExists

 public function testClearHeaderAndHeaderNotExists()
 {
     $response = $this->response = $this->getMock('Magento\\Framework\\HTTP\\PhpEnvironment\\Response', ['getHeaders', 'send']);
     $this->headers->addHeaderLine('Header-name: header-value');
     $header = \Zend\Http\Header\GenericHeader::fromString('Header-name: header-value');
     $this->headers->expects($this->once())->method('has')->with('Header-name')->will($this->returnValue(false));
     $this->headers->expects($this->never())->method('get')->with('Header-name')->will($this->returnValue($header));
     $this->headers->expects($this->never())->method('removeHeader')->with($header);
     $response->expects($this->once())->method('getHeaders')->will($this->returnValue($this->headers));
     $response->clearHeader('Header-name');
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:ResponseTest.php

示例10: validateMediaType

 /**
  * Validate the passed mediatype against the appropriate header
  *
  * @param  string $match
  * @param  HttpHeaders $headers
  * @return bool
  */
 protected function validateMediaType($match, HttpHeaders $headers)
 {
     if (!$headers->has('accept')) {
         return true;
     }
     $accept = $headers->get('accept');
     if ($accept->match($match)) {
         return true;
     }
     return false;
 }
开发者ID:antarus,项目名称:mystra-pve,代码行数:18,代码来源:AcceptFilterListener.php

示例11: getRequest

 /**
  * Get Request
  *
  * @return Request
  */
 public function getRequest()
 {
     if (empty($this->request)) {
         $headers = new Headers();
         $headers->addHeaders(array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
         $request = parent::getRequest();
         $request->setHeaders($headers);
         $request->setMethod('POST');
     }
     return $this->request;
 }
开发者ID:webpants,项目名称:YAWIK,代码行数:16,代码来源:RestClient.php

示例12: __invoke

 /**
  * Retrieve Mobile-detect service
  *
  * @param \Zend\Http\Headers $oHeaders
  *
  * @throws \LogicException
  * @return \Mobile_Detect
  */
 public function __invoke(\Zend\Http\Headers $oHeaders = null)
 {
     $oController = $this->getController();
     if (!$oController) {
         throw new \LogicException('Controller is undefined for MobileDetect controller plugin');
     }
     if ($oHeaders) {
         $this->mobileDetect->setHttpHeaders($oHeaders->toArray());
         $this->mobileDetect->setUserAgent($oHeaders->get('user-agent')->getFieldValue());
     }
     return $this->mobileDetect;
 }
开发者ID:neilime,项目名称:zf2-mobile-detect,代码行数:20,代码来源:MobileDetectPlugin.php

示例13: testFromResponseInCookie

 public function testFromResponseInCookie()
 {
     $response = new Response();
     $headers = new Headers();
     $header = new SetCookie("foo", "bar");
     $header->setDomain("www.zend.com");
     $header->setPath("/");
     $headers->addHeader($header);
     $response->setHeaders($headers);
     $response = Cookies::fromResponse($response, "http://www.zend.com");
     $this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo'));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:12,代码来源:CookiesTest.php

示例14: execute

 /**
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function execute()
 {
     $optionsRenderer = $this->getOptionsRenderer();
     $delimiter = ',';
     if (isset($optionsRenderer['delimiter'])) {
         $delimiter = $optionsRenderer['delimiter'];
     }
     $enclosure = '"';
     if (isset($optionsRenderer['enclosure'])) {
         $enclosure = $optionsRenderer['enclosure'];
     }
     $options = $this->getOptions();
     $optionsExport = $options['settings']['export'];
     $path = $optionsExport['path'];
     $saveFilename = date('Y-m-d_H-i-s') . $this->getCacheId() . '.csv';
     $fp = fopen($path . '/' . $saveFilename, 'w');
     // Force UTF-8 for CSV rendering in EXCEL.
     fprintf($fp, chr(0xef) . chr(0xbb) . chr(0xbf));
     /*
      * Save the file
      */
     // header
     if (isset($optionsRenderer['header']) && true === $optionsRenderer['header']) {
         $header = [];
         foreach ($this->getColumnsToExport() as $col) {
             $header[] = $this->getTranslator()->translate($col->getLabel());
         }
         fputcsv($fp, $header, $delimiter, $enclosure);
     }
     // data
     foreach ($this->getData() as $row) {
         $csvRow = [];
         foreach ($this->getColumnsToExport() as $col) {
             $value = $row[$col->getUniqueId()];
             if ($col->getType() instanceof Type\PhpArray || $col->getType() instanceof Type\Image) {
                 $value = implode(',', $value);
             }
             $csvRow[] = $value;
         }
         fputcsv($fp, $csvRow, $delimiter, $enclosure);
     }
     fclose($fp);
     /*
      * Return the file
      */
     $response = new ResponseStream();
     $response->setStream(fopen($path . '/' . $saveFilename, 'r'));
     $headers = new Headers();
     $headers->addHeaders(['Content-Type' => ['application/force-download', 'application/octet-stream', 'application/download', 'text/csv; charset=utf-8'], 'Content-Length' => filesize($path . '/' . $saveFilename), 'Content-Disposition' => 'attachment;filename=' . $this->getFilename() . '.csv', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'no-cache', 'Expires' => 'Thu, 1 Jan 1970 00:00:00 GMT']);
     $response->setHeaders($headers);
     return $response;
 }
开发者ID:jonathangreco,项目名称:ZfcDatagrid,代码行数:56,代码来源:Renderer.php

示例15: nearby

 public static function nearby($countryCode, $postalCode)
 {
     $http = new Client();
     $http->setOptions(array('sslverifypeer' => false));
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', 'application/json');
     $http->setHeaders($headers);
     $http->setUri(self::$apiUrl . 'nearby/' . urlencode($countryCode) . '/' . urlencode($postalCode));
     $http->setMethod('GET');
     $response = $http->send();
     $json = Json::decode($response->getBody());
     return $json;
 }
开发者ID:TomHAnderson,项目名称:ZippopotamusClient-PHP,代码行数:13,代码来源:Zippopotamus.php


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