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


PHP Headers::fromString方法代码示例

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


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

示例1: pharAction

 public function pharAction()
 {
     $client = $this->serviceLocator->get('zendServerClient');
     $client = new Client();
     if (defined('PHAR')) {
         // the file from which the application was started is the phar file to replace
         $file = $_SERVER['SCRIPT_FILENAME'];
     } else {
         $file = dirname($_SERVER['SCRIPT_FILENAME']) . '/zs-client.phar';
     }
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setHeaders(Headers::fromString('If-Modified-Since: ' . gmdate('D, d M Y H:i:s T', filemtime($file))));
     $request->setUri('https://github.com/zendtech/ZendServerSDK/raw/master/bin/zs-client.phar');
     //$client->getAdapter()->setOptions(array('sslcapath' => __DIR__.'/../../../certs/'));
     $client->setAdapter(new Curl());
     $response = $client->send($request);
     if ($response->getStatusCode() == 304) {
         return 'Already up-to-date.';
     } else {
         ErrorHandler::start();
         rename($file, $file . '.' . date('YmdHi') . '.backup');
         $handler = fopen($file, 'w');
         fwrite($handler, $response->getBody());
         fclose($handler);
         ErrorHandler::stop(true);
         return 'The phar file was updated successfully.';
     }
 }
开发者ID:alexb-uk,项目名称:ZendServerSDK,代码行数:29,代码来源:UpdateController.php

示例2: getHeaders

 /**
  * Return the header container responsible for headers
  *
  * @return Headers
  */
 public function getHeaders()
 {
     if ($this->headers === null || is_string($this->headers)) {
         // this is only here for fromString lazy loading
         $this->headers = is_string($this->headers) ? Headers::fromString($this->headers) : new Headers();
     }
     return $this->headers;
 }
开发者ID:idwsdta,项目名称:INIT-frame,代码行数:13,代码来源:AbstractMessage.php

示例3: testWrongContentTypeThrowsInvalidResponseException

 public function testWrongContentTypeThrowsInvalidResponseException()
 {
     $this->setExpectedException('Magium\\Mail\\Api\\InvalidResponseException');
     $builder = $this->getMockBuilder('Zend\\Http\\Client')->setMethods(['send']);
     $client = $builder->getMock();
     /* @var $client \Zend\Http\Client */
     $response = new Response();
     $response->setContent(json_encode(['error' => 'error message']));
     $response->setHeaders(Headers::fromString('Content-Type: wrong'));
     $client->expects($this->once())->method('send')->willReturn($response);
     $generator = new Generator(new Configuration(), $client, 'abcd');
     $generator->generate();
 }
开发者ID:magium,项目名称:MagiumMail,代码行数:13,代码来源:ErrorTest.php

示例4: testHeadersFromStringFactoryCreatesMultipleObjects

 public function testHeadersFromStringFactoryCreatesMultipleObjects()
 {
     $headers = Headers::fromString("Fake: foo-bar\r\nAnother-Fake: boo-baz");
     $this->assertEquals(2, $headers->count());
     $header = $headers->get('fake');
     $this->assertInstanceOf('Zend\\Http\\Header\\GenericHeader', $header);
     $this->assertEquals('Fake', $header->getFieldName());
     $this->assertEquals('foo-bar', $header->getFieldValue());
     $header = $headers->get('anotherfake');
     $this->assertInstanceOf('Zend\\Http\\Header\\GenericHeader', $header);
     $this->assertEquals('Another-Fake', $header->getFieldName());
     $this->assertEquals('boo-baz', $header->getFieldValue());
 }
开发者ID:JojoBombardo,项目名称:zf2,代码行数:13,代码来源:HeadersTest.php

示例5: testFromHeaderMethod

 public function testFromHeaderMethod()
 {
     $headers = "X-Test-Header-1: Header1Value\r\n" . "X-Test-Header-2: Header2Value\r\n";
     $r = new Request();
     $r->setHeaders(\Zend\Http\Headers::fromString($headers));
     $e = new MvcEvent();
     $e->setRequest($r);
     $helper = new Helper($e);
     $header = $helper->fromHeader('X-Test-Header-1');
     $this->assertInstanceOf('\\Zend\\Http\\Header\\GenericHeader', $header);
     $this->assertEquals('Header1Value', $header->getFieldValue());
     $expect = array('X-Test-Header-1' => 'Header1Value', 'X-Test-Header-2' => 'Header2Value');
     $this->assertEquals($expect, $helper->fromHeader());
     $this->assertEquals('default', $helper->fromHeader('X-Not-Here', 'default'));
 }
开发者ID:bitrecruiter,项目名称:CrossApplicantManager,代码行数:15,代码来源:ParamsTest.php

示例6: testUrlIsRight

 public function testUrlIsRight()
 {
     $builder = $this->getMockBuilder('Zend\\Http\\Client')->setMethods(['send']);
     $client = $builder->getMock();
     /* @var $client \Zend\Http\Client */
     $response = new Response();
     $response->setContent(json_encode(['email' => 'test@example.com']));
     $response->setHeaders(Headers::fromString('Content-Type: application/json'));
     $client->expects($this->once())->method('send')->willReturn($response);
     $configuration = new Configuration();
     $generator = new Generator($configuration, $client, 'abcd');
     $email = $generator->generate();
     self::assertEquals('test@example.com', $email);
     self::assertEquals($configuration->getApiEndpointUrl(), $client->getUri()->toString());
 }
