1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-16 21:08:34 +01:00

added getDataAsHeaders()

This commit is contained in:
maximebf 2013-09-20 13:42:12 -04:00
parent f74037a29d
commit 3c5e8cca50
2 changed files with 23 additions and 4 deletions

View File

@ -233,14 +233,15 @@ class DebugBar implements ArrayAccess
}
return $this->data;
}
/**
* Sends the data through the HTTP headers
* Returns an array of HTTP headers containing the data
*
* @param string $headerName
* @param integer $maxHeaderLength
* @return array
*/
public function sendDataInHeaders($headerName = 'phpdebugbar', $maxHeaderLength = 4096)
public function getDataAsHeaders($headerName = 'phpdebugbar', $maxHeaderLength = 4096)
{
$data = rawurlencode(json_encode(array(
'id' => $this->getCurrentRequestId(),
@ -260,8 +261,19 @@ class DebugBar implements ArrayAccess
$headers[$name] = $chunks[$i];
}
return $headers;
}
/**
* Sends the data through the HTTP headers
*
* @param string $headerName
* @param integer $maxHeaderLength
*/
public function sendDataInHeaders($headerName = 'phpdebugbar', $maxHeaderLength = 4096)
{
$headers = $this->getDataAsHeaders($headerName, $maxHeaderLength);
$this->getHttpDriver()->setHeaders($headers);
return $this;
}

View File

@ -54,6 +54,13 @@ class DebugBarTest extends DebugBarTestCase
$this->assertEquals($s->data[$this->debugbar->getCurrentRequestId()], $data);
}
public function testGetDataAsHeaders()
{
$this->debugbar->addCollector($c = new MockCollector(array('foo')));
$headers = $this->debugbar->getDataAsHeaders();
$this->assertArrayHasKey('phpdebugbar', $headers);
}
public function testSendDataInHeaders()
{
$http = $this->debugbar->getHttpDriver();