/** * @param array $row * @param string $propertyPath * * @return mixed */ protected function extractValueByPropertyPath(array &$row, $propertyPath) { $result = null; $properties = ConfigUtil::explodePropertyPath($propertyPath); $lastIndex = count($properties) - 1; $i = 0; $path = []; $currentRow =& $row; while ($i <= $lastIndex) { $property = $properties[$i]; if (null === $currentRow || !array_key_exists($property, $currentRow)) { break; } if ($i === $lastIndex) { // get property value $result = $currentRow[$property]; // remove extracted property unset($currentRow[$property]); // remove empty containers $p = count($path) - 1; while ($p >= 0) { $currentRow =& $path[$p][0]; if (!empty($currentRow[$path[$p][1]])) { break; } unset($currentRow[$path[$p][1]]); $p--; } break; } $path[] = [&$currentRow, $property]; $currentRow =& $currentRow[$property]; $i++; } return $result; }
/** * @param array $config * @param string $propertyPath * @param array $fieldConfig * * @return array */ protected function applyPropertyPathConfig(array $config, $propertyPath, array &$fieldConfig) { $properties = ConfigUtil::explodePropertyPath($propertyPath); $currentConfig =& $config; $currentProperty = $properties[0]; $this->applyPropertyConfig($currentConfig, $currentProperty); $count = count($properties); if ($count > 1) { $i = 1; while ($i < $count) { $currentConfig =& $currentConfig[ConfigUtil::FIELDS][$properties[$i - 1]]; if (null === $currentConfig) { $currentConfig = []; } $currentProperty = $properties[$i]; $this->applyPropertyConfig($currentConfig, $currentProperty); $i++; } } if (array_key_exists(ConfigUtil::DATA_TRANSFORMER, $fieldConfig)) { $currentConfig[ConfigUtil::FIELDS][$currentProperty][ConfigUtil::DATA_TRANSFORMER] = $fieldConfig[ConfigUtil::DATA_TRANSFORMER]; unset($fieldConfig[ConfigUtil::DATA_TRANSFORMER]); } return $config; }