Render.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\PageCache\Controller\Block;
  8. class Render extends \Magento\PageCache\Controller\Block
  9. {
  10. /**
  11. * Returns block content depends on ajax request
  12. *
  13. * @return void
  14. */
  15. public function execute()
  16. {
  17. if (!$this->getRequest()->isAjax()) {
  18. $this->_forward('noroute');
  19. return;
  20. }
  21. // disable profiling during private content handling AJAX call
  22. \Magento\Framework\Profiler::reset();
  23. $currentRoute = $this->getRequest()->getRouteName();
  24. $currentControllerName = $this->getRequest()->getControllerName();
  25. $currentActionName = $this->getRequest()->getActionName();
  26. $currentRequestUri = $this->getRequest()->getRequestUri();
  27. $origRequest = $this->getRequest()->getParam('originalRequest');
  28. if ($origRequest && is_string($origRequest)) {
  29. $origRequest = json_decode($origRequest, true);
  30. }
  31. $this->getRequest()->setRouteName($origRequest['route']);
  32. $this->getRequest()->setControllerName($origRequest['controller']);
  33. $this->getRequest()->setActionName($origRequest['action']);
  34. $this->getRequest()->setRequestUri($origRequest['uri']);
  35. /** @var \Magento\Framework\View\Element\BlockInterface[] $blocks */
  36. $blocks = $this->_getBlocks();
  37. $data = [];
  38. foreach ($blocks as $blockName => $blockInstance) {
  39. $data[$blockName] = $blockInstance->toHtml();
  40. }
  41. $this->getRequest()->setRouteName($currentRoute);
  42. $this->getRequest()->setControllerName($currentControllerName);
  43. $this->getRequest()->setActionName($currentActionName);
  44. $this->getRequest()->setRequestUri($currentRequestUri);
  45. $this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE);
  46. $this->translateInline->processResponseBody($data);
  47. $this->getResponse()->appendBody(json_encode($data));
  48. }
  49. }