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


PHP Component::behaviors方法代码示例

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


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

示例1: hasBehavior

 /**
  * Checks whether or not a subject has a behavior of a certain type attached.
  *
  * @param \yii\base\Component $subject the subject to check
  * @param string|\yii\base\Behavior $behavior either the class name or an instance of the behavior
  * @param bool $throwException if set to true, an exception will be thrown if the
  * subject doesn't have the behavior attached
  * @return bool true if attached
  * @throws \yii\base\InvalidParamException when subject is of wrong type
  * @throws \yii\base\InvalidConfigException if desired and behavior missing
  */
 public static function hasBehavior($subject, $behavior, $throwException = false)
 {
     //only components allowed
     if (!$subject instanceof \yii\base\Component) {
         throw new InvalidParamException(Yii::t('app', 'Subject must extend Component'));
     }
     //prepare vars
     $behavior = $behavior instanceof \yii\base\Behavior ? $behavior::className() : $behavior;
     //check if behavior is attached
     $found = false;
     foreach ($subject->behaviors() as $name => $config) {
         $className = is_array($config) ? $config['class'] : $config;
         if (strcmp($className, $behavior) === 0) {
             $found = true;
             break;
         }
     }
     if ($throwException && !$found) {
         $msg = Yii::t('app', '{subject} needs to have behavior {behavior} attached', ['subject' => $subject->className(), 'behavior' => $behavior]);
         throw new InvalidConfigException($msg);
     }
     return $found;
 }
开发者ID:highestgoodlikewater,项目名称:yii2-toolbox,代码行数:34,代码来源:ComponentConfig.php

示例2: behaviors

 public function behaviors()
 {
     return Utils::behaviorMerge(self::className(), parent::behaviors());
 }
开发者ID:suyuanen,项目名称:p2p,代码行数:4,代码来源:llPayComponent.php


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