public function setFormat($format)
    {
        if ($this->app['debug']) {
            if (false === is_string($format)) {
                throw new \InvalidArgumentException(sprintf('Format must be a string, got "%s".', is_object($format) ? get_class($format) : gettype($format)));
            }

            if (false === strpos($format, '%key%')) {
                throw new \InvalidArgumentException(sprintf('Format must contain "%%key%%", got "%s".', $format));
            }

            if (false === strrpos($format, '.')) {
                throw new \InvalidArgumentException(sprintf('Format missing extension, got "%s".', $format));
            }
        }

        $this->format = $format;

        if (strlen($format) > 5 && '.dist' === substr($format, -5)) {
            $format = substr($format, strrpos($format, '.', -6) + 1);
        } else {
            $format = substr($format, strrpos($format, '.') + 1);
        }

        switch ($format) {
            case 'json':
            case 'json.dist':
                $this->loader = new JsonLoader();
                break;
            case 'yml':
            case 'yml.dist':
            case 'yaml':
            case 'yaml.dist':
                if (false === class_exists('Symfony\\Component\\Yaml\\Yaml')) {
                    throw new \RuntimeException('Missing Symfony Yaml component.');
                }

                $this->loader = new YamlLoader();
                break;
            case 'php':
            case 'php.dist':
                $this->loader = new PHPLoader();
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Unsupported file format "%s".', $format));
        }

        $this->flushAll();

        return $this;
    }