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.

LuIntDbo.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 2/22/16
  6. * Time: 9:25 PM
  7. */
  8. namespace Luticate\Utils\Dbo;
  9. class LuIntDbo extends LuDbo
  10. {
  11. /**
  12. * @var int
  13. */
  14. private $_value;
  15. /**
  16. * @return int
  17. */
  18. public function getInt()
  19. {
  20. return $this->_value;
  21. }
  22. /**
  23. * @param int $value
  24. */
  25. public function setInt($value)
  26. {
  27. $this->_value = $value;
  28. }
  29. function jsonSerialize()
  30. {
  31. return $this->_value;
  32. }
  33. public static function jsonDeserialize($json)
  34. {
  35. if (!is_numeric($json) || intval($json) != $json) {
  36. throw new LuDboDeserializeException("Invalid integer value");
  37. }
  38. $val = new self();
  39. $val->setInt(intval($json));
  40. return $val;
  41. }
  42. public static function generateSample()
  43. {
  44. return 42;
  45. }
  46. public function between($min, $max)
  47. {
  48. if ($this->_value < $min || $this->_value > $max) {
  49. throw new LuDboConstraintException("Integer must be between ${min} and ${max} inclusive");
  50. }
  51. }
  52. public function min($min)
  53. {
  54. if ($this->_value < $min) {
  55. throw new LuDboConstraintException("Integer must be greater or equal to ${min}");
  56. }
  57. }
  58. public function max($max)
  59. {
  60. if ($this->_value > $max) {
  61. throw new LuDboConstraintException("Integer must be smaller or equal to ${max}");
  62. }
  63. }
  64. }