CustomerData.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class CustomerData extends \Magento\Framework\View\Element\Template
  12. {
  13. /**
  14. * @var array
  15. */
  16. private $expirableSectionNames;
  17. /**
  18. * @param \Magento\Framework\View\Element\Template\Context $context
  19. * @param array $data
  20. * @param array $expirableSectionNames
  21. */
  22. public function __construct(
  23. \Magento\Framework\View\Element\Template\Context $context,
  24. array $data = [],
  25. array $expirableSectionNames = []
  26. ) {
  27. parent::__construct($context, $data);
  28. $this->expirableSectionNames = $expirableSectionNames;
  29. }
  30. /**
  31. * Get CookieLifeTime
  32. * @return null|string scopeCode
  33. */
  34. public function getCookieLifeTime()
  35. {
  36. return $this->_scopeConfig->getValue(
  37. \Magento\Framework\Session\Config::XML_PATH_COOKIE_LIFETIME,
  38. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  39. );
  40. }
  41. /**
  42. * Get url for customer data ajax requests. Returns url with protocol matching used to request page.
  43. *
  44. * @param string $route
  45. * @return string Customer data url.
  46. */
  47. public function getCustomerDataUrl($route)
  48. {
  49. return $this->getUrl($route, ['_secure' => $this->getRequest()->isSecure()]);
  50. }
  51. /**
  52. * Retrieve lifetime period (in minutes) of the frontend section configuration.
  53. *
  54. * Once this period has expired the corresponding section must be invalidated and reloaded.
  55. *
  56. * @return int section lifetime in minutes
  57. * @since 101.0.0
  58. */
  59. public function getExpirableSectionLifetime()
  60. {
  61. return (int)$this->_scopeConfig->getValue('customer/online_customers/section_data_lifetime');
  62. }
  63. /**
  64. * Retrieve the list of sections that can expire.
  65. *
  66. * @return array
  67. * @since 101.0.0
  68. */
  69. public function getExpirableSectionNames()
  70. {
  71. return array_values($this->expirableSectionNames);
  72. }
  73. }