开发者ID:magium,项目名称:MagiumMail,代码行数:15,代码来源:SuccessTest.php

示例7: testSendHeadersSendsStatusLast

 /**
  * @runInSeparateProcess
  */
 public function testSendHeadersSendsStatusLast()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('Xdebug extension needed, skipped test');
     }
     $mockResponse = $this->getMock('Zend\\Http\\Response');
     $mockResponse->expects($this->once())->method('getHeaders')->will($this->returnValue(Headers::fromString('Location: example.com')));
     $mockResponse->expects($this->once())->method('renderStatusLine')->will($this->returnValue('X-Test: HTTP/1.1 202 Accepted'));
     $mockSendResponseEvent = $this->getMock('Zend\\Mvc\\ResponseSender\\SendResponseEvent', array('getResponse'));
     $mockSendResponseEvent->expects($this->any())->method('getResponse')->will($this->returnValue($mockResponse));
     $responseSender = $this->getMockForAbstractClass('Zend\\Mvc\\ResponseSender\\AbstractResponseSender');
     $responseSender->sendHeaders($mockSendResponseEvent);
     $sentHeaders = xdebug_get_headers();
     $this->assertCount(2, $sentHeaders);
     $this->assertEquals('Location: example.com', $sentHeaders[0]);
     $this->assertEquals('X-Test: HTTP/1.1 202 Accepted', $sentHeaders[1], 'Status header is sent last to prevent header() from overwriting the ZF status code when a Location header is used');
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:20,代码来源:AbstractResponseSenderTest.php

示例8: getHeaders

 /**
  * Return the header container responsible for headers or all headers of a certain name/type
  *
  * @see \Zend\Http\Headers::get()
  * @param string|null           $name            Header name to retrieve, or null to get the whole container.
  * @param mixed|null            $default         Default value to use when the requested header is missing.
  * @return \Zend\Http\Headers|bool|\Zend\Http\Header\HeaderInterface|\ArrayIterator
  */
 public function getHeaders($name = null, $default = false)
 {
     if ($this->headers === null || is_string($this->headers)) {
         // this is only here for fromString lazy loading
         $this->headers = is_string($this->headers) ? Headers::fromString($this->headers) : new Headers();
     }
     if ($name === null) {
         return $this->headers;
     }
     if ($this->headers->has($name)) {
         return $this->headers->get($name);
     }
     return $default;
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:22,代码来源:Request.php

示例9: getHeaders

 /**
  * Get response headers
  *
  * @return Headers
  */
 public function getHeaders()
 {
     if ($this->headers === null || is_string($this->headers)) {
         $this->headers = is_string($this->headers) ? Headers::fromString($this->headers) : new Headers();
     }
     return $this->headers;
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:12,代码来源:Response.php

示例10: downloadAction

 /**
  * Download a processed document
  */
 public function downloadAction()
 {
     $documentId = (int) $this->params()->fromRoute('id');
     $user = $this->identity();
     if (!($document = $this->documentDAO->find($documentId)) or $document->job->user->id != $user->id and !$user->isAdministrator()) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $response = $this->getEvent()->getResponse();
     $response->setHeaders(Headers::fromString("Content-Type: {$document->mimeType}\r\n" . "Content-Length: {$document->size}\r\n" . "Content-Disposition: attachment; filename=\"{$document->getFileName()}\""));
     $response->setContent(file_get_contents($document->path));
     return $response;
 }
开发者ID:anukat2015,项目名称:xmlps,代码行数:16,代码来源:ManagerController.php

示例11: testZeroIsAValidHeaderValue

 public function testZeroIsAValidHeaderValue()
 {
     $headers = Headers::fromString('Fake: 0');
     $this->assertSame('0', $headers->get('Fake')->getFieldValue());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:5,代码来源:HeadersTest.php

示例12: getHeaders

 /**
  * Get headers for caching file and type
  * 
  * @param string $mime File mimetype
  * @return \Zend\Http\Headers
  */
 protected function getHeaders($file, $mime)
 {
     $cache_days = 20;
     $info = new \SplFileInfo($file);
     $filetime = $info->getMTime();
     unset($info);
     $last_modified = date('D, d M Y H:i:s', $filetime) . ' GMT';
     $expires = date('D, d M Y H:i:s', strtotime('+30 days', $filetime)) . ' GMT';
     $hasid = md5($last_modified);
     $headers = "Cache-Control: max-age=" . $cache_days * 24 * 60 * 60 . "\r\n" . "Pragma: private\r\n" . "Last-Modified: " . $last_modified . "\r\n" . "Expires: " . $expires . "\r\n" . "Vary: Accept-Encoding\r\n" . "Etag: " . $hasid . "\r\n" . "Content-Type: " . $mime . "\r\n";
     return Headers::fromString($headers);
 }
开发者ID:robertdamoc,项目名称:zf2-module-assets,代码行数:18,代码来源:AssetsManager.php


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