本文整理汇总了PHP中yii\base\Model::hasMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::hasMethod方法的具体用法?PHP Model::hasMethod怎么用?PHP Model::hasMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Model
的用法示例。
在下文中一共展示了Model::hasMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createValidator
/**
* Creates a validator object.
* @param mixed $type the validator type. This can be a built-in validator name,
* a method name of the model class, an anonymous function, or a validator class name.
* @param \yii\base\Model $object the data object to be validated.
* @param array|string $attributes list of attributes to be validated. This can be either an array of
* the attribute names or a string of comma-separated attribute names.
* @param array $params initial values to be applied to the validator properties
* @return Validator the validator
*/
public static function createValidator($type, $object, $attributes, $params = [])
{
$params['attributes'] = $attributes;
if ($type instanceof \Closure || $object->hasMethod($type)) {
// method-based validator
$params['class'] = __NAMESPACE__ . '\\InlineValidator';
$params['method'] = $type;
} else {
if (isset(static::$builtInValidators[$type])) {
$type = static::$builtInValidators[$type];
}
if (is_array($type)) {
foreach ($type as $name => $value) {
$params[$name] = $value;
}
} else {
if (!class_exists($type)) {
throw new InvalidConfigException("Unknown validator: '{$type}'.");
}
$params['class'] = $type;
}
}
return Yii::createObject($params);
}
示例2: createValidator
/**
* Creates a validator object.
* @param string|\Closure $type the validator type. This can be either:
* * a built-in validator name listed in [[builtInValidators]];
* * a method name of the model class;
* * an anonymous function;
* * a validator class name.
* @param \yii\base\Model $model the data model to be validated.
* @param array|string $attributes list of attributes to be validated. This can be either an array of
* the attribute names or a string of comma-separated attribute names.
* @param array $params initial values to be applied to the validator properties.
* @return Validator the validator
*/
public static function createValidator($type, $model, $attributes, $params = [])
{
$params['attributes'] = $attributes;
if ($type instanceof \Closure || $model->hasMethod($type)) {
// method-based validator
$params['class'] = __NAMESPACE__ . '\\InlineValidator';
$params['method'] = $type;
} else {
if (isset(static::$builtInValidators[$type])) {
$type = static::$builtInValidators[$type];
}
if (is_array($type)) {
$params = array_merge($type, $params);
} else {
$params['class'] = $type;
}
}
return Yii::createObject($params);
}
示例3: providersSupplied
/**
* @param MonsterProvidersTrait|yii\base\Model $model
* @param string $postKey
*/
protected function providersSupplied(&$model, $postKey)
{
if ($this->action() === self::ACTION_DEFAULT) {
// skip on default action
return;
}
$providers = ArrayHelper::getValue($this->visualBuilderProvided(), "{$postKey}.providers", null);
if (is_array($providers) === false) {
// no providers supplied
return;
}
//! @todo add check for proper class names and properties here
$model->setEntityDataProviders($providers);
if ($this->action() === self::ACTION_SAVE) {
$result = $model->hasMethod('saveMonsterContent') ? $model->saveMonsterContent() : $model->saveProviders();
if ($result === false) {
throw new \Exception(var_export($model->errors, true));
}
}
}