本文整理汇总了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;
}
示例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');
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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"}');
}
示例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;
}
示例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');
}
示例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;
}
示例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;
}
示例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;
}
示例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'));
}
示例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;
}
示例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;
}