protected function flattenArray(array $array, $separator = null)
    {
        $flattened = array();

        if (is_null($separator)) {
            $separator = $this->separator;
        }

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $flattened = array_merge($flattened, $this->flattenArray($value, $key.$separator));
            } else {
                $flattened[trim($separator.$key, $this->separator)] = $value;
            }
        }

        return $flattened;
    }