/** * Get the final arguments. * * @param object $self The self value. * @param Arguments $arguments The incoming arguments. * * @return Arguments The final arguments. */ public function finalArguments($self, Arguments $arguments) { $finalArguments = $this->arguments->all(); if ($this->prefixSelf) { array_unshift($finalArguments, $self); } if ($this->suffixArgumentsObject) { $finalArguments[] = $arguments; } if ($this->suffixArguments && $arguments) { $finalArguments = array_merge($finalArguments, $arguments->all()); } return new Arguments($finalArguments); }
/** * Invoke this object. * * This method supports reference parameters. * * @param Arguments|array $arguments The arguments. * * @return mixed The result of invocation. * @throws Exception|Error If an error occurs. */ 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)); }