public function getData($key = '', $index = null)
{
if ('' === $key) {
return $this->data;
}
$default = null;
// accept a/b/c as ['a']['b']['c']
// Not !== false no need '/a/b always return null
if (strpos($key, '/')) {
$keyArray = explode('/', $key);
$data = $this->data;
foreach ($keyArray as $i => $k) {
if ($k === '') {
return $default;
}
if (is_array($data)) {
if (!isset($data[$k])) {
return $default;
}
$data = $data[$k];
}
}
return $data;
}
// legacy functionality for $index
if (isset($this->data[$key])) {
if (is_null($index)) {
return $this->data[$key];
}
$value = $this->data[$key];
if (is_array($value)) {
if (isset($value[$index])) {
return $value[$index];
}
return null;
} elseif (is_string($value)) {
$array = explode(PHP_EOL, $value);
return isset($array[$index]) && (!empty($array[$index]) || strlen($array[$index]) > 0) ? $array[$index] : null;
} elseif ($value instanceof Object) {
return $value->getData($index);
}
return $default;
}
return $default;
}