123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 2/22/16
- * Time: 9:25 PM
- */
-
- namespace Luticate\Utils\Dbo;
-
-
- use Luticate\Utils\LuBusiness;
- use Luticate\Utils\LuDbo;
-
- class LuFloatDbo extends LuDbo
- {
- /**
- * @var float
- */
- private $_value;
-
- /**
- * @return float
- */
- public function getFloat()
- {
- return $this->_value;
- }
-
- /**
- * @param float $value
- */
- public function setFloat($value)
- {
- $this->_value = $value;
- }
-
- function jsonSerialize()
- {
- return $this->_value;
- }
-
- public static function jsonDeserialize($json)
- {
- if (!is_numeric($json)) {
- throw new LuDboDeserializeException("Invalid float value");
- }
- $val = new self();
- $val->setFloat(floatval($json));
- return $val;
- }
-
- public static function generateSample()
- {
- return 42.42;
- }
-
- public function between($min, $max)
- {
- if ($this->_value < $min || $this->_value > $max) {
- throw new LuDboConstraintException("Float must be between ${min} and ${max} inclusive");
- }
- }
-
- public function min($min)
- {
- if ($this->_value < $min) {
- throw new LuDboConstraintException("Float must be greater or equal to ${min}");
- }
- }
-
- public function max($max)
- {
- if ($this->_value > $max) {
- throw new LuDboConstraintException("Float must be smaller or equal to ${max}");
- }
- }
- }
|