12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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 LuIntDbo extends LuDbo
- {
- /**
- * @var int
- */
- private $_value;
-
- /**
- * @return int
- */
- public function getInt()
- {
- return $this->_value;
- }
-
- /**
- * @param int $value
- */
- public function setInt($value)
- {
- $this->_value = $value;
- }
-
- function jsonSerialize()
- {
- return $this->_value;
- }
-
- public static function jsonDeserialize($json)
- {
- if (!is_numeric($json) || intval($json) != $json) {
- throw new LuDboDeserializeException("Invalid integer value");
- }
- $val = new self();
- $val->setInt(intval($json));
- return $val;
- }
-
- public static function generateSample()
- {
- return 42;
- }
-
- public function between($min, $max)
- {
- if ($this->_value < $min || $this->_value > $max) {
- throw new LuDboConstraintException("Integer must be between ${min} and ${max} inclusive");
- }
- }
-
- public function min($min)
- {
- if ($this->_value < $min) {
- throw new LuDboConstraintException("Integer must be greater or equal than ${min}");
- }
- }
-
- public function max($max)
- {
- if ($this->_value > $max) {
- throw new LuDboConstraintException("Integer must be smaller or equal than ${max}");
- }
- }
-
- }
|