Neos\Eel\Context::call PHP Method

call() public method

Call a method on this context
public call ( string $method, array $arguments = [] ) : mixed
$method string
$arguments array Arguments to the method, if of type Context they will be unwrapped
return mixed
    public function call($method, array $arguments = [])
    {
        if ($this->value === null) {
            return null;
        } elseif (is_object($this->value)) {
            $callback = [$this->value, $method];
        } elseif (is_array($this->value)) {
            if (!array_key_exists($method, $this->value)) {
                throw new EvaluationException('Array has no function "' . $method . '"', 1344350459);
            }
            $callback = $this->value[$method];
        } else {
            throw new EvaluationException('Needs object or array to call method "' . $method . '", but has ' . gettype($this->value), 1344350454);
        }
        if (!is_callable($callback)) {
            throw new EvaluationException('Method "' . $method . '" is not callable', 1344350374);
        }
        $argumentsCount = count($arguments);
        for ($i = 0; $i < $argumentsCount; $i++) {
            if ($arguments[$i] instanceof Context) {
                $arguments[$i] = $arguments[$i]->unwrap();
            }
        }
        return call_user_func_array($callback, $arguments);
    }

Usage Example

コード例 #1
0
 /**
  * Call a method if in whitelist
  *
  * @param string $method
  * @param array $arguments
  * @return mixed|void
  * @throws NotAllowedException
  */
 public function call($method, array $arguments = [])
 {
     if ($this->value === null || isset($this->whitelist[$method]) || isset($this->whitelist['*']) || $this->value instanceof ProtectedContextAwareInterface && $this->value->allowsCallOfMethod($method)) {
         return parent::call($method, $arguments);
     }
     throw new NotAllowedException('Method "' . $method . '" is not callable in untrusted context', 1369043080);
 }