registerArgument('array', 'array', 'Array to search in', true); $this->registerArgument('key', 'string', 'Key to return its value', true); $this->registerArgument('subKey', 'string', 'If result of key access is an array, subkey can be used to fetch an element from this again', false, ''); } /** * Return array element by key. Accessed values must be scalar (string, int, float or double) * * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @throws Exception * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $array = $arguments['array']; $key = $arguments['key']; $subKey = $arguments['subKey']; $result = ''; if (is_array($array) && isset($array[$key])) { $result = $array[$key]; if (is_array($result) && $subKey && isset($result[$subKey])) { $result = $result[$subKey]; } } if (!is_scalar($result)) { throw new Exception('Only scalar return values (string, int, float or double) are supported.', 1382284105); } return $result; } }