public static function Map($data, $scheme, $vars = null) { if (is_null($data) || !file_exists($scheme)) { return null; } $scheme = json_decode(file_get_contents($scheme)); $result = new \stdClass(); if (is_null($scheme)) { return null; } $propMode = false; if (is_object($data)) { $propMode = true; } foreach ($scheme as $propertyName => $propertyValue) { if (!$propMode) { $value = isset($data[$propertyName]) ? $data[$propertyName] : null; } else { $value = property_exists($data, $propertyName) ? $data->{$propertyName} : null; } $name = $propertyName; if (strtolower($propertyValue->Type) === "string") { $result->{$name} = \BTRSchemeMap::ConvertString($value); } else { if (strtolower($propertyValue->Type) === "boolean") { $result->{$name} = \BTRSchemeMap::ConvertBoolean($value); } else { if (strtolower($propertyValue->Type) === "int") { $result->{$name} = intval($value); } else { if (strtolower($propertyValue->Type) === "list") { $haystack = !is_null($vars) && isset($vars[$propertyValue->Source]) ? $vars[$propertyValue->Source] : null; if (is_null($haystack)) { $result->{$name} = array(); } else { $got = array(); $currentCount = 0; $maximum = -1; if (property_exists($propertyValue, "Max")) { $maximum = $propertyValue->Max; } foreach ($value as $needle) { if (is_numeric($needle)) { $hayResult = \BTRSchemeMap::Pick($haystack, intval($needle)); if (!is_null($hayResult)) { $got[] = $hayResult; } $currentCount++; if ($maximum !== -1 && $currentCount === $maximum) { break; } } } $result->{$name} = $got; } } } } } } return $result; }