Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $valid = ctype_alpha($value);
     return $valid;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $valid = filter_var($value, FILTER_VALIDATE_FLOAT) !== false;
     return $valid;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function validate($value)
 {
     if (Value::isEmpty($value)) {
         return true;
     }
     $valid = Arr::contains($value, $this->values);
     return $valid;
 }
Esempio n. 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;
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function setValue($value)
 {
     if ($value === null) {
         $value = array();
     } elseif (!Value::isArray($value)) {
         throw new InvalidArgumentException(sprintf("Field set value has invalid type: '%s'", gettype($value)));
     }
     return parent::setValue($value);
 }
Esempio n. 6
0
 /**
  * Caller
  *
  * @param mixed $value Data
  *
  * @return mixed
  */
 public function trim($value)
 {
     $value = Value::getString($value);
     if ($value === null) {
         return null;
     }
     $value = trim($value);
     return $value;
 }
Esempio n. 7
0
 /**
  * Caller
  *
  * @param string     $name   Route name
  * @param null|array $params Route params
  *
  * @return string|null
  */
 public function routeUrl($name = null, $params = array())
 {
     $name = Value::getString($name);
     if ($name === null) {
         return null;
     }
     $url = $this->getView()->getApp()->getRouter()->assemble($name, (array) $params);
     return $url;
 }
Esempio n. 8
0
 /**
  * Caller
  *
  * @param string $search  Search
  * @param string $replace Replace
  * @param string $value   Subject
  *
  * @return string
  */
 public function replace($value, $search, $replace)
 {
     $value = Value::getString($value);
     if ($value === null) {
         return null;
     }
     $value = str_replace($search, $replace, $value);
     return $value;
 }
Esempio n. 9
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;
 }
Esempio n. 10
0
 /**
  * Caller
  *
  * @param string $value Value to be filtered
  *
  * @return string
  */
 public function upper($value)
 {
     $value = Value::getString($value);
     if ($value === null) {
         return null;
     }
     $charset = $this->getContext()->getCharset();
     $value = mb_strtoupper($value, $charset);
     return $value;
 }
Esempio n. 11
0
 /**
  * Caller
  *
  * @param string $value Value to be filtered
  *
  * @return string
  */
 public function escape($value)
 {
     $value = Value::getString($value);
     if ($value === null) {
         return null;
     }
     $charset = $this->getContext()->getCharset();
     $value = htmlentities($value, ENT_QUOTES, $charset);
     return $value;
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 /**
  * Caller
  *
  * @param mixed    $data     Data
  * @param \Closure $callback Callback
  *
  * @return mixed
  */
 public function map($data, \Closure $callback)
 {
     if (!Value::isArray($data)) {
         return array();
     } elseif (!is_callable($callback)) {
         return $data;
     }
     foreach ($data as $key => $value) {
         $data[$key] = call_user_func_array($callback, array($key, $value));
     }
     return $data;
 }
Esempio n. 14
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;
 }
Esempio n. 15
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;
 }
Esempio n. 16
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;
 }
Esempio n. 17
0
 /**
  * Caller
  *
  * @param \Traversable|array $values   Values to be iterated
  * @param callable           $callback Callback
  *
  * @return array
  */
 public function each($values, \Closure $callback)
 {
     if (!Value::isArray($values) || !is_callable($callback)) {
         return array();
     }
     $renderer = $this->getView()->getRenderer();
     $results = array();
     foreach ($values as $value) {
         $args = array($renderer, $value);
         $result = call_user_func_array($callback, $args);
         $results[] = $result;
     }
     return $results;
 }
Esempio n. 18
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;
 }
Esempio n. 19
0
 /**
  * Constructor
  *
  * @param Form     $form    Base form
  * @param string   $name    Unique name
  * @param array    $values  Values to be binded
  * @param callable $creator Fields creator
  * @param callable $updater Binded values updater
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(Form $form, $name, $values, $creator, $updater)
 {
     $this->form = $form;
     $this->name = $name;
     $this->values = Value::isArray($values) ? $values : (array) $values;
     if (!is_callable($creator)) {
         throw new \InvalidArgumentException(sprintf("Form bind '%s' creator is not callable.", $this->name));
     }
     $this->creator = $creator;
     if (!is_callable($creator)) {
         throw new \InvalidArgumentException(sprintf("Form bind '%s' updater is not callable.", $this->name));
     }
     $this->updater = $updater;
     $form->addBind($this);
 }
Esempio n. 20
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;
 }
Esempio n. 21
0
 /**
  * Caller
  *
  * @param mixed  $data      Traversable data
  * @param string $separator Characters between values
  *
  * @return mixed
  */
 public function join($data, $separator = ', ')
 {
     if (Value::isArray($data)) {
         $values = array();
         foreach ($data as $value) {
             $value = Value::getString($value);
             if ($value !== null) {
                 $values[] = $value;
             }
         }
         $data = $values;
     } else {
         $data = array();
     }
     $result = implode($separator, $data);
     return $result;
 }
Esempio n. 22
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;
 }
Esempio n. 23
0
 /**
  * Caller
  *
  * @param string  $value     Value
  * @param boolean $upperRest Uppercase all except first letter
  *
  * @return string
  */
 public function firstLower($value, $upperRest = false)
 {
     $value = Value::getString($value);
     if ($value === null) {
         return null;
     }
     $charset = $this->getContext()->getCharset();
     $first = mb_strtolower(mb_substr($value, 0, 1, $charset), $charset);
     $rest = null;
     if ($upperRest) {
         $rest = mb_strtoupper(mb_substr($value, 1, mb_strlen($value, $charset), $charset), $charset);
     } else {
         $rest = mb_substr($value, 1, mb_strlen($value, $charset), $charset);
     }
     $result = $first . $rest;
     return $result;
 }
Esempio n. 24
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;
 }
Esempio n. 25
0
 /**
  * {@inheritdoc}
  */
 public function filter($value)
 {
     $value = Value::getString($value);
     return $value;
 }
Esempio n. 26
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;
 }
Esempio n. 27
0
 /**
  * Check whether value is empty
  *
  * @return boolean
  */
 public function isEmpty()
 {
     return Value::isEmpty($this->value);
 }
Esempio n. 28
0
 /**
  * {@inheritdoc}
  */
 public function filter($value)
 {
     $value = Value::getDate($value);
     return $value;
 }