当前位置: 首页>>代码示例>>PHP>>正文


PHP validator::getInstance方法代码示例

本文整理汇总了PHP中validator::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP validator::getInstance方法的具体用法?PHP validator::getInstance怎么用?PHP validator::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validator的用法示例。


在下文中一共展示了validator::getInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _validates

 /**
  * Returns true if configuration field pass given validation rule.
  * 
  * @param string $config Configuration variable
  * @param string $group Configuration group
  * @param mixed $value Submitted value
  * @param mixed $relatedValue value that related such as mail settings
  * @return boolean True if there are no errors
  * @access public
  */
 function _validates($config, $group, &$value, &$relatedValue = null)
 {
     global $_CONF_VALIDATE, $LANG_VALIDATION;
     $_validator =& validator::getInstance();
     if (isset($_CONF_VALIDATE[$group][$config]) && !empty($_CONF_VALIDATE[$group][$config])) {
         $default = array('rule' => 'blank');
         foreach ($_CONF_VALIDATE[$group][$config] as $index => $validator) {
             if (!is_array($validator)) {
                 if ($index == 'message' && is_string($validator)) {
                     continue;
                 }
                 $validator = array('rule' => $validator);
             } else {
                 if ($index == 'rule') {
                     $validator = array('rule' => $validator);
                 }
             }
             if (isset($_CONF_VALIDATE[$group][$config]['message']) && is_string($_CONF_VALIDATE[$group][$config]['message'])) {
                 $validator['message'] = $_CONF_VALIDATE[$group][$config]['message'];
                 unset($_CONF_VALIDATE[$group][$config]['message']);
             }
             $validator = array_merge($default, $validator);
             if (isset($validator['message'])) {
                 $message = $validator['message'];
             } else {
                 if (is_string($validator['rule']) && isset($LANG_VALIDATION[$validator['rule']])) {
                     $message = $LANG_VALIDATION[$validator['rule']];
                 } else {
                     if (is_array($validator['rule']) && isset($LANG_VALIDATION[$validator['rule'][0]])) {
                         $message = $LANG_VALIDATION[$validator['rule'][0]];
                     } else {
                         $message = $LANG_VALIDATION['default'];
                     }
                 }
             }
             if (is_array($validator['rule'])) {
                 $rule = $validator['rule'][0];
                 unset($validator['rule'][0]);
                 $ruleParams = array_merge(array($value), array_values($validator['rule']));
             } else {
                 $rule = $validator['rule'];
                 $ruleParams = array($value);
             }
             $valid = true;
             $custom_function = 'custom_validation_' . strtolower($rule);
             if (function_exists($custom_function)) {
                 $ruleParams[] = $validator;
                 $ruleParams[0] = array($config => $ruleParams[0]);
                 if (is_array($relatedValue) && !empty($relatedValue)) {
                     $ruleParams[] = $relatedValue;
                 }
                 $valid = $custom_function($rule, $ruleParams);
             } elseif (method_exists($_validator, $rule)) {
                 $valid = $_validator->dispatchMethod($rule, $ruleParams);
             } elseif (!is_array($validator['rule'])) {
                 $valid = preg_match($rule, $value);
             }
             if (!$valid || is_string($valid) && strlen($valid) > 0) {
                 if (is_string($valid) && strlen($valid) > 0) {
                     $validator['message'] = $valid;
                 } elseif (!isset($validator['message'])) {
                     $validator['message'] = $message;
                 }
                 $this->validationErrors[$group][$config] = $validator['message'];
                 $this->validationErrorValues[$group][$config] = $value;
                 return FALSE;
             }
         }
         // end foreach
         return $valid;
     }
     // end if
     return TRUE;
 }
开发者ID:alxstuart,项目名称:ajfs.me,代码行数:84,代码来源:config.class.php

示例2: reset

 /**
  * reset this singleton back to base values
  */
 private function reset()
 {
     $v = validator::getInstance();
     foreach (array('rules') as $var) {
         $v->{$var} = array();
     }
 }
开发者ID:AshleyJSheridan,项目名称:tweed,代码行数:10,代码来源:validator.php

示例3: _extract

 /**
  * Get the values to use when value sent to validation method is
  * an array.
  *
  * @param  array $params Parameters sent to validation method
  * @return void
  */
 protected function _extract($params)
 {
     $_this = validator::getInstance();
     extract($params, EXTR_OVERWRITE);
     if (isset($check)) {
         $_this->check = $check;
     }
     if (isset($regex)) {
         $_this->regex = $regex;
     }
     if (isset($type)) {
         $_this->type = $type;
     }
 }
