• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP BehaviorCollection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: init

 /**
  * Attaches a model object and loads a list of behaviors
  *
  * @todo Make this method a constructor instead..
  * @param string $modelName
  * @param array $behaviors
  * @return void
  */
 public function init($modelName, $behaviors = array())
 {
     $this->modelName = $modelName;
     if (!empty($behaviors)) {
         foreach (BehaviorCollection::normalizeObjectArray($behaviors) as $behavior => $config) {
             $this->load($config['class'], $config['settings']);
         }
     }
 }
开发者ID:ronaldsalazar23,项目名称:ComercialChiriguano,代码行数:17,代码来源:BehaviorCollection.php


示例2: testHasMethodAsCallback

 /**
  * test hasMethod returning a 'callback'
  *
  * @return void
  */
 public function testHasMethodAsCallback()
 {
     new Sample();
     $Collection = new BehaviorCollection();
     $Collection->init('Sample', array('Test', 'Test2'));
     $result = $Collection->hasMethod('testMethod', true);
     $expected = array('Test', 'testMethod');
     $this->assertEquals($expected, $result);
     $result = $Collection->hasMethod('resolveMethod', true);
     $expected = array('Test2', 'resolveMethod');
     $this->assertEquals($expected, $result);
     $result = $Collection->hasMethod('mappingRobotOnTheRoof', true);
     $expected = array('Test2', 'mapped', 'mappingRobotOnTheRoof');
     $this->assertEquals($expected, $result);
 }
开发者ID:magooemp,项目名称:eramba,代码行数:20,代码来源:BehaviorCollectionTest.php


示例3: 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


示例4: 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


示例5: hasMethod

 /**
  * Check that a method is callable on a model. This will check both the model's own methods, its
  * inherited methods and methods that could be callable through behaviors.
  *
  * @param string $method The method to be called.
  * @return boolean True on method being callable.
  */
 public function hasMethod($method)
 {
     if (method_exists($this, $method)) {
         return true;
     }
     return $this->Behaviors->hasMethod($method);
 }
开发者ID:ajayphp,项目名称:Zuha,代码行数:14,代码来源:Model.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Benchmark类代码示例发布时间:2022-05-23
下一篇:
PHP BeanFinder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap