本文整理汇总了PHP中Zend\Http\Headers::addHeaderLine方法的典型用法代码示例。如果您正苦于以下问题:PHP Headers::addHeaderLine方法的具体用法?PHP Headers::addHeaderLine怎么用?PHP Headers::addHeaderLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Headers
的用法示例。
在下文中一共展示了Headers::addHeaderLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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"}');
}
示例2: 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;
}
示例3: 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');
}
示例4: 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');
}
示例5: 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;
}
示例6: get
public function get($id)
{
$headers = new Headers();
$headers->addHeaderLine('Access-Control-Allow-Origin', '*');
$json = new JsonModel(array('data' => $this->listadoCursos($id)));
return $json;
}
示例7: injectEsiHeader
/**
*
*/
private function injectEsiHeader()
{
if (!$this->esiHeaderInjected) {
$this->responseHeaders->addHeaderLine('Surrogate-Control', 'ESI/1.0');
$this->esiHeaderInjected = true;
}
}
示例8: 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;
}
示例9: testGet
public function testGet()
{
$expectedDate = '2015-01-01';
$headers = new Headers();
$headers->addHeaderLine(sprintf('Cookie: %s=%s', TimetableCookieListener::COOKIE_NAME, $expectedDate));
$request = new Request();
$request->setHeaders($headers);
$response = new Response();
$listener = new TimetableCookieListener($request, $response);
$event = new TimetableManagerEvent();
$listener->getTime($event);
$this->assertTrue($event->hasPointInTime());
$this->assertEquals($expectedDate, $event->getPointInTime()->format('Y-m-d'));
}
示例10: getCountries
public static function getCountries()
{
$http = new Client();
$http->setOptions(array('sslverifypeer' => false));
$headers = new Headers();
$headers->addHeaderLine('X-Mashape-Key', MASHAPE_API_KEY);
$http->setHeaders($headers);
$http->setUri("https://restcountries-v1.p.mashape.com/all");
$http->setMethod('GET');
$response = $http->send();
$json = Json::decode($response->getBody());
$data = array();
foreach ($json as $country) {
$data[] = array("code" => strtolower($country->alpha2Code), "name" => $country->name);
}
return $data;
}
示例11: _doAuth
/**
* Acts like a client sending the given Authenticate header value.
*
* @param string $clientHeader Authenticate header value
* @param string $scheme Which authentication scheme to use
* @return array Containing the result, the response headers, and the status
*/
public function _doAuth($clientHeader, $scheme)
{
// Set up stub request and response objects
$response = new Response();
$response->setStatusCode(200);
$headers = new Headers();
$headers->addHeaderLine('Proxy-Authorization', $clientHeader);
$headers->addHeaderLine('User-Agent', 'PHPUnit');
$request = new Request();
$request->setUri('http://localhost/');
$request->setMethod('GET');
$request->setHeaders($headers);
// Select an Authentication scheme
switch ($scheme) {
case 'basic':
$use = $this->_basicConfig;
break;
case 'digest':
$use = $this->_digestConfig;
break;
case 'both':
default:
$use = $this->_bothConfig;
}
// Create the HTTP Auth adapter
$a = new \Zend\Authentication\Adapter\Http($use);
$a->setBasicResolver($this->_basicResolver);
$a->setDigestResolver($this->_digestResolver);
// Send the authentication request
$a->setRequest($request);
$a->setResponse($response);
$result = $a->authenticate();
$return = array('result' => $result, 'status' => $response->getStatusCode(), 'headers' => $response->getHeaders());
return $return;
}
示例12: testUnsupportedScheme
public function testUnsupportedScheme()
{
$response = new Response();
$headers = new Headers();
$request = new Request();
$headers->addHeaderLine('Authorization', 'NotSupportedScheme <followed by a space character');
$request->setHeaders($headers);
$a = new Adapter\Http($this->_digestConfig);
$a->setDigestResolver($this->_digestResolver)->setRequest($request)->setResponse($response);
$result = $a->authenticate();
$this->assertEquals($result->getCode(), Authentication\Result::FAILURE_UNCATEGORIZED);
}
示例13: testGetContent
/**
* @covers Hermes\Api\Response::__construct
* @covers Hermes\Api\Response::getContent
*/
public function testGetContent()
{
$http = new Client();
$response = new ZendResponse();
$headers = new Headers();
$headers->addHeaderLine('Content-Type', 'application/json');
$response->setHeaders($headers);
$response->setContent(static::$sampleJson);
$this->object = new Response($http, $response);
$content = $this->object->getContent();
}
示例14: testUpdateCanBeAccessed
public function testUpdateCanBeAccessed()
{
$data = array('firstName' => 'Jim', 'lastName' => 'Smith', 'middleInitial' => null, 'address1' => '123 Main St', 'address2' => 'Ste 400', 'city' => 'Pleasantville', 'state' => 'OK', 'zip' => '12345', 'zip4' => '6789', 'email' => 'john.smith@company.com', 'phoneNumber' => '8885551212', 'id' => 1);
$contact = new Contact();
$contact->exchangeArray($data);
$entityManager = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock();
$entityManager->expects($this->once())->method('merge')->with($this->anything())->will($this->returnValue($contact));
$entityManager->expects($this->once())->method('flush');
$entityManager->expects($this->once())->method('find')->with('AddressBook\\Model\\Contact', 1)->will($this->returnValue($contact));
$this->controller->setObjectManager($entityManager);
$this->routeMatch->setParam('id', '1');
$this->request->setMethod('put');
$this->request->setContent(json_encode($data));
$headers = new Headers();
$headers->addHeaderLine('Content-type', 'application/json');
$this->request->setHeaders($headers);
$result = $this->controller->dispatch($this->request);
$response = $this->controller->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('{"data":1}', $result->serialize());
}
示例15: call
/**
* Call an api method
*
* @param $method
* @param $params
* @return mixed
* @throws \Exception
*/
public function call($method, $params)
{
$params['apikey'] = $this->getApiKey();
$params = json_encode($params);
$client = $this->getClient();
$uri = $this->getBaseUri() . $method . '.json';
$headers = new Headers();
$headers->addHeaderLine('Accept-Encoding', 'identity');
$headers->addHeaderLine('Content-Type', 'application/json');
$headers->addHeaderLine('Accept', '*/*');
$request = new Request();
$request->setHeaders($headers);
$request->setUri($uri);
$request->setMethod('POST');
$request->setContent($params);
$response = $client->dispatch($request);
if ($response->isSuccess()) {
return json_decode($response->getContent(), true);
} else {
/*@TODO throw a more useful exception*/
throw new \Exception('Request Failed');
}
}