开发者ID:Geeklog-Core,项目名称:geeklog,代码行数:21,代码来源:validator.class.php

示例4: validate


//.........这里部分代码省略.........
                 oc::registry()->message->data['error']['warning'] = $this->language->get('error_stock');
             }
             if ($template_info['minimum']) {
                 $products = $this->cart->getProducts();
                 foreach ($products as $product) {
                     $product_total = 0;
                     foreach ($products as $product_2) {
                         if ($product_2['product_id'] == $product['product_id']) {
                             $product_total += $product_2['quantity'];
                         }
                     }
                     if ($product['minimum'] > $product_total) {
                         oc::registry()->message->data['error']['warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
                     }
                 }
             }
         } else {
             // product
             if ($this->isAjax()) {
                 $this->load->model('catalog/product');
                 if (isset($this->request->get['product_id'])) {
                     $product_id = $this->request->get['product_id'];
                 } elseif (isset($this->request->post['product_id'])) {
                     $product_id = $this->request->post['product_id'];
                 } else {
                     $product_id = 0;
                 }
                 if ($template_info['minimum']) {
                     $product_info = $this->model_catalog_product->getProduct($product_id);
                     if (isset($this->request->post['quantity'])) {
                         $quantity = $this->request->post['quantity'];
                     } else {
                         $quantity = 1;
                     }
                     if ($product_info['minimum'] > $quantity) {
                         oc::registry()->message->data['error']['warning'] = sprintf($this->language->get('error_minimum'), $product_info['name'], $product_info['minimum']);
                     }
                 }
                 if (strpos(VERSION, '1.6') !== FALSE) {
                     if (isset($this->request->post['profile_id'])) {
                         $profile_id = $this->request->post['profile_id'];
                     } else {
                         $profile_id = 0;
                     }
                     $profiles = $this->model_catalog_product->getProfiles($product_id);
                     if ($profiles) {
                         $profile_ids = array();
                         foreach ($profiles as $profile) {
                             $profile_ids[] = $profile['profile_id'];
                         }
                         if (!in_array($profile_id, $profile_ids)) {
                             $json['error']['profile'] = $this->language->get('error_profile_required');
                         }
                     }
                 }
                 if ($template_info['use_option'] && $template_info['option_required']) {
                     if (isset($this->request->post['option'])) {
                         $option = array_filter($this->request->post['option']);
                     } else {
                         $option = array();
                     }
                     $required_options = array();
                     $product_options = $this->model_catalog_product->getProductOptions($product_id);
                     foreach ($product_options as $product_option) {
                         if ($product_option['required'] && (!isset($this->request->post['option'][$product_option['product_option_id']]) || !$this->request->post['option'][$product_option['product_option_id']])) {
                             $required_options[] = trim($product_option['name']);
                         }
                     }
                     if (!empty($required_options)) {
                         oc::registry()->message->data['error']['warning'] = sprintf($this->language->get('error_required_options'), implode(', ', $required_options));
                     }
                 }
             }
         }
         $language_id = $this->config->get('config_language_id');
         foreach ($template_info['fields'] as $field_id => $field_info) {
             if (!$field_info['status']) {
                 continue;
             }
             if (isset($post['fields'][$field_id]) || in_array($field_info['type']['type'], array('radio', 'checkbox'))) {
                 $value = isset($post['fields'][$field_id]) ? $post['fields'][$field_id] : FALSE;
                 // field value
                 $isEmpty = $value === FALSE || empty($value) && $value !== '0';
                 if ($isEmpty) {
                     if ($field_info['required']) {
                         oc::registry()->message->data['error']['fields'][$field_id] = $this->language->get('error_required');
                     }
                 } elseif (!empty($field_info['validate']) && ($validator = validator::getInstance($field_info))) {
                     if (!$validator->validate($value)) {
                         oc::registry()->message->data['error']['fields'][$field_id] = $validator->getErrorMessage();
                     }
                 }
             } else {
                 oc::registry()->message->data['error']['system'] = sprintf($this->language->get('error_field_empty'), $field_info['title'][$language_id]);
                 break;
             }
         }
     }
     return (bool) empty(oc::registry()->message->data['error']);
 }
开发者ID:SwayWebStudio,项目名称:night.com,代码行数:101,代码来源:quick_order_pro.php


注:本文中的validator::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。