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


PHP Component::className方法代碼示例

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


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

示例1: validate

 /**
  * @param Component $component
  * @return \skeeks\sx\validate\Result
  */
 public function validate($component)
 {
     if (!$component instanceof ActiveRecord) {
         return $this->_bad(\Yii::t('app', "Object: {class} must be inherited from: {parent}", ['class' => $component->className(), 'parent' => ActiveRecord::className()]));
     }
     return !$component->isNewRecord ? $this->_ok() : $this->_bad(\Yii::t('app', "The object must already be saved"));
 }
開發者ID:Liv1020,項目名稱:cms,代碼行數:11,代碼來源:NotNewRecord.php

示例2: behavior

 /**
  * Getting behavior object from given model
  *
  * @param Component $model
  * @return SeoBehavior
  * @throws InvalidConfigException if model don't have our SeoBehavior
  */
 protected static function behavior(Component $model)
 {
     foreach ($model->getBehaviors() as $b) {
         if ($b instanceof SeoBehavior) {
             return $b;
         }
     }
     throw new InvalidConfigException('Model ' . $model->className() . ' must have SeoBehavior');
 }
開發者ID:romi45,項目名稱:yii2-seo-behavior,代碼行數:16,代碼來源:SeoContentHelper.php

示例3: testOf

 public function testOf()
 {
     $container = new Container();
     $className = Component::className();
     $instance = Instance::of($className, $container);
     $this->assertTrue($instance instanceof Instance);
     $this->assertTrue($instance->get() instanceof Component);
     $this->assertTrue(Instance::ensure($instance, $className) instanceof Component);
     $this->assertTrue($instance->get() !== Instance::ensure($instance, $className));
 }
開發者ID:rajanishtimes,項目名稱:basicyii,代碼行數:10,代碼來源:InstanceTest.php

示例4: validate

 /**
  * @param Component $component
  * @return \skeeks\sx\validate\Result
  */
 public function validate($component)
 {
     if (!$component instanceof Component) {
         return $this->_bad(\Yii::t('app', "The object must be inherited from") . ": " . Component::className());
     }
     if (!$this->_behavior) {
         return $this->_ok();
     }
     $hasBehaviors = $component->getBehaviors();
     foreach ($hasBehaviors as $behavior) {
         if ($behavior instanceof $this->_behavior) {
             return $this->_ok();
         }
     }
     return $this->_bad(\Yii::t('app', "At the component: {class} requires a behavior", ['class' => $component->className()]) . ": " . $this->_behavior);
 }
開發者ID:Liv1020,項目名稱:cms,代碼行數:20,代碼來源:HasBehavior.php

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

示例6: name

}
function name($event)
{
    echo 'hi ' . $event->data . '<br />';
}
function event()
{
    echo 'hello event!<br />';
}
function event2()
{
    echo 'hello event2!<br />';
}
$test = new Test2();
$test->on('say', 'hello');
$test->on('say', 'name', 'shuru');
$test->on('say', [$test, 'test']);
$test->on('say', ['Test2', 'test_two']);
$test->trigger('say');
//會觸發實例的事件
echo '<hr />';
$test->off('say', 'hello');
$test->trigger('say');
echo '<hr />';
Event::on(Test2::className(), 'say', 'event');
$test->trigger('say');
//因為該對象的類,也綁定了該事件,因此會觸發類事件,類事件是在Event.php裏麵
echo '<hr />';
Event::on(Component::className(), 'say', 'event2');
//父類也綁定了該事件,因此,也會被觸發
$test->trigger('say');
開發者ID:xinyifuyun,項目名稱:code-yii,代碼行數:31,代碼來源:test2.php


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