Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function afterAction($action, $result)
 {
     $result = parent::afterAction($action, $result);
     $result = $this->serializeData($result);
     if (!isset($result['code'])) {
         return ApiHelper::successResponse($result);
     }
     return $result;
 }
Esempio n. 2
0
 public function afterAction($action, $result)
 {
     $result = parent::afterAction($action, $result);
     $token_info = Yii::$app->getResponse()->content;
     if (!is_null($token_info)) {
         $result += Yii::$app->getResponse()->content;
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  * Fix Yii2 Bug #5665: The `currentPage` meta data in the RESTful result should be 1-based, similar to that in HTTP headers
  * There is a similar fix in backend\components\Controller.php
  */
 public function afterAction($action, $result)
 {
     $result = parent::afterAction($action, $result);
     $pageFixActions = ['member'];
     if (('index' === $action->id || in_array($action->id, $pageFixActions)) && isset($result['_meta']['currentPage'])) {
         $result['_meta']['currentPage']++;
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Returns an open renderer stream that outputs formatted items from the dataProvider.
  * @param Action $action the action just executed.
  * @param mixed $result  the action return result.
  * @param array $params params extracted from result
  * @return Response
  * @throws Exception when failed to register the renderer stream class
  * @throws \HttpInvalidParamException
  */
 protected function getLargeResponse($action, $result, $params)
 {
     parent::afterAction($action, $result);
     $format = Yii::$app->response->format;
     /** @var stream\RendererStream $rendererClass */
     switch ($format) {
         case Response::FORMAT_CSV:
             $rendererClass = 'netis\\utils\\crud\\stream\\CsvRendererStream';
             break;
         case Response::FORMAT_JSON:
             $rendererClass = 'netis\\utils\\crud\\stream\\JsonRendererStream';
             break;
         case Response::FORMAT_XML:
             $rendererClass = 'netis\\utils\\crud\\stream\\XmlRendererStream';
             break;
         case Response::FORMAT_XLS:
             $rendererClass = 'netis\\utils\\crud\\stream\\XlsRendererStream';
             break;
         default:
             throw new \HttpInvalidParamException('Unsupported format requested: ' . $format);
     }
     $streamName = $format . 'View';
     if (!stream_wrapper_register($streamName, $rendererClass)) {
         throw new Exception('Failed to register the RenderStream wrapper.');
     }
     $rendererClass::$params = $params;
     $response = new \yii\web\Response();
     $response->setDownloadHeaders($action->id . '.' . $format, Yii::$app->response->acceptMimeType);
     $response->format = Response::FORMAT_RAW;
     $streamParams = ['format' => $format, 'serializer' => $this->serializer];
     $response->stream = fopen("{$streamName}://{$action->id}?" . \http_build_query($streamParams), "r");
     return $response;
 }
 public function afterAction($action, $result)
 {
     $result = parent::afterAction($action, $result);
     if (Yii::$app->response->format == \yii\web\Response::FORMAT_JSONP) {
         if (isset($_GET['callback'])) {
             $result = array('callback' => $_GET['callback'], 'data' => $result);
         }
     }
     /*
      * CORS requires some headers in order for the requests to work. 
      * These are current working headers for the app.
      * 
      * We may want to move this to a better location, or maybe change 
      * the entire Header-logic.
      */
     Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Credentials', 'true');
     Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', Yii::$app->request->getHeaders()->get('Origin'));
     Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Headers', 'Authorization');
     $headers = implode(',', array_keys(Yii::$app->response->getHeaders()->toArray()));
     Yii::$app->getResponse()->getHeaders()->set('Access-Control-Expose-Headers', $headers);
     return $result;
 }
Esempio n. 6
0
 public function afterAction($action, $result)
 {
     if (!$this->handleAfterActionEvent($action, $result)) {
         $msg = "Failed to do after action, action: " . $action->id . ' class is: ' . $this::className();
         throw new \Exception($msg);
     }
     return parent::afterAction($action, $result);
 }