/**
  * @inheritdoc
  */
 public function run(Router $router, \Closure $next)
 {
     $this->validateToken($router);
     $response = $next();
     if (is_string($response)) {
         $response = new Response($response);
     }
     if ($response instanceof ResponseInterface && $response->getStatusCode() === 200) {
         $response->addHeader('X-CSRF-Token', $this->getCSRFToken());
     }
     return $response;
 }
Esempio n. 2
0
 public function run()
 {
     /** @var $error Error */
     $error = Error::getInstance();
     /** @var $request Request */
     $request = Request::getInstance();
     $this->getUserInformation();
     if (!$this->isUserExist()) {
         $error->catchError(Error::USER_NOT_FOUND);
     }
     if (!$this->isAvailablePaymentType()) {
         $error->catchError(Error::INCORRECT_VALUE_PAYMENT_TYPE);
     }
     if (!$this->isCorrectAmount()) {
         $error->catchError(Error::INCORRECT_PAYMENT);
     }
     $this->getReceiptInformation();
     if ($this->isReceiptExist()) {
         if ($this->isCanceled()) {
             $error->catchError(Error::RECEIPT_CANCEL, ['authcode' => $this->_receipt['authcode']]);
         } else {
             $error->catchError(Error::INCORRECT_RECEIPT);
         }
     }
     $this->_provider->savePayment($request);
     $this->_provider->initCallback($request);
     $this->getReceiptInformation();
     Response::getInstance()->giveXML(['authcode' => $this->_receipt['authcode']]);
 }
Esempio n. 3
0
 public function catchError($name, $params = array())
 {
     if (is_numeric($name)) {
         $error_code = $name;
     } else {
         $error_code = constant('self::' . $name);
     }
     $this->currentErrorCode = $error_code;
     if (self::NO_ERRORS != $error_code) {
         //завершаем приложение
         Response::getInstance()->giveXML($params);
     }
 }
Esempio n. 4
0
 public function run()
 {
     /** @var $error Error */
     $error = Error::getInstance();
     $this->getUserInformation();
     if (!$this->isUserExist()) {
         $error->catchError(Error::USER_NOT_FOUND);
     }
     if (!$this->isAvailablePaymentType()) {
         $error->catchError(Error::INCORRECT_VALUE_PAYMENT_TYPE);
     }
     if (!$this->isCorrectAmount()) {
         $error->catchError(Error::INCORRECT_PAYMENT);
     }
     Response::getInstance()->giveXML();
 }
Esempio n. 5
0
 public function run()
 {
     /** @var $error Error */
     $error = Error::getInstance();
     $this->getReceiptInformation();
     if (!$this->isReceiptExist()) {
         $error->catchError(Error::INCORRECT_RECEIPT);
     }
     if (!$this->isCancelAvailable()) {
         $error->catchError(Error::PAYMENT_CAN_NOT_BE_CANCELED);
     }
     if ($this->isCanceled()) {
         $error->catchError(Error::RECEIPT_CANCEL, ['authcode' => $this->_receipt['authcode']]);
     }
     $this->cancelPayment();
     $this->initCallback();
     Response::getInstance()->giveXML(['authcode' => $this->_receipt['authcode']]);
 }
Esempio n. 6
0
 public function run()
 {
     /** @var $error Error */
     $error = Error::getInstance();
     $this->getReceiptInformation();
     if (!$this->isReceiptExist()) {
         $error->catchError(Error::INCORRECT_RECEIPT);
     }
     if (!$this->isStatusExist()) {
         $error->catchError(Error::UNKNOWN_RECEIPT_STATUS);
     }
     if ($this->isCanceled()) {
         $error->catchError(Error::RECEIPT_CANCEL, ['authcode' => $this->_receipt['authcode']]);
     }
     if (!$this->isReceiptPaid()) {
         $error->catchError(Error::NOT_FOUND_SUCCESS_RECEIPT);
     }
     Response::getInstance()->giveXML(['authcode' => $this->_receipt['authcode']]);
 }
 public function logoutAction()
 {
     $this->application->getView()->clearCache();
     Session::destroy();
     setcookie(session_name(), '', time() - 42000, '/');
     $response = new Response();
     $response->setCacheControl('nocache');
     $response->redirect('/');
 }
Esempio n. 8
0
 /**
  * @inheritDoc
  */
 public function run()
 {
     $this->dispatch('core.app.run.pre', $this);
     $this->response = $response = $this->handle($this->getRequest());
     if ($response instanceof View) {
         $this->response = $response = new Response($response->fetch());
     }
     $response->send();
     $this->terminate();
 }
Esempio n. 9
0
 /**
  * @covers \Core\Response\Response::send
  * @runInSeparateProcess
  */
 public function testSendWithContentAsArray()
 {
     $arr = ['test1' => 'val1', 'test2' => 'val2'];
     $response = new Response($arr);
     $response->send();
     $headersList = xdebug_get_headers();
     $statusCode = http_response_code();
     $this->assertEquals(200, $statusCode);
     $this->assertContains('Connection: close', $headersList);
     $this->assertContains('Content-Type: application/json', $headersList);
     $this->assertJson(json_encode($arr), $response->getContent());
     $this->expectOutputString("{\"test1\":\"val1\",\"test2\":\"val2\"}");
 }