|
@@ -35,13 +35,14 @@ class Value
|
|
|
|
|
|
public function convert($array, $source, $dest, $type = '')
|
|
|
{
|
|
|
+ $default = $source;
|
|
|
$source = explode('.', $source);
|
|
|
$dest = explode('.', $dest);
|
|
|
- $extracted = $this->extracted($array, $source, $type);
|
|
|
+ $extracted = $this->extracted($array, $source, $default, $type);
|
|
|
return $this->transform($extracted, $dest);
|
|
|
}
|
|
|
|
|
|
- public function extracted(&$array, $source, $type = '')
|
|
|
+ public function extracted(&$array, $source, $default, $type = '')
|
|
|
{
|
|
|
$current = array_shift($source);
|
|
|
if (substr($current, -2) == '[]') {
|
|
@@ -49,7 +50,7 @@ class Value
|
|
|
$result = [];
|
|
|
if (isset($array[$current]) && is_array($array[$current])) {
|
|
|
foreach ($array[$current] as $item) {
|
|
|
- $sub = $this->extracted($item, $source, $type);
|
|
|
+ $sub = $this->extracted($item, $source, $default, $type);
|
|
|
if ($sub !== null) {
|
|
|
$result[] = $sub;
|
|
|
}
|
|
@@ -62,12 +63,12 @@ class Value
|
|
|
if (empty($source)) {
|
|
|
$result = $array[$current];
|
|
|
} else {
|
|
|
- return $this->extracted($array[$current], $source, $type);
|
|
|
+ return $this->extracted($array[$current], $source, $default, $type);
|
|
|
}
|
|
|
} elseif ($this->field->$current) {
|
|
|
$result = $this->field->$current;
|
|
|
} else {
|
|
|
- $result = $current;
|
|
|
+ $result = $default;
|
|
|
}
|
|
|
if ($type) {
|
|
|
$result .= '||' . $type;
|
|
@@ -102,12 +103,13 @@ class Value
|
|
|
if (!is_array($data)) {
|
|
|
return $data;
|
|
|
}
|
|
|
+ /*
|
|
|
foreach ($data as $k => $v) {
|
|
|
if (!is_array($v)) {
|
|
|
$temp = explode('||', $v);
|
|
|
$this->field->set($k, $temp[0]);
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
foreach ($data as $k => $v) {
|
|
|
if (is_array($v)) {
|
|
|
if (isset($v[0])) {
|
|
@@ -122,28 +124,28 @@ class Value
|
|
|
if (empty($temp[1])) {
|
|
|
$temp[1] = '';
|
|
|
}
|
|
|
+ $value = $temp[0];
|
|
|
+ $type = $temp[1];
|
|
|
+ if (strstr($value, '.')) {
|
|
|
+ $value = $this->extracted($data, explode('.', $value), $value);
|
|
|
+ }
|
|
|
$state = false;
|
|
|
# 临时特殊处理,以后封装
|
|
|
- if (strstr($temp[0], '\n')) {
|
|
|
- $array = explode('\n', $temp[0]);
|
|
|
- foreach ($array as &$v1) {
|
|
|
- if (isset($data[$v1])) {
|
|
|
- $v1 = $data[$v1];
|
|
|
- }
|
|
|
- }
|
|
|
- $temp[0] = implode("\n", $array);
|
|
|
- $state = true;
|
|
|
- } elseif (strstr($temp[0], '+')) {
|
|
|
- $array = explode('+', $temp[0]);
|
|
|
+ if (strstr($value, '\n')) {
|
|
|
+ $array = explode('\n', $value);
|
|
|
foreach ($array as &$v1) {
|
|
|
if (isset($data[$v1])) {
|
|
|
$v1 = $data[$v1];
|
|
|
}
|
|
|
}
|
|
|
- $temp[0] = implode('', $array);
|
|
|
+ $value = implode("\n", $array);
|
|
|
$state = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data[$k] = $this->field->value($value, $type, $state);
|
|
|
+ if (!$state && strpos($data[$k], '{') === 0) {
|
|
|
+ $data[$k] = Dever::json_decode($data[$k]);
|
|
|
}
|
|
|
- $data[$k] = $this->field->value($temp[0], $temp[1], $state);
|
|
|
$this->field->set($k, $data[$k]);
|
|
|
}
|
|
|
}
|