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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 LuFloatDbo extends LuDbo
  10. {
  11. /**
  12. * @var float
  13. */
  14. private $_value;
  15. /**
  16. * @return float
  17. */
  18. public function getFloat()
  19. {
  20. return $this->_value;
  21. }
  22. /**
  23. * @param float $value
  24. */
  25. public function setFloat($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)) {
  36. throw new LuDboDeserializeException("Invalid float value");
  37. }
  38. $val = new self();
  39. $val->setFloat(floatval($json));
  40. return $val;
  41. }
  42. public static function generateSample()
  43. {
  44. return 42.42;
  45. }
  46. public function between($min, $max)
  47. {
  48. if ($this->_value < $min || $this->_value > $max) {
  49. throw new LuDboConstraintException("Float must be between ${min} and ${max} inclusive");
  50. }
  51. }
  52. public function min($min)
  53. {
  54. if ($this->_value < $min) {
  55. throw new LuDboConstraintException("Float must be greater or equal to ${min}");
  56. }
  57. }
  58. public function max($max)
  59. {
  60. if ($this->_value > $max) {
  61. throw new LuDboConstraintException("Float must be smaller or equal to ${max}");
  62. }
  63. }
  64. }