1
0

BxDolKeyQuery.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Database queries for BxDolKey object.
  11. * @see BxDolKey
  12. */
  13. class BxDolKeyQuery extends BxDolDb
  14. {
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. }
  19. public function insert ($sKey, $sData, $iExpire, $sSalt = '')
  20. {
  21. $sQuery = $this->prepare("INSERT INTO `sys_keys` SET `key` = ?, `data` = ?, `expire` = ?, `salt` = ?", $sKey, $sData, time() + $iExpire, $sSalt);
  22. return $this->query($sQuery);
  23. }
  24. public function remove ($sKey)
  25. {
  26. $sQuery = $this->prepare("DELETE FROM `sys_keys` WHERE `key` = ?", $sKey);
  27. return $this->query($sQuery);
  28. }
  29. public function get ($sKey, $sSalt = '')
  30. {
  31. $sWhere = '';
  32. $aBind = ['key' => $sKey];
  33. if ($sSalt) {
  34. $sWhere .= " AND `salt` = :salt ";
  35. $aBind['salt'] = $sSalt;
  36. }
  37. return $this->getOne("SELECT `key` FROM `sys_keys` WHERE `key` = :key" . $sWhere, $aBind);
  38. }
  39. public function getData ($sKey, $sSalt = '')
  40. {
  41. $sWhere = '';
  42. $aBind = ['key' => $sKey];
  43. if ($sSalt) {
  44. $sWhere .= " AND `salt` = :salt ";
  45. $aBind['salt'] = $sSalt;
  46. }
  47. return $this->getOne("SELECT `data` FROM `sys_keys` WHERE `key` = :key" . $sWhere, $aBind);
  48. }
  49. public function prune ()
  50. {
  51. $sQuery = $this->prepare("DELETE FROM `sys_keys` WHERE `expire` < ?", time());
  52. return $this->query($sQuery);
  53. }
  54. }
  55. /** @} */