public static function flatten($data, $seperator = '_', $prefix = null, array &$result = null)
    {
        if ($result === null) {
            $result = array();
        }

        if ($data instanceof \stdClass) {
            $data = (array) $data;
        } elseif (!is_array($data)) {
            throw new InvalidArgumentException('Data must be either an stdClass or array');
        }

        foreach ($data as $key => $value) {
            if ($value instanceof \stdClass || is_array($value)) {
                self::flatten($value, $seperator, $prefix . $key . $seperator, $result);
            } else {
                $result[$prefix . $key] = $value;
            }
        }

        return $result;
    }