/** * {@inheritDoc} */ public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { // visit the arguments array_map(function ($argument) use(&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); }
/** * {@inheritDoc} */ public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { $xcallable = $this->getOperator($element->getName()); $arguments = array_map(function ($argument) use(&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); return $xcallable->distributeArguments($arguments); }
/** * {@inheritDoc} */ public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { $operatorName = $element->getName(); // the operator does not exist at all, throw an error before doing anything else. if (!$this->hasInlineOperator($operatorName) && !$this->hasOperator($operatorName)) { throw new OperatorNotFoundException($operatorName, sprintf('Operator "%s" does not exist.', $operatorName)); } // expand the arguments $arguments = array_map(function ($argument) use(&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); // and either inline the operator call if ($this->hasInlineOperator($operatorName)) { $callable = $this->getInlineOperator($operatorName); return call_user_func_array($callable, $arguments); } $inlinedArguments = empty($arguments) ? '' : ', ' . implode(', ', $arguments); // or defer it. return sprintf('call_user_func($operators["%s"]%s)', $operatorName, $inlinedArguments); }
/** * Visit an operator * * @param \Hoa\Visitor\Element $element Element to visit. * @param mixed &$handle Handle (reference). * @param mixed $eldnah Handle (not reference). * @return mixed */ protected function visitOperator(Ruler\Model\Operator $element, &$handle = null, $eldnah = null) { $name = $element->getName(); $arguments = []; foreach ($element->getArguments() as $argument) { $value = $argument->accept($this, $handle, $eldnah); $arguments[] = $value; if ($element::LAZY_BREAK === $element->shouldBreakLazyEvaluation($value)) { break; } } if (false === $this->operatorExists($name)) { throw new Ruler\Exception\Asserter('Operator %s does not exist.', 0, $name); } return $this->getOperator($name)->distributeArguments($arguments); }