Exemplo n.º 1
0
 /**
  * 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'));
 }
 /**
  * @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());
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
 /**
  * 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));
     }
 }
 /**
  * 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));
     }
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * Test for getHeader method. Validation for attempt to get not existing header
  *
  * @covers \Magento\Framework\App\Response\Http::getHeader
  */
 public function testGetHeaderNotExists()
 {
     $this->model->setHeader('Name', 'value', true);
     $this->assertFalse($this->model->getHeader('Wrong name'));
 }
Exemplo n.º 8
0
 /**
  * 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);
     }
 }
Exemplo n.º 9
0
 /**
  * {@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);
     }
 }