You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
893 B

  1. <?php
  2. namespace modl;
  3. class Privacy extends Model {
  4. public $pkey;
  5. public $value;
  6. protected $hash;
  7. public function __construct() {
  8. $this->_struct = '
  9. {
  10. "pkey" :
  11. {"type":"string", "size":128, "mandatory":true, "key":true },
  12. "value" :
  13. {"type":"int", "size":4, "mandatory":true },
  14. "hash" :
  15. {"type":"string", "size":128, "mandatory":true }
  16. }';
  17. parent::__construct();
  18. }
  19. static function set($key, $value) {
  20. $p = new Privacy();
  21. $p->pkey = $key;
  22. $p->value = $value;
  23. $p->hash = md5(openssl_random_pseudo_bytes(5));
  24. $pd = new PrivacyDAO();
  25. $pd->set($p);
  26. }
  27. static function get($key) {
  28. $pd = new PrivacyDAO();
  29. return (int)$pd->get($key)->value;
  30. }
  31. }