Writer.php 836 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * Copyright © 2013-2017 Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Update\Queue;
  7. class Writer extends Reader
  8. {
  9. /**
  10. * Write JSON string to job queue
  11. *
  12. * @param string $data
  13. * @return bool|int
  14. * @throw \RuntimeException
  15. */
  16. public function write($data)
  17. {
  18. if (file_exists($this->queueFilePath)) {
  19. // empty string is used to clear the job queue
  20. if ($data != '') {
  21. json_decode($data);
  22. if (json_last_error() !== JSON_ERROR_NONE) {
  23. throw new \RuntimeException(sprintf('Content to write must be a valid JSON.'));
  24. }
  25. }
  26. return file_put_contents($this->queueFilePath, $data);
  27. }
  28. return false;
  29. }
  30. }