本文整理汇总了PHP中Rule::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Rule::factory方法的具体用法?PHP Rule::factory怎么用?PHP Rule::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rule
的用法示例。
在下文中一共展示了Rule::factory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* @param KnowledgeBase $knowledgeBase
*/
public function load(KnowledgeBase $knowledgeBase)
{
foreach ($this->data['facts'] as $name => $value) {
$knowledgeBase->add(Fact::factory($name, $value));
}
foreach ($this->data['rules'] as $condition => $data) {
if (is_string($data)) {
$action = $data;
$priority = 0;
} else {
$action = $data['action'];
$priority = isset($data['priority']) ? $data['priority'] : 0;
}
$knowledgeBase->add(Rule::factory($condition, $condition, $action, $priority));
}
}
示例2: execute
public function execute()
{
$this->context->pseudo_args($this->args);
// Create a rule
$rule = Rule::factory($this->context, $this->callback, $this->args);
// Execute the rule, and if no errors are returned, perform the actions
if ($rule->execute() === $this->check_against) {
// Use the parent for executing actions
$parent = $this->context->parent(Formo::PARENT);
foreach ($this->action_fields as $key => $field) {
// Fix the args
$this->context->pseudo_args($this->action_args[$key]);
// Perform each action
$callback = array($parent->find($field), $this->action_callbacks[$key]);
call_user_func_array($callback, $this->action_args[$key]);
}
}
}
示例3: rule
public function rule($field, $callback, array $args = NULL)
{
$context = $field = $field === NULL ? $this : $this->find($field);
$this->make_context($context, $callback);
// Add the rule
$field->add_validator('rules', Rule::factory($field, $context, $callback, $args));
return $this;
}