AnalyticsToken.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Model;
  7. use Magento\Framework\App\Config\ReinitableConfigInterface;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\App\Config\Storage\WriterInterface;
  10. /**
  11. * Model for handling Magento BI token value into config.
  12. */
  13. class AnalyticsToken
  14. {
  15. /**
  16. * Path to value of Magento BI token into config.
  17. */
  18. private $tokenPath = 'analytics/general/token';
  19. /**
  20. * Reinitable Config Model.
  21. *
  22. * @var ReinitableConfigInterface
  23. */
  24. private $reinitableConfig;
  25. /**
  26. * Scope config model.
  27. *
  28. * @var ScopeConfigInterface
  29. */
  30. private $config;
  31. /**
  32. * Service which allows to write values into config.
  33. *
  34. * @var WriterInterface
  35. */
  36. private $configWriter;
  37. /**
  38. * @param ReinitableConfigInterface $reinitableConfig
  39. * @param ScopeConfigInterface $config
  40. * @param WriterInterface $configWriter
  41. */
  42. public function __construct(
  43. ReinitableConfigInterface $reinitableConfig,
  44. ScopeConfigInterface $config,
  45. WriterInterface $configWriter
  46. ) {
  47. $this->reinitableConfig = $reinitableConfig;
  48. $this->config = $config;
  49. $this->configWriter = $configWriter;
  50. }
  51. /**
  52. * Get Magento BI token value.
  53. *
  54. * @return string|null
  55. */
  56. public function getToken()
  57. {
  58. return $this->config->getValue($this->tokenPath);
  59. }
  60. /**
  61. * Stores Magento BI token value.
  62. *
  63. * @param string $value
  64. *
  65. * @return bool
  66. */
  67. public function storeToken($value)
  68. {
  69. $this->configWriter->save($this->tokenPath, $value);
  70. $this->reinitableConfig->reinit();
  71. return true;
  72. }
  73. /**
  74. * Check Magento BI token value exist.
  75. *
  76. * @return bool
  77. */
  78. public function isTokenExist()
  79. {
  80. return (bool)$this->getToken();
  81. }
  82. }