DataStore.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * PrivateBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link https://github.com/PrivateBin/PrivateBin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. * @version 1.1
  11. */
  12. namespace PrivateBin\Persistence;
  13. use Exception;
  14. use PrivateBin\Configuration;
  15. use PrivateBin\Json;
  16. /**
  17. * DataStore
  18. *
  19. * Handles data storage for Data\Filesystem.
  20. */
  21. class DataStore extends AbstractPersistence
  22. {
  23. /**
  24. * store the data
  25. *
  26. * @access public
  27. * @static
  28. * @param string $filename
  29. * @param string $data
  30. * @return bool
  31. */
  32. public static function store($filename, $data)
  33. {
  34. $path = self::getPath();
  35. if (strpos($filename, $path) === 0) {
  36. $filename = substr($filename, strlen($path));
  37. }
  38. try {
  39. self::_store($filename, Json::encode($data));
  40. return true;
  41. } catch (Exception $e) {
  42. return false;
  43. }
  44. }
  45. }