本文整理汇总了PHP中Validation::error方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::error方法的具体用法?PHP Validation::error怎么用?PHP Validation::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_date
/**
* date validator
*
* @param Validation $validation
* @param string $field
* @param string $value
* @throws Validation_Exception
* @return void
*/
public function validate_date(Validation $validation, $field, $value)
{
$stamp = strtotime($value);
if ($stamp < time() - 31556926) {
$validation->error($field, 'invalid_date', array($validation[$field]));
}
if ($field == "start") {
// if it is a new reservation, check if time is in the future
if ($this->id == null && $stamp < time()) {
$validation->error($field, 'past', array($validation[$field], $value));
}
// check if the resaurant is opened on that day
if (in_array(date("N", $stamp), Kohana::$config->load('smacky.closed'))) {
$validation->error($field, 'closed', array($validation[$field]));
}
}
if ($field == "end") {
// check if the end-stamp is after the start-stamp
if ($value <= $this->start) {
$validation->error($field, 'invalid_timespan', array($validation[$field], $value));
}
// check if max reservation time is not exceeded
if ($stamp - strtotime($this->start) > Kohana::$config->load('smacky.max-reservation') * 3600) {
$validation->error($field, 'max_time', array($validation[$field], $value));
}
}
}
示例2: unique_identity
/**
* Triggers error if identity exists.
* Validation callback.
*
* @param Validation Validation object
* @param string field name
* @return void
*/
public function unique_identity(Validation $validation, $field)
{
$identity_exists = (bool) DB::select(array('COUNT("*")', 'total_count'))->from($this->_table_name)->where('identity', '=', $validation['identity'])->and_where('provider', '=', $validation['provider'])->execute($this->_db)->get('total_count');
if ($identity_exists) {
$validation->error($field, 'identity_available', array($validation[$field]));
}
}
示例3: checkAdminRoleLimit
public function checkAdminRoleLimit(Validation $validation, $role)
{
$config = \Kohana::$config->load('features.limits');
if ($config['admin_users'] > 1 && $role == 'admin') {
$total = $this->repo->getTotalCount(['role' => 'admin']);
if ($total >= $config['admin_users']) {
$validation->error('role', 'adminUserLimitReached');
}
}
}
示例4: checkPostTypeLimit
public function checkPostTypeLimit(Validation $validation)
{
$config = \Kohana::$config->load('features.limits');
if ($config['forms'] !== TRUE) {
$total_forms = $this->repo->getTotalCount();
if ($total_forms >= $config['forms']) {
$validation->error('name', 'postTypeLimitReached');
}
}
}
示例5: checkPermissions
public function checkPermissions(Validation $validation, $permissions)
{
if (!$permissions) {
return;
}
foreach ($permissions as $permission) {
if (!$this->permission_repo->exists($permission)) {
$validation->error('permissions', 'permissionDoesNotExist', [$permission]);
return;
}
}
}
示例6: install
/**
*
* @param array $post
* @return boolean
* @throws Installer_Exception
*/
public function install(array $post)
{
if (empty($post)) {
throw new Installer_Exception('No install data!');
}
if (isset($post['password_generate'])) {
$post['password_field'] = Text::random();
}
if (isset($post['admin_dir_name'])) {
$post['admin_dir_name'] = URL::title($post['admin_dir_name']);
}
if (isset($post['db_port'])) {
$post['db_port'] = (int) $post['db_port'];
}
date_default_timezone_set($post['timezone']);
$this->_session->set('install_data', $post);
$this->_validation = $this->_valid($post);
try {
$this->_db_instance = $this->connect_to_db($post);
} catch (Database_Exception $exc) {
$validation = FALSE;
switch ($exc->getCode()) {
case 1049:
$this->_validation->error('db_name', 'incorrect');
$validation = TRUE;
break;
case 2:
$this->_validation->error('db_server', 'incorrect')->error('db_user', 'incorrect')->error('db_password', 'incorrect');
$validation = TRUE;
break;
}
if ($validation === TRUE) {
throw new Validation_Exception($this->_validation, $exc->getMessage(), NULL, $exc->getCode());
} else {
throw new Database_Exception($exc->getMessage(), NULL, $exc->getCode());
}
}
Database::$default = 'install';
Observer::notify('before_install', $post, $this->_validation);
if (isset($post['empty_database'])) {
$this->_reset();
}
define('TABLE_PREFIX_TMP', Arr::get($post, 'db_table_prefix', ''));
$this->_import_shema($post);
$this->_import_dump($post);
$this->_install_modules($post);
Observer::notify('install', $post);
$this->_create_site_config($post);
$this->_create_config_file($post);
return TRUE;
}
示例7: valid_range
public function valid_range(Validation $validation, $field)
{
$start = $validation['startDate'];
$end = $validation['endDate'];
if (!$start || !$end || $start >= $end) {
$validation->error($field, 'valid_range', array($validation[$field]));
}
}
示例8: is_valid
/**
* Validation callback
*
* @param string $name Validation name
* @param Validation $validation Validation object
* @param string $field Field name
*
* @uses Valid::numeric
* @uses Config::get
*/
public function is_valid($name, Validation $validation, $field)
{
// Make sure we have a valid term id set
if ($name == 'category') {
if (isset($this->categories) and is_array($this->categories)) {
foreach ($this->categories as $id => $term) {
if ($term == 'last' or !Valid::numeric($term)) {
$validation->error('categories', 'invalid', array($validation[$field]));
}
}
}
} elseif ($name == 'created') {
if (!empty($this->author_date) and !($date = strtotime($this->author_date))) {
$validation->error($field, 'invalid', array($this->author_date));
} else {
if (isset($date)) {
$this->created = $date;
}
}
} elseif ($name == 'author') {
if (!empty($this->author_name) and !($account = User::lookup_by_name($this->author_name))) {
$validation->error($field, 'invalid', array($this->author_name));
} else {
if (isset($account)) {
$this->author = $account->id;
}
}
} elseif ($name == 'pubdate') {
if (!empty($this->author_pubdate) and !($date = strtotime($this->author_pubdate))) {
$validation->error($field, 'invalid', array($validation[$field]));
} else {
if (isset($date)) {
$this->pubdate = $date;
}
}
} elseif ($name == 'image') {
if (isset($_FILES['image']['name']) and !empty($_FILES['image']['name'])) {
$allowed_types = Config::get('media.supported_image_formats', array('jpg', 'png', 'gif'));
$data = Validation::factory($_FILES)->rule('image', 'Upload::not_empty')->rule('image', 'Upload::valid')->rule('image', 'Upload::type', array(':value', $allowed_types));
if (!$data->check()) {
$validation->error($field, 'invalid', array($validation[$field]));
}
}
}
}
示例9: user_has_avatar
/**
* @param Validation $validation
* @param string $field
* @param string $value
*/
public function user_has_avatar($validation, $field, $value)
{
if (!$this->user->has('avatars', $value)) {
$validation->error($field, 'You do not own that avatar');
}
}
示例10: checkRequiredAttributes
/**
* Check required attributes are completed before completing stages
*
* @param Validation $validation
* @param Array $attributes
* @param Array $data
*/
public function checkRequiredAttributes(Validation $validation, $attributes, $data)
{
if (empty($data['completed_stages'])) {
return;
}
// If a stage is being marked completed
// Check if the required attribute have been completed
foreach ($data['completed_stages'] as $stage_id) {
// Load the required attributes
$required_attributes = $this->attribute_repo->getRequired($stage_id);
// Check each attribute has been completed
foreach ($required_attributes as $attr) {
if (!array_key_exists($attr->key, $attributes)) {
$stage = $this->stage_repo->get($stage_id);
// If a required attribute isn't completed, throw an error
$validation->error('values', 'attributeRequired', [$attr->key, $stage->label]);
}
}
}
}
示例11: validate_commands
/**
* Validate item command input when creating an item
*
* @param Validation $validation Validation objec
* @param JSON $value Command to validate
*/
public static function validate_commands($validation, $value)
{
$values = json_decode($value, TRUE);
foreach ($values as $command) {
$cmd = Item_Command::factory($command['name']);
if (!$cmd->validate($command['param'])) {
$validation->error('commands', $command['name']);
}
}
}
示例12: is_valid
/**
* Validation callback
*
* @param Validation $validation Validation object
* @param string $field Field name
* @uses Valid::numeric
* @return void
*/
public function is_valid(Validation $validation, $field)
{
if (empty($this->name) and empty($this->title)) {
$validation->error('title', 'not_empty', array($this->title));
} else {
$text = empty($this->name) ? $this->title : $this->name;
$this->name = $this->_unique_slug(URL::title($text));
}
}
示例13: check_measures
/**
* @static
* @param string $field
* @param string $value
* @param Model $model
* @param Validation $validation
*/
public static function check_measures($field, $value, $model, $validation)
{
if ($value == 'E-Total' and $model->min == 0) {
$validation->error($field, "E-Total's MIN cannot be zero.");
}
}
示例14: _is_unique
/**
* Callback for validating that a field is unique.
*
* @param Validation $data
* @param Jelly_Model $model
* @param string $field
* @param string $value
* @return void
*/
public function _is_unique(Validation $data, Jelly_Model $model, $field, $value)
{
// According to the SQL standard NULL is not checked by the unique constraint
// We also skip this test if the value is the same as the default value
if ($value !== NULL and $value !== $this->default) {
// Build query
$query = Jelly::query($model)->where($field, '=', $value);
// Limit to one
$query->limit(1);
if ($query->count()) {
// Add error if duplicate found
$data->error($field, 'unique');
}
}
}
示例15: valid_avatar_type
/**
* @param Validation $validation
* @param string $field
* @param string $value
*/
public function valid_avatar_type($validation, $field, $value)
{
$avatars = $this->get_avatar_drivers();
$ids = array();
foreach ($avatars as $avatar) {
$ids[] = $avatar->id;
}
if (!in_array($value, $ids)) {
$validation->error($field, 'Unknown avatar type');
}
}