public function invokeWith($arguments = array())
{
$this->closeRule();
if (empty($this->rules)) {
call_user_func($this->defaultAnswerCallback, $this);
$this->closeRule();
}
if ($arguments instanceof Arguments) {
$argumentsArray = $arguments->all();
} else {
$argumentsArray = $arguments;
$arguments = new Arguments($arguments);
}
foreach ($this->rules as $rule) {
if ($this->matcherVerifier->matches($rule->criteria(), $argumentsArray)) {
break;
}
}
$answer = $rule->next();
foreach ($answer->secondaryRequests() as $request) {
$this->invoker->callWith($request->callback(), $request->finalArguments($this->self, $arguments));
}
$request = $answer->primaryRequest();
return $this->invoker->callWith($request->callback(), $request->finalArguments($this->self, $arguments));
}