本文整理汇总了PHP中Zend_Controller_Response_Http::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Controller_Response_Http::getHeaders方法的具体用法?PHP Zend_Controller_Response_Http::getHeaders怎么用?PHP Zend_Controller_Response_Http::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Controller_Response_Http
的用法示例。
在下文中一共展示了Zend_Controller_Response_Http::getHeaders方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDisplay
public function testDisplay()
{
$this->_response->expects($this->atLeastOnce())->method('sendHeaders');
$this->_request->expects($this->atLeastOnce())->method('getHeader');
$stat = (include __DIR__ . '/_files/timers.php');
$this->_output->display($stat);
$actualHeaders = $this->_response->getHeaders();
$this->assertNotEmpty($actualHeaders);
$actualProtocol = false;
$actualProfilerData = false;
foreach ($actualHeaders as $oneHeader) {
$headerName = $oneHeader['name'];
$headerValue = $oneHeader['value'];
if (!$actualProtocol && $headerName == 'X-Wf-Protocol-1') {
$actualProtocol = $headerValue;
}
if (!$actualProfilerData && $headerName == 'X-Wf-1-1-1-1') {
$actualProfilerData = $headerValue;
}
}
$this->assertNotEmpty($actualProtocol, 'Cannot get protocol header');
$this->assertNotEmpty($actualProfilerData, 'Cannot get profiler header');
$this->assertContains('Protocol/JsonStream', $actualProtocol);
$this->assertRegExp('/"Type":"TABLE","Label":"Code Profiler \\(Memory usage: real - \\d+, emalloc - \\d+\\)"/', $actualProfilerData);
$this->assertContains('[' . '["Timer Id","Time","Avg","Cnt","Emalloc","RealMem"],' . '["root","0.080000","0.080000","1","1,000","50,000"],' . '[". init","0.040000","0.040000","1","200","2,500"],' . '[". . init_store","0.020000","0.010000","2","100","2,000"],' . '["system","0.030000","0.015000","2","400","20,000"]' . ']', $actualProfilerData);
}
示例2: testPreDispatchNonWhitelistedAction
public function testPreDispatchNonWhitelistedAction()
{
$this->request->setModuleName('default')->setControllerName('foo')->setActionName('home');
$this->plugin->preDispatch($this->request);
$this->assertTrue($this->response->isRedirect());
$responseHeaders = $this->response->getHeaders();
$this->assertEquals('/user/login', $responseHeaders[0]['value']);
}
示例3: _parseLocationHeaderValue
protected function _parseLocationHeaderValue()
{
$headers = $this->response->getHeaders();
foreach ($headers as $header) {
if ('Location' == $header['name']) {
return $header['value'];
}
}
}
示例4: getHeaders
/**
* Returns all headers of type $name.
*
* Example:
*
* $headers = $this->getHeaders('Content-Type');
*
* @param string $name
* @return array(string) All matching header values.
*/
protected function getHeaders($name)
{
$headers = array();
foreach ($this->response->getHeaders() as $headerData) {
/* @var $headerData array */
if ($headerData['name'] === $name) {
$headers[] = $headerData['value'];
}
}
return $headers;
}
示例5: sendResponse
/**
* Send response to browser with json content type
*/
public function sendResponse()
{
$this->_response = Mage::app()->getResponse();
//check redirect
if ($this->_response->isRedirect()) {
$headers = $this->_response->getHeaders();
$redirect = '';
foreach ($headers as $header) {
if ("Location" == $header["name"]) {
$redirect = $header["value"];
break;
}
}
if ($redirect) {
$this->setRedirect($redirect);
}
}
$this->_response->clearHeaders();
$this->_response->setHeader('Content-Type', 'application/json');
$this->_response->clearBody();
$this->_response->setBody($this->toJson());
$this->_response->sendResponse();
exit;
}
示例6: testUseAbsoluteUriSetsFullUriInResponse
public function testUseAbsoluteUriSetsFullUriInResponse()
{
$_SERVER['HTTP_HOST'] = 'foobar.example.com';
$_SERVER['SERVER_PORT'] = '4443';
$_SERVER['HTTPS'] = 1;
$this->redirector->setUseAbsoluteUri(true);
$this->redirector->gotoUrl('/bar/baz');
$headers = $this->response->getHeaders();
$uri = false;
foreach ($headers as $header) {
if ('Location' == $header['name']) {
$uri = $header['value'];
}
}
if (!$uri) {
$this->fail('No redirect header set in response');
}
$this->assertEquals('https://foobar.example.com:4443/bar/baz', $uri);
}
示例7: run
/**
* Runs the request, handling from routing straight through to response output.
* Primary method to be used by the external API.
*
* @return string|null Returns a string if {@link $_sendResponse} is false
*/
public function run()
{
ob_start();
XenForo_Application::set('fc', $this);
$this->setup();
$this->setRequestPaths();
$showDebugOutput = $this->showDebugOutput();
$this->_dependencies->preLoadData();
XenForo_CodeEvent::fire('front_controller_pre_route', array($this));
$routeMatch = $this->route();
XenForo_CodeEvent::fire('front_controller_pre_dispatch', array($this, &$routeMatch));
$controllerResponse = $this->dispatch($routeMatch);
if (!$controllerResponse) {
XenForo_Error::noControllerResponse($routeMatch, $this->_request);
exit;
}
$viewRenderer = $this->_getViewRenderer($routeMatch->getResponseType());
if (!$viewRenderer) {
// note: should only happen if there's an error getting the default renderer, which should never happen :)
XenForo_Error::noViewRenderer($this->_request);
exit;
}
$containerParams = array('majorSection' => $routeMatch->getMajorSection(), 'minorSection' => $routeMatch->getMinorSection());
XenForo_CodeEvent::fire('front_controller_pre_view', array($this, &$controllerResponse, &$viewRenderer, &$containerParams));
$content = $this->renderView($controllerResponse, $viewRenderer, $containerParams);
if ($showDebugOutput) {
$content = $this->renderDebugOutput($content);
}
$bufferedContents = ob_get_contents();
ob_end_clean();
if ($bufferedContents !== '' && is_string($content)) {
if (preg_match('#<body[^>]*>#sU', $content, $match)) {
$content = str_replace($match[0], $match[0] . $bufferedContents, $content);
} else {
$content = $bufferedContents . $content;
}
}
XenForo_CodeEvent::fire('front_controller_post_view', array($this, &$content));
if ($this->_sendResponse) {
$headers = $this->_response->getHeaders();
$isText = false;
foreach ($headers as $header) {
if ($header['name'] == 'Content-Type') {
if (strpos($header['value'], 'text/') === 0) {
$isText = true;
}
break;
}
}
if ($isText && is_string($content) && $content) {
$extraHeaders = XenForo_Application::gzipContentIfSupported($content);
foreach ($extraHeaders as $extraHeader) {
$this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]);
}
}
if (is_string($content) && $content && !ob_get_level() && XenForo_Application::get('config')->enableContentLength) {
if ($this->_response->getHttpResponseCode() >= 400 && strpos($this->_request->getServer('HTTP_USER_AGENT', ''), 'IEMobile') !== false) {
// Windows mobile bug - 400+ errors cause the standard browser error
// to be output if a content length is sent. ...Err, what?
} else {
$this->_response->setHeader('Content-Length', strlen($content), true);
}
}
$this->_response->sendHeaders();
if ($content instanceof XenForo_FileOutput) {
$content->output();
} else {
echo $content;
}
} else {
return $content;
}
}
示例8: run
public function run(Zend_Controller_Response_Abstract $response = null)
{
$args = array($this);
$this->runCallback(self::CB_BEFORE_RUN, $args);
if ($response === null) {
$response = new Zend_Controller_Response_Http();
}
$this->response = $response;
$action = $this->getCurrentAction();
$this->request->setActionName($action);
ob_start();
$this->actionRun($action);
if ($this->response->isRedirect() && $this->completeRequest->isXmlHttpRequest()) {
$url = null;
foreach ($response->getHeaders() as $header) {
if ($header['name'] == 'Location') {
$url = $header['value'];
}
}
$code = $response->getHttpResponseCode();
// change request to ajax response
$response->clearAllHeaders();
$response->clearBody();
$response->setHttpResponseCode(200);
$response->setHeader("Content-Type", "application/json; charset=UTF-8", true);
$response->setBody(Am_Controller::getJson(array('ngrid-redirect' => $url, 'status' => $code)));
//throw new Am_Exception_Redirect($url);
} else {
$response->appendBody(ob_get_clean());
}
unset($this->response);
return $response;
}
示例9: run
/**
* Runs the request, handling from routing straight through to response output.
* Primary method to be used by the external API.
*
* @return string|null Returns a string if {@link $_sendResponse} is false
*/
public function run($innerContent = "", $newParams = array())
{
ob_start();
$this->setup();
$this->setRequestPaths();
$showDebugOutput = $this->showDebugOutput();
$this->_dependencies->preLoadData();
XenForo_CodeEvent::fire('front_controller_pre_route', array($this));
$routeMatch = $this->route();
XenForo_CodeEvent::fire('front_controller_pre_dispatch', array($this, &$routeMatch));
$controllerResponse = $this->dispatch($routeMatch);
if (!$controllerResponse) {
XenForo_Error::noControllerResponse($routeMatch, $this->_request);
exit;
}
$viewRenderer = $this->_getViewRenderer($routeMatch->getResponseType());
if (!$viewRenderer) {
// note: should only happen if there's an error getting the default renderer, which should never happen :)
XenForo_Error::noViewRenderer($this->_request);
exit;
}
$containerParams = array('majorSection' => $routeMatch->getMajorSection(), 'minorSection' => $routeMatch->getMinorSection());
XenForo_CodeEvent::fire('front_controller_pre_view', array($this, &$controllerResponse, &$viewRenderer, &$containerParams));
$content = $this->renderView($controllerResponse, $viewRenderer, $containerParams, $innerContent, $newParams);
if ($showDebugOutput) {
$content = $this->renderDebugOutput($content);
}
$bufferedContents = ob_get_contents();
ob_end_clean();
if ($bufferedContents !== '') {
$content = $bufferedContents . $content;
}
XenForo_CodeEvent::fire('front_controller_post_view', array($this, &$content));
if ($this->_sendResponse) {
$headers = $this->_response->getHeaders();
$isText = false;
foreach ($headers as $header) {
if ($header['name'] == 'Content-Type') {
if (strpos($header['value'], 'text/') === 0) {
$isText = true;
}
break;
}
}
if ($isText && is_string($content) && $content) {
$extraHeaders = XenForo_Application::gzipContentIfSupported($content);
foreach ($extraHeaders as $extraHeader) {
$this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]);
}
}
if (is_string($content) && $content && !ob_get_level() && XenForo_Application::get('config')->enableContentLength) {
$this->_response->setHeader('Content-Length', strlen($content), true);
}
$this->_response->sendHeaders();
if ($content instanceof XenForo_FileOutput) {
$content->output();
} else {
//$uncompressed = gzuncompress($content);
//echo $uncompressed;
echo $content;
}
} else {
return $content;
}
}
示例10: processResponse
/**
* Process response body by specific request
*
* @param Zend_Controller_Response_Http $response response
* @param Zend_Controller_Request_Http $request request
*
* @return Smile_MageCache_Model_Engine_Default
*/
public function processResponse(Zend_Controller_Response_Http $response, Zend_Controller_Request_Http $request)
{
/*
* Check request and response.
* Note: Deal only with 200 for the moment
*/
if ($this->canProcessRequest($request) && $response->getHttpResponseCode() == 200) {
$cacheId = $this->getRequestCacheId();
$content = $response->getBody();
if (function_exists('gzcompress')) {
$content = gzcompress($content);
}
$res = $this->_adapter->save($content, $cacheId, $this->getRequestTags());
$this->setMetadata('response_headers', $response->getHeaders());
$this->_saveMetadata();
}
return $this;
}