/** * {@inheritdoc} */ public function validate($value) { if (Value::isEmpty($value)) { return true; } $valid = ctype_alpha($value); return $valid; }
/** * {@inheritdoc} */ public function validate($value) { if (Value::isEmpty($value)) { return true; } $valid = filter_var($value, FILTER_VALIDATE_FLOAT) !== false; return $valid; }
/** * {@inheritdoc} */ public function validate($value) { if (Value::isEmpty($value)) { return true; } $valid = Arr::contains($value, $this->values); return $valid; }
/** * {@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; }
/** * {@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); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * {@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; }
/** * 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; }
/** * 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; }
/** * {@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; }
/** * {@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; }
/** * 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; }
/** * {@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; }
/** * 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); }
/** * 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; }
/** * 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; }
/** * {@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; }
/** * 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; }
/** * {@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; }
/** * {@inheritdoc} */ public function filter($value) { $value = Value::getString($value); return $value; }
/** * 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; }
/** * Check whether value is empty * * @return boolean */ public function isEmpty() { return Value::isEmpty($this->value); }
/** * {@inheritdoc} */ public function filter($value) { $value = Value::getDate($value); return $value; }