本文整理汇总了PHP中Magento\Framework\App\Response\Http::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::setHeader方法的具体用法?PHP Http::setHeader怎么用?PHP Http::setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\Response\Http
的用法示例。
在下文中一共展示了Http::setHeader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRepresentJson
/**
* Test setting body in JSON format
*/
public function testRepresentJson()
{
$this->model->setHeader('Content-Type', 'text/javascript');
$this->model->representJson('json_string');
$this->assertEquals('application/json', $this->model->getHeader('Content-Type')->getFieldValue());
$this->assertEquals('json_string', $this->model->getBody('default'));
}
示例2: beforeSendResponse
/**
* @param \Magento\Framework\App\Response\Http $subject
* @return void
* @codeCoverageIgnore
*/
public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject)
{
foreach ($this->headerProviders as $provider) {
if ($provider->canApply()) {
$subject->setHeader($provider->getName(), $provider->getValue());
}
}
}
示例3: handleDeveloperMode
/**
* Error handler for developer mode
*
* @param Bootstrap $bootstrap
* @param \Exception $exception
* @return bool
*/
private function handleDeveloperMode(Bootstrap $bootstrap, \Exception $exception)
{
if ($bootstrap->isDeveloperMode()) {
$this->_response->setHttpResponseCode(500);
$this->_response->setHeader('Content-Type', 'text/plain');
$this->_response->setBody($exception->getMessage() . "\n" . $exception->getTraceAsString());
$this->_response->sendResponse();
return true;
}
return false;
}
示例4: execute
/**
* Execute method.
*/
public function execute()
{
$attribute = $this->getRequest()->getParam('attribute');
$conditionName = $this->getRequest()->getParam('condition');
$valueName = $this->getRequest()->getParam('value');
if ($attribute && $conditionName && $valueName) {
$type = $this->ruleType->getInputType($attribute);
$conditionOptions = $this->ruleCondition->getInputTypeOptions($type);
$response['condition'] = $this->_getOptionHtml('conditions', $conditionName, $conditionOptions);
$elmType = $this->ruleValue->getValueElementType($attribute);
if ($elmType == 'select') {
$valueOptions = $this->ruleValue->getValueSelectOptions($attribute);
$response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions);
} elseif ($elmType == 'text') {
$html = "<input style='width:160px' title='cvalue' class='' id='' name={$valueName} />";
$response['cvalue'] = $html;
}
$this->http->getHeaders()->clearHeaders();
$this->http->setHeader('Content-Type', 'application/json')->setBody($this->jsonEncoder->encode($response));
}
}
示例5: execute
/**
* Execute method.
*
* @return $this
*/
public function execute()
{
$id = $this->getRequest()->getParam('ruleid');
$attribute = $this->getRequest()->getParam('attribute');
$arrayKey = $this->getRequest()->getParam('arraykey');
$conditionName = $this->getRequest()->getParam('condition');
$valueName = $this->getRequest()->getParam('value');
if ($arrayKey && $id && $attribute && $conditionName && $valueName) {
$rule = $this->rulesFactory->create()->load($id);
//rule not found
if (!$rule->getId()) {
$this->http->getHeaders()->clearHeaders();
return $this->http->setHeader('Content-Type', 'application/json')->setBody('Rule not found!');
}
$conditions = $rule->getCondition();
$condition = $conditions[$arrayKey];
$selectedConditions = $condition['conditions'];
$selectedValues = $condition['cvalue'];
$type = $this->ruleType->getInputType($attribute);
$conditionOptions = $this->ruleCondition->getInputTypeOptions($type);
$response['condition'] = str_replace('value="' . $selectedConditions . '"', 'value="' . $selectedConditions . '"' . 'selected="selected"', $this->getOptionHtml('conditions', $conditionName, $conditionOptions));
$elmType = $this->ruleValue->getValueElementType($attribute);
if ($elmType == 'select' or $selectedConditions == 'null') {
$isEmpty = false;
if ($selectedConditions == 'null') {
$isEmpty = true;
}
$valueOptions = $this->ruleValue->getValueSelectOptions($attribute, $isEmpty);
$response['cvalue'] = str_replace('value="' . $selectedValues . '"', 'value="' . $selectedValues . '"' . 'selected="selected"', $this->getOptionHtml('cvalue', $valueName, $valueOptions));
} elseif ($elmType == 'text') {
$html = "<input style='width:160px' title='cvalue' name='{$valueName}' value='{$selectedValues}'/>";
$response['cvalue'] = $html;
}
$this->http->getHeaders()->clearHeaders();
$this->http->setHeader('Content-Type', 'application/json')->setBody($this->jsonEncoder->encode($response));
}
}
示例6: handleDeveloperMode
/**
* Error handler for developer mode
*
* @param Bootstrap $bootstrap
* @param \Exception $exception
* @return bool
*/
private function handleDeveloperMode(Bootstrap $bootstrap, \Exception $exception)
{
if ($bootstrap->isDeveloperMode()) {
if (Bootstrap::ERR_IS_INSTALLED == $bootstrap->getErrorCode()) {
try {
$this->redirectToSetup($bootstrap, $exception);
return true;
} catch (\Exception $e) {
$exception = $e;
}
}
$this->_response->setHttpResponseCode(500);
$this->_response->setHeader('Content-Type', 'text/plain');
$this->_response->setBody($this->buildContentFromException($exception));
$this->_response->sendResponse();
return true;
}
return false;
}
示例7: addDebugHeader
/**
* Add additional header for debug purpose
*
* @param ResponseHttp $response
* @param string $name
* @param string $value
* @param bool $replace
* @return void
*/
protected function addDebugHeader(ResponseHttp $response, $name, $value, $replace = false)
{
if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
$response->setHeader($name, $value, $replace);
}
}
示例8: setHeader
/**
* {@inheritdoc}
*/
public function setHeader($name, $value, $replace = false)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'setHeader');
if (!$pluginInfo) {
return parent::setHeader($name, $value, $replace);
} else {
return $this->___callPlugins('setHeader', func_get_args(), $pluginInfo);
}
}