Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result back from the function in the Rule. #44

Open
yayabla opened this issue Feb 1, 2016 · 0 comments
Open

Result back from the function in the Rule. #44

yayabla opened this issue Feb 1, 2016 · 0 comments

Comments

@yayabla
Copy link

yayabla commented Feb 1, 2016

Would be nice to have the result back from the function in the Rule.
not really an issue but it makes the Ruler more complete :)

$rb = new RuleBuilder;
$rule = $rb->create(
$rb->logicalAnd(
$rb['minNumPeople']->lessThanOrEqualTo($rb['actualNumPeople']),
$rb['maxNumPeople']->greaterThanOrEqualTo($rb['actualNumPeople'])
),
function() {
return 'YAY!';
}
);
$context = new Context(array(
'minNumPeople' => 5,
'maxNumPeople' => 25,
'actualNumPeople' => function() {
return 6;
},
));
echo $rule->execute($context); // "Yay!"

this does not work.
but if you change line in Rule.php;

public function execute(Context $context)
{
if ($this->evaluate($context) && isset($this->action)) {
if (!is_callable($this->action)) {
throw new \LogicException('Rule actions must be callable.');
}

        **return** call_user_func($this->action);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant