本文整理汇总了PHP中yii\base\Behavior::attach方法的典型用法代码示例。如果您正苦于以下问题:PHP Behavior::attach方法的具体用法?PHP Behavior::attach怎么用?PHP Behavior::attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Behavior
的用法示例。
在下文中一共展示了Behavior::attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attach
public function attach($owner)
{
parent::attach($owner);
$owner->on(BaseActiveRecord::EVENT_BEFORE_INSERT, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
$owner->on(BaseActiveRecord::EVENT_BEFORE_UPDATE, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
$owner->on(BaseActiveRecord::EVENT_BEFORE_DELETE, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
}
示例2: attach
/**
* @inheritdoc
* @param Controller $owner
*/
public function attach($owner)
{
if (false === $owner instanceof Controller) {
throw new InvalidParamException('QueryLanguageBehaviour can only be attached to ' . 'instances of Controller');
}
parent::attach($owner);
}
示例3: attach
public function attach($owner)
{
parent::attach($owner);
if (!$this->key) {
$this->key = constant(get_class($owner) . '::CACHE_KEY');
}
}
示例4: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
$validators = $this->owner->getValidators();
$validator = Validator::createValidator('safe', $this->owner, 'template_id');
$validators->append($validator);
}
示例5: attach
/**
* @inheritdoc
* @param ActiveRecord $owner
*/
public function attach($owner)
{
if (false === $owner instanceof ActiveRecord) {
throw new InvalidParamException('SafeSaver can only be attached to ' . 'instances of ActiveRecord');
}
parent::attach($owner);
}
示例6: 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);
});
}
示例7: attach
public function attach($owner)
{
parent::attach($owner);
if ($this->hasMethod('defaultScope')) {
call_user_func([$owner->modelClass, 'defaultScope'], $owner);
}
}
示例8: attach
/**
* @param ActiveRecord $owner
*/
public function attach($owner)
{
parent::attach($owner);
// Применяем конфигурационные опции
foreach ($this->imageConfig as $key => $value) {
$var = '_' . $key;
$this->{$var} = $value;
}
// Вычисляем корень сайта
if (empty($this->_rootPathAlias)) {
$savePathParts = explode('/', $this->_savePathAlias);
// Удаляем последнюю часть
unset($savePathParts[count($savePathParts - 1)]);
// Объединяем все части обратно
$this->_rootPathAlias = implode('/', $savePathParts);
}
// Добавляем валидатор require
if ($this->_imageRequire) {
$owner->validators->append(Validator::createValidator(RequiredValidator::className(), $owner, $this->_imageAttribute));
}
// Подключаем валидатор изображения
$validatorParams = array_merge(['extensions' => $this->_fileTypes, 'maxSize' => $this->_maxFileSize, 'skipOnEmpty' => true, 'tooBig' => 'Изображение слишком велико, максимальный размер: ' . floor($this->_maxFileSize / 1024 / 1024) . ' Мб'], $this->_imageValidatorParams);
$validator = Validator::createValidator(ImageValidator::className(), $owner, $this->_imageAttribute, $validatorParams);
$owner->validators->append($validator);
}
示例9: attach
/**
* @param ActiveRecord $owner
*/
public function attach($owner)
{
if (!$owner instanceof ActiveRecord) {
throw new \InvalidArgumentException(sprintf('Behavior %s can only be attached to an instace of yii\\db\\ActiveRecord, %s given.', get_called_class(), is_object($owner) ? get_class($owner) : gettype($owner)));
}
parent::attach($owner);
}
示例10: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
if (!in_array($owner->scenario, $this->scenarios)) {
return;
}
if (!$owner instanceof PasswordInterface) {
throw new InvalidConfigException('Class `' . get_class($owner) . '` must be an object implementing ' . '`PasswordInterface`');
}
parent::attach($owner);
$oldPasswordAttribute = $this->oldPasswordAttribute;
$newPasswordAttribute = $this->newPasswordAttribute;
$confirmedPasswordAttribute = $this->confirmedPasswordAttribute;
// required
if (!$this->skipOnEmpty && !$this->checkPassword) {
$validator = Validator::createValidator('required', $owner, [$newPasswordAttribute, $confirmedPasswordAttribute]);
$owner->validators->append($validator);
}
// safe
$attributes = [$newPasswordAttribute, $confirmedPasswordAttribute];
if ($this->checkPassword) {
$attributes[] = $oldPasswordAttribute;
}
$validator = Validator::createValidator('safe', $owner, $attributes);
$owner->validators->append($validator);
}
示例11: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
if ($this->modelClass === null) {
$this->modelClass = get_class($owner);
}
parent::attach($owner);
}
示例12: attach
/**
* Check if the behavior is attached to an Active Record
* @param ActiveRecord $owner
* @throws RuntimeException
*/
public function attach($owner)
{
if (!$owner instanceof ActiveRecord) {
throw new RuntimeException('Owner must be instance of yii\\db\\ActiveRecord');
}
parent::attach($owner);
}
示例13: attach
public function attach($model)
{
parent::attach($model);
if (empty($this->fileInputName)) {
$this->fileInputName = 'hydra_' . $this->attribute;
}
}
示例14: attach
/**
* @param \skeeks\cms\base\db\ActiveRecord $owner
* @throws Exception
*/
public function attach($owner)
{
if (!$owner instanceof \yii\db\ActiveRecord) {
throw new Exception(\Yii::t('app', "This behavior is designed only to work with {class}", ['class' => \yii\db\ActiveRecord::className()]));
}
parent::attach($owner);
}
示例15: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
$validators = $owner->validators;
$validator = Validator::createValidator('safe', $owner, array_keys($this->attributes));
$validators->append($validator);
}