123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 5/29/16
- * Time: 2:41 PM
- */
-
- namespace Luticate\Utils\Dbo;
-
-
- use Luticate\Utils\LuBusiness;
- use Luticate\Utils\LuDbo;
-
- class LuStringDbo extends LuDbo
- {
- /**
- * @var $_value string
- */
- private $_value;
-
- /**
- * @return string
- */
- public function getString()
- {
- return $this->_value;
- }
-
- /**
- * @param string $value
- */
- public function setString($value)
- {
- $this->_value = $value;
- }
-
- function jsonSerialize()
- {
- return $this->_value;
- }
-
- public static function jsonDeserialize($json)
- {
- if (is_object($json) || is_array($json) || is_bool($json) || is_null($json)) {
- throw new LuDboDeserializeException("Invalid string value");
- }
- $val = new self();
- $val->setString($json . "");
- return $val;
- }
-
- public static function generateSample()
- {
- return "sample string";
- }
-
- protected function getLength($trim)
- {
- return strlen($trim ? trim($this->_value) : $this->_value);
- }
-
- public function between($min, $max, $trim = true)
- {
- $len = self::getLength($trim);
- if ($len < $min || $len > $max) {
- throw new LuDboConstraintException("String length must be between ${min} and ${max} inclusive");
- }
- }
-
- public function min($min, $trim = true)
- {
- if (self::getLength($trim) < $min) {
- throw new LuDboConstraintException("String length must be greater or equal to ${min}");
- }
- }
-
- public function max($max, $trim = true)
- {
- if (self::getLength($trim) > $max) {
- throw new LuDboConstraintException("String length must be smaller or equal to ${max}");
- }
- }
- }
|