State.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Translate\Inline;
  7. class State implements StateInterface
  8. {
  9. /**
  10. * Flag to enable/disable inine translation
  11. *
  12. * @var bool
  13. */
  14. protected $isEnabled = true;
  15. /**
  16. * @var bool
  17. */
  18. protected $storedStatus;
  19. /**
  20. * Disable inline translation
  21. *
  22. * @return void
  23. */
  24. public function disable()
  25. {
  26. $this->isEnabled = false;
  27. }
  28. /**
  29. * Enable inline translation
  30. *
  31. * @return void
  32. */
  33. public function enable()
  34. {
  35. $this->isEnabled = true;
  36. }
  37. /**
  38. * Check if inline translation enabled/disabled
  39. *
  40. * @return bool
  41. */
  42. public function isEnabled()
  43. {
  44. return $this->isEnabled;
  45. }
  46. /**
  47. * Suspend inline translation
  48. *
  49. * Store current inline translation status
  50. * and apply new status or disable inline translation.
  51. *
  52. * @param bool $status
  53. * @return void
  54. */
  55. public function suspend($status = false)
  56. {
  57. if ($this->storedStatus === null) {
  58. $this->storedStatus = $this->isEnabled;
  59. $this->isEnabled = $status;
  60. }
  61. }
  62. /**
  63. * Disable inline translation
  64. *
  65. * Restore inline translation status
  66. * or apply new status.
  67. *
  68. * @param bool $status
  69. * @return void
  70. */
  71. public function resume($status = true)
  72. {
  73. $this->isEnabled = !$status ? $status : $this->storedStatus;
  74. $this->storedStatus = null;
  75. }
  76. }