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


PHP BehaviorCollection::methods方法代码示例

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


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

示例1: invalidFields

 /**
  * Returns an array of fields that have failed validation. On the current model.
  *
  * @param string $options An optional array of custom options to be made available in the beforeValidate callback
  * @return array Array of invalid fields
  * @see Model::validates()
  */
 public function invalidFields($options = array())
 {
     if (!$this->Behaviors->trigger('beforeValidate', array(&$this, $options), array('break' => true, 'breakOn' => false)) || $this->beforeValidate($options) === false) {
         return false;
     }
     if (!isset($this->validate) || empty($this->validate)) {
         return $this->validationErrors;
     }
     $data = $this->data;
     $methods = array_map('strtolower', get_class_methods($this));
     $behaviorMethods = array_keys($this->Behaviors->methods());
     if (isset($data[$this->alias])) {
         $data = $data[$this->alias];
     } elseif (!is_array($data)) {
         $data = array();
     }
     $exists = $this->exists();
     $_validate = $this->validate;
     $whitelist = $this->whitelist;
     if (!empty($options['fieldList'])) {
         $whitelist = $options['fieldList'];
     }
     if (!empty($whitelist)) {
         $validate = array();
         foreach ((array) $whitelist as $f) {
             if (!empty($this->validate[$f])) {
                 $validate[$f] = $this->validate[$f];
             }
         }
         $this->validate = $validate;
     }
     $validationDomain = $this->validationDomain;
     if (empty($validationDomain)) {
         $validationDomain = 'default';
     }
     foreach ($this->validate as $fieldName => $ruleSet) {
         if (!is_array($ruleSet) || is_array($ruleSet) && isset($ruleSet['rule'])) {
             $ruleSet = array($ruleSet);
         }
         $default = array('allowEmpty' => null, 'required' => null, 'rule' => 'blank', 'last' => true, 'on' => null);
         foreach ($ruleSet as $index => $validator) {
             if (!is_array($validator)) {
                 $validator = array('rule' => $validator);
             }
             $validator = array_merge($default, $validator);
             if (empty($validator['on']) || $validator['on'] == 'create' && !$exists || $validator['on'] == 'update' && $exists) {
                 $valid = true;
                 $requiredFail = !isset($data[$fieldName]) && $validator['required'] === true || isset($data[$fieldName]) && (empty($data[$fieldName]) && !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false;
                 if (!$requiredFail && array_key_exists($fieldName, $data)) {
                     if (empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
                         break;
                     }
                     if (is_array($validator['rule'])) {
                         $rule = $validator['rule'][0];
                         unset($validator['rule'][0]);
                         $ruleParams = array_merge(array($data[$fieldName]), array_values($validator['rule']));
                     } else {
                         $rule = $validator['rule'];
                         $ruleParams = array($data[$fieldName]);
                     }
                     if (in_array(strtolower($rule), $methods)) {
                         $ruleParams[] = $validator;
                         $ruleParams[0] = array($fieldName => $ruleParams[0]);
                         $valid = $this->dispatchMethod($rule, $ruleParams);
                     } elseif (in_array($rule, $behaviorMethods) || in_array(strtolower($rule), $behaviorMethods)) {
                         $ruleParams[] = $validator;
                         $ruleParams[0] = array($fieldName => $ruleParams[0]);
                         $valid = $this->Behaviors->dispatchMethod($this, $rule, $ruleParams);
                     } elseif (method_exists('Validation', $rule)) {
                         $valid = call_user_func_array(array('Validation', $rule), $ruleParams);
                     } elseif (!is_array($validator['rule'])) {
                         $valid = preg_match($rule, $data[$fieldName]);
                     } elseif (Configure::read('debug') > 0) {
                         trigger_error(__d('cake_dev', 'Could not find validation handler %s for %s', $rule, $fieldName), E_USER_WARNING);
                     }
                 }
                 if ($requiredFail || !$valid || is_string($valid) && strlen($valid) > 0) {
                     if (is_string($valid)) {
                         $message = $valid;
                     } elseif (isset($validator['message'])) {
                         $args = null;
                         if (is_array($validator['message'])) {
                             $message = $validator['message'][0];
                             $args = array_slice($validator['message'], 1);
                         } else {
                             $message = $validator['message'];
                         }
                         if (is_array($validator['rule']) && $args === null) {
                             $args = array_slice($ruleSet[$index]['rule'], 1);
                         }
                         $message = __d($validationDomain, $message, $args);
                     } elseif (is_string($index)) {
                         if (is_array($validator['rule'])) {
//.........这里部分代码省略.........
开发者ID:Chromedian,项目名称:inventory,代码行数:101,代码来源:Model.php

示例2: invalidFields

 /**
  * Returns an array of fields that have failed validation.
  *
  * @param string $options An optional array of custom options to be made available in the beforeValidate callback
  * @return array Array of invalid fields
  * @access public
  * @link http://book.cakephp.org/view/410/Validating-Data-from-the-Controller
  */
 function invalidFields($options = array())
 {
     if (!$this->Behaviors->trigger($this, 'beforeValidate', array($options), array('break' => true, 'breakOn' => false)) || $this->beforeValidate($options) === false) {
         return $this->validationErrors;
     }
     if (!isset($this->validate) || empty($this->validate)) {
         return $this->validationErrors;
     }
     $data = $this->data;
     $methods = array_map('strtolower', get_class_methods($this));
     $behaviorMethods = array_keys($this->Behaviors->methods());
     if (isset($data[$this->alias])) {
         $data = $data[$this->alias];
     } elseif (!is_array($data)) {
         $data = array();
     }
     $Validation =& Validation::getInstance();
     $this->exists();
     $_validate = $this->validate;
     $whitelist = $this->whitelist;
     if (array_key_exists('fieldList', $options)) {
         $whitelist = $options['fieldList'];
     }
     if (!empty($whitelist)) {
         $validate = array();
         foreach ((array) $whitelist as $f) {
             if (!empty($this->validate[$f])) {
                 $validate[$f] = $this->validate[$f];
             }
         }
         $this->validate = $validate;
     }
     foreach ($this->validate as $fieldName => $ruleSet) {
         if (!is_array($ruleSet) || is_array($ruleSet) && isset($ruleSet['rule'])) {
             $ruleSet = array($ruleSet);
         }
         $default = array('allowEmpty' => null, 'required' => null, 'rule' => 'blank', 'last' => false, 'on' => null);
         foreach ($ruleSet as $index => $validator) {
             if (!is_array($validator)) {
                 $validator = array('rule' => $validator);
             }
             $validator = array_merge($default, $validator);
             if (isset($validator['message'])) {
                 $message = $validator['message'];
             } else {
                 $message = __('This field cannot be left blank', true);
             }
             if (empty($validator['on']) || $validator['on'] == 'create' && !$this->__exists || $validator['on'] == 'update' && $this->__exists) {
                 $required = !isset($data[$fieldName]) && $validator['required'] === true || isset($data[$fieldName]) && (empty($data[$fieldName]) && !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false;
                 if ($required) {
                     $this->invalidate($fieldName, $message);
                     if ($validator['last']) {
                         break;
                     }
                 } elseif (array_key_exists($fieldName, $data)) {
                     if (empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
                         break;
                     }
                     if (is_array($validator['rule'])) {
                         $rule = $validator['rule'][0];
                         unset($validator['rule'][0]);
                         $ruleParams = array_merge(array($data[$fieldName]), array_values($validator['rule']));
                     } else {
                         $rule = $validator['rule'];
                         $ruleParams = array($data[$fieldName]);
                     }
                     $valid = true;
                     if (in_array(strtolower($rule), $methods)) {
                         $ruleParams[] = $validator;
                         $ruleParams[0] = array($fieldName => $ruleParams[0]);
                         $valid = $this->dispatchMethod($rule, $ruleParams);
                     } elseif (in_array($rule, $behaviorMethods) || in_array(strtolower($rule), $behaviorMethods)) {
                         $ruleParams[] = $validator;
                         $ruleParams[0] = array($fieldName => $ruleParams[0]);
                         $valid = $this->Behaviors->dispatchMethod($this, $rule, $ruleParams);
                     } elseif (method_exists($Validation, $rule)) {
                         $valid = $Validation->dispatchMethod($rule, $ruleParams);
                     } elseif (!is_array($validator['rule'])) {
                         $valid = preg_match($rule, $data[$fieldName]);
                     }
                     if (!$valid || is_string($valid) && strlen($valid) > 0) {
                         if (is_string($valid) && strlen($valid) > 0) {
                             $validator['message'] = $valid;
                         } elseif (!isset($validator['message'])) {
                             if (is_string($index)) {
                                 $validator['message'] = $index;
                             } elseif (is_numeric($index) && count($ruleSet) > 1) {
                                 $validator['message'] = $index + 1;
                             } else {
                                 $validator['message'] = $message;
                             }
                         }
//.........这里部分代码省略.........
开发者ID:javan-it-services,项目名称:steak,代码行数:101,代码来源:model.php


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