protected function replace($data, $replacements = null)
    {
        if (!is_array($data) && !is_string($data)) {
            return $data;
        }

        if (!$replacements) {
            $replacements = $this->replacements();
            if (!$replacements) {
                return $data;
            }
        }

        if (is_array($data)) {
            foreach ($data as $key => &$value) {
                $value = $this->replace($value, $replacements);
            }
            return $data;
        }

        return str_replace(array_keys($replacements), array_values($replacements), $data);
    }