當前位置: 首頁>>代碼示例>>PHP>>正文


PHP base\Behavior類代碼示例

本文整理匯總了PHP中yii\base\Behavior的典型用法代碼示例。如果您正苦於以下問題:PHP Behavior類的具體用法?PHP Behavior怎麽用?PHP Behavior使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Behavior類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param string|Behavior $behavior
  */
 public function __construct($behavior)
 {
     if ($behavior instanceof Behavior) {
         $this->_behavior = (string) $behavior->className();
     } else {
         if (is_string($behavior)) {
             $this->_behavior = (string) $behavior;
         }
     }
 }
開發者ID:Liv1020,項目名稱:cms,代碼行數:13,代碼來源:HasBehavior.php

示例2: init

 public function init()
 {
     parent::init();
     $mark = $this->multiple ? UploadStrategyFactory::UPLOAD_MULTIPLE : UploadStrategyFactory::UPLOAD_SINGLE;
     $this->uploadStrategy = UploadStrategyFactory::get($mark);
     $this->uploadStrategy->setBehavior($this);
 }
開發者ID:Vlsirko,項目名稱:yii2-uploads,代碼行數:7,代碼來源:UploadBehaviour.php

示例3: init

 /**
  * Init
  */
 public function init()
 {
     if ($this->attributes == null) {
         throw new InvalidConfigException('Property "attributes" must be set');
     }
     parent::init();
 }
開發者ID:voskobovich,項目名稱:yii2-copy-value-behavior,代碼行數:10,代碼來源:CopyValueBehavior.php

示例4: attach

 public function attach($owner)
 {
     parent::attach($owner);
     if (!$this->key) {
         $this->key = constant(get_class($owner) . '::CACHE_KEY');
     }
 }
開發者ID:radiegtya,項目名稱:easyii,代碼行數:7,代碼來源:CacheFlush.php

示例5: attach

 public function attach($owner)
 {
     parent::attach($owner);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_INSERT, [AdminLogEvent::className(), AdminLogEvent::EVENT_CREATE_ITEM], ['title' => $this->titleAttribute, 'icon' => $this->icon]);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_UPDATE, [AdminLogEvent::className(), AdminLogEvent::EVENT_UPDATE_ITEM], ['title' => $this->titleAttribute, 'icon' => $this->icon]);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_DELETE, [AdminLogEvent::className(), AdminLogEvent::EVENT_DELETE_ITEM], ['title' => $this->titleAttribute, 'icon' => $this->icon]);
 }
開發者ID:radiata-cms,項目名稱:radiata,代碼行數:7,代碼來源:AdminLogBehavior.php

示例6: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!is_array($this->attributes) || empty($this->attributes)) {
         throw new InvalidParamException('Invalid or empty attributes array.');
     } else {
         foreach ($this->attributes as $attribute => $config) {
             if (!isset($config['path']) || empty($config['path'])) {
                 throw new InvalidParamException('Path must be set for all attributes.');
             }
             if (!isset($config['tempPath']) || empty($config['tempPath'])) {
                 throw new InvalidParamException('Temporary path must be set for all attributes.');
             }
             if (!isset($config['url']) || empty($config['url'])) {
                 $config['url'] = $this->publish($config['path']);
             }
             $this->attributes[$attribute]['path'] = FileHelper::normalizePath(Yii::getAlias($config['path'])) . DIRECTORY_SEPARATOR;
             $this->attributes[$attribute]['tempPath'] = FileHelper::normalizePath(Yii::getAlias($config['tempPath'])) . DIRECTORY_SEPARATOR;
             $this->attributes[$attribute]['url'] = rtrim($config['url'], '/') . '/';
             $validator = Validator::createValidator('string', $this->owner, $attribute);
             $this->owner->validators[] = $validator;
             unset($validator);
         }
     }
 }
開發者ID:cjq,項目名稱:QRCode-yii2,代碼行數:28,代碼來源:UploadBehavior.php

示例7: canSetProperty

 /**
  * @inheritdoc
  */
 public function canSetProperty($name, $checkVars = true)
 {
     if (in_array($name, [$this->titleAttribute, $this->keywordsAttribute, $this->descriptionAttribute])) {
         return true;
     }
     return parent::canSetProperty($name, $checkVars);
 }
開發者ID:romi45,項目名稱:yii2-seo-behavior,代碼行數:10,代碼來源:SeoBehavior.php

示例8: attach

 /**
  * @param \yii\base\Component $owner
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!$this->group) {
         $this->group = get_class($this->owner);
     }
 }
開發者ID:Chiliec,項目名稱:yii2-hitable-behavior,代碼行數:10,代碼來源:HitableBehavior.php

示例9: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->copyTo)) {
         throw new InvalidConfigException('attribute copyTo must be provided');
     }
 }
開發者ID:jlorente,項目名稱:yii2-app-advanced,代碼行數:10,代碼來源:CopyBehavior.php

示例10: __get

 public function __get($name)
 {
     if ($name == $this->getAttributeName()) {
         return $this->getRelation();
     }
     return parent::__get($name);
 }
開發者ID:NullRefExcep,項目名稱:yii2-core,代碼行數:7,代碼來源:HasRelation.php

示例11: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $validators = $owner->validators;
     foreach ($this->rules as $rule) {
         if ($rule instanceof Validator) {
             $validators->append($rule);
             $this->validators[] = $rule;
             // keep a reference in behavior
         } elseif (is_array($rule) && isset($rule[0], $rule[1])) {
             // attributes, validator type
             $validator = Validator::createValidator($rule[1], $owner, (array) $rule[0], array_slice($rule, 2));
             $validators->append($validator);
             $this->validators[] = $validator;
             // keep a reference in behavior
         } else {
             throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');
         }
     }
     $owner->on(ActiveRecord::EVENT_BEFORE_INSERT, function () {
         $this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
     });
     $owner->on(ActiveRecord::EVENT_BEFORE_UPDATE, function () {
         $this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
     });
 }
開發者ID:slavam,項目名稱:placement,代碼行數:29,代碼來源:BasicBehavior.php

示例12: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->sessionVarName)) {
         throw new InvalidConfigException('The $sessionVarName should be configured for this behavior.');
     }
 }
開發者ID:marqu3s,項目名稱:yii2-behaviors,代碼行數:10,代碼來源:MarquesBehavior.php

示例13: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->app_id || !$this->mch_id || !$this->app_key || !$this->app_secret) {
         throw new InvalidConfigException("WxPay::app_id & mch_id & app_key & app_secret are required to be configured.");
     }
 }
開發者ID:chinahub,項目名稱:yii2-wechat-pay,代碼行數:10,代碼來源:WxPayConfig.php

示例14: canSetProperty

 /**
  * @inheritdoc
  */
 public function canSetProperty($name, $checkVars = true)
 {
     if (isset($this->attributes[$name]) || $name === $this->flagsAttribute) {
         return true;
     }
     return parent::canSetProperty($name, $checkVars);
 }
開發者ID:Mirocow,項目名稱:yii2-flag-behavior,代碼行數:10,代碼來源:FlagBehavior.php

示例15: attach

 public function attach($owner)
 {
     if (!$owner instanceof ShelterInterface) {
         throw new InvalidParamException('$owner must implement ShelterInterface.');
     }
     parent::attach($owner);
 }
開發者ID:iw-reload,項目名稱:iw,代碼行數:7,代碼來源:ShelterCapacityBehavior.php


注:本文中的yii\base\Behavior類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。