Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Tunnel.php
Go to the documentation of this file.
1 <?php
8 
12 
14 {
18  protected $resultRawFactory;
19 
24  public function __construct(
25  Action\Context $context,
26  Result\RawFactory $resultRawFactory
27  ) {
28  parent::__construct($context);
29  $this->resultRawFactory = $resultRawFactory;
30  }
31 
39  public function execute()
40  {
41  $error = __('invalid request');
42  $httpCode = 400;
43  $gaData = $this->_request->getParam('ga');
44  $gaHash = $this->_request->getParam('h');
46  $resultRaw = $this->resultRawFactory->create();
47  if ($gaData && $gaHash) {
49  $helper = $this->_objectManager->get(\Magento\Backend\Helper\Dashboard\Data::class);
50  $newHash = $helper->getChartDataHash($gaData);
51  if (Security::compareStrings($newHash, $gaHash)) {
52  $params = null;
53  $paramsJson = base64_decode(urldecode($gaData));
54  if ($paramsJson) {
55  $params = json_decode($paramsJson, true);
56  }
57  if ($params) {
58  try {
60  $httpClient = $this->_objectManager->create(\Magento\Framework\HTTP\ZendClient::class);
61  $response = $httpClient->setUri(
62  \Magento\Backend\Block\Dashboard\Graph::API_URL
63  )->setParameterGet(
64  $params
65  )->setConfig(
66  ['timeout' => 5]
67  )->request(
68  'GET'
69  );
70 
71  $headers = $response->getHeaders();
72 
73  $resultRaw->setHeader('Content-type', $headers['Content-type'])
74  ->setContents($response->getBody());
75  return $resultRaw;
76  } catch (\Exception $e) {
77  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
78  $error = __('see error log for details');
79  $httpCode = 503;
80  }
81  }
82  }
83  }
84  $resultRaw->setHeader('Content-Type', 'text/plain; charset=UTF-8')
85  ->setHttpResponseCode($httpCode)
86  ->setContents(__('Service unavailable: %1', $error));
87  return $resultRaw;
88  }
89 }
$response
Definition: 404.php:11
$helper
Definition: iframe.phtml:13
__()
Definition: __.php:13
__construct(Action\Context $context, Result\RawFactory $resultRawFactory)
Definition: Tunnel.php:24
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18