DataStore.php 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\Json;
  15. /**
  16. * DataStore
  17. *
  18. * Handles data storage for Data\Filesystem.
  19. */
  20. class DataStore extends AbstractPersistence
  21. {
  22. /**
  23. * store the data
  24. *
  25. * @access public
  26. * @static
  27. * @param string $filename
  28. * @param array $data
  29. * @return bool
  30. */
  31. public static function store($filename, $data)
  32. {
  33. $path = self::getPath();
  34. if (strpos($filename, $path) === 0) {
  35. $filename = substr($filename, strlen($path));
  36. }
  37. try {
  38. self::_store($filename, Json::encode($data));
  39. return true;
  40. } catch (Exception $e) {
  41. return false;
  42. }
  43. }
  44. }