public static function reorder(array $data, array $order, $throwExceptionIfKeyNotFound = false, $throwExceptionIfExtraData = false) {
        $result = array();
        foreach($order as $orderedKey) {
            if (array_key_exists($orderedKey, $data)) {
                $result[$orderedKey] = $data[$orderedKey];
                unset($data[$orderedKey]);
            } elseif ($throwExceptionIfKeyNotFound) {
                throw new KeyNotFoundException("Key '".$orderedKey."' not found in data.");
            }
        }
        if (empty($data)) {
            return $result;
        }
        if ($throwExceptionIfExtraData) {
            throw new ExtraDataException("Extra data found.");
        }
        foreach ($data as $key => $value) {
            $result[$key] = $value;
        }
        return $result;
    }