__toString() public method

The string representation of the Response is the same as the one that will be sent to the client only if the prepare() method has been called before.
See also: prepare()
public __toString ( ) : string
return string The Response as an HTTP string
コード例 #1
0
ファイル: Response.php プロジェクト: rickysu/php-livereload
 public function __toString()
 {
     $this->headers->set('Content-Length', strlen($this->getContent()));
     return parent::__toString();
 }
コード例 #2
0
ファイル: ResponseTest.php プロジェクト: rooster/symfony
 public function testDefaultContentType()
 {
     $headerMock = $this->getMock('Symfony\\Component\\HttpFoundation\\ResponseHeaderBag', array('set'));
     $headerMock->expects($this->at(0))->method('set')->with('Content-Type', 'text/html; charset=UTF-8');
     $headerMock->expects($this->at(1))->method('set')->with('Content-Type', 'text/html; charset=Foo');
     $response = new Response();
     $response->headers = $headerMock;
     // verify first set()
     $response->__toString();
     $response->headers->remove('Content-Type');
     $response->setCharset('Foo');
     // verify second set()
     $response->__toString();
 }
コード例 #3
0
ファイル: ResponseTest.php プロジェクト: nightchiller/symfony
 public function testContentTypeCharset()
 {
     $response = new Response();
     $response->headers->set('Content-Type', 'text/css');
     // force fixContentType() to be called
     $response->__toString();
     $this->assertEquals('text/css; charset=UTF-8', $response->headers->get('Content-Type'));
 }