Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $valid = Arr::contains($value, $this->values);
     return $valid;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $valid = ctype_alpha($value);
     return $valid;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $valid = filter_var($value, FILTER_VALIDATE_FLOAT) !== false;
     return $valid;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $valid = in_array($value, array(0, 1, '0', '1', false, true), true);
     return $valid;
 }
Beispiel #5
0
 /**
  * Caller
  *
  * @param mixed $date Unix timestamp or string, e.g '+ 1 week'
  *
  * @return string
  */
 public function age($date)
 {
     if (Value::isEmpty($date)) {
         return null;
     }
     $date = Value::getDate($date);
     $now = new \DateTime('now');
     $age = $now->diff($date)->y;
     return $age;
 }
Beispiel #6
0
 /**
  * Caller
  *
  * @param string $path
  *
  * @return string
  */
 public function webUrl($path)
 {
     if (Value::isEmpty($path)) {
         return null;
     }
     $url = $this->context->getBaseUrl();
     if (!empty($url)) {
         $url .= '/';
     }
     $url .= 'web/' . $path;
     return $url;
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $value = Value::getString($value);
     if ($value === null) {
         return false;
     }
     $flag = filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
     return $flag;
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $value = Value::getString($value);
     if ($value === null) {
         return false;
     }
     $length = mb_strlen($value);
     $flag = $length >= $this->min && $length <= $this->max;
     return $flag;
 }
Beispiel #9
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return false;
     }
     if (Value::isArray($value)) {
         $flag = !empty($value);
     } else {
         $value = Value::getString($value);
         $flag = !Value::isEmpty($value);
     }
     return $flag;
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function validate($values)
 {
     if (!is_array($values) || count($values) !== 2) {
         return false;
     }
     if (Value::isEmpty($values[0]) && Value::isEmpty($values[1])) {
         return true;
     }
     $left = Value::getDate($values[0]);
     $right = Value::getDate($values[1]);
     $between = new DateBetween($left, $right);
     $flag = $between->validate($this->left) || $between->validate($this->right);
     return $flag;
 }
Beispiel #11
0
 /**
  * Caller
  *
  * @param \DateTime|mixed $value  Unix timestamp or string, e.g '+ 1 week'
  * @param string          $format Date format
  *
  * @return string
  * @throws \InvalidArgumentException
  */
 public function date($value = null, $format = '%Y-%m-%d %H:%M:%S')
 {
     if ($value === null) {
         $value = new \DateTime();
     } else {
         if (Value::isEmpty($value)) {
             return null;
         }
         $value = Value::getDate($value);
         if ($value === null) {
             return null;
         }
     }
     $result = strftime($format, $value->getTimestamp());
     return $result;
 }
Beispiel #12
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $value = Value::getString($value);
     if ($value === null) {
         return false;
     }
     $flag = null;
     if ($this->format === null) {
         $flag = strtotime($value) !== false;
     } else {
         $flag = \DateTime::createFromFormat($this->format, $value) !== false;
     }
     return $flag;
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $value = Value::getDate($value);
     if ($value === null) {
         return false;
     }
     $v = $value->getTimestamp();
     $l = $this->left === null ? -INF : $this->left;
     $r = $this->right === null ? INF : $this->right;
     $flag = null;
     if ($this->edges) {
         $flag = $v - $l >= 0 && $v - $r <= 0 || $v - $l <= 0 && $v - $r >= 0;
     } else {
         $flag = $v - $l > 0 && $v - $r < 0 || $v - $l < 0 && $v - $r > 0;
     }
     return $flag;
 }
Beispiel #14
0
 /**
  * Check whether value is empty
  *
  * @return boolean
  */
 public function isEmpty()
 {
     return Value::isEmpty($this->value);
 }
Beispiel #15
0
 /**
  * Is field contain not empty value
  *
  * @param string $name Field name
  *
  * @return boolean
  */
 public function has($name)
 {
     $value = $this->get($name);
     $has = !Value::isEmpty($value);
     return $has;
 }