public render ( string $key, mixed $content = null, boolean $recursive = true, boolean $single = false ) : array | ||
$key | string | The name of the key from which you wish to extract the value |
$content | mixed | The array or Iterator that contains either the value or arrays of values |
$recursive | boolean | If TRUE, attempts to extract the key from deep nested arrays |
$single | boolean | If TRUE, returns only one value - always the first one - instead of an array of values |
Résultat | array |
public function render($key, $content = null, $recursive = true, $single = false)
{
if (null === $content) {
$content = $this->renderChildren();
}
try {
// extraction from Iterators could potentially use a getter method which throws
// exceptions - although this would be bad practice. Catch the exception here
// and turn it into a WARNING log message so that output does not break.
if (true === (bool) $recursive) {
$result = $this->recursivelyExtractKey($content, $key);
} else {
$result = $this->extractByKey($content, $key);
}
} catch (\Exception $error) {
GeneralUtility::sysLog($error->getMessage(), 'vhs', GeneralUtility::SYSLOG_SEVERITY_WARNING);
$result = [];
}
if (true === (bool) $single) {
return reset($result);
}
return $result;
}
/** * @test * @dataProvider nestedStructures */ public function recursivelyExtractKey($structure, $key, $expected) { $recursive = TRUE; $this->assertSame($expected, $this->fixture->render($key, $structure, $recursive)); }