From a9f0613ceebd7c53a4c80e080a8a73a368b177c6 Mon Sep 17 00:00:00 2001 From: Josh Hall-Bachner Date: Tue, 4 Jun 2013 15:30:07 -0700 Subject: [PATCH] Added a configuration parameter to determine the default body format. --- DependencyInjection/Configuration.php | 4 ++++ DependencyInjection/NelmioApiDocExtension.php | 1 + Formatter/HtmlFormatter.php | 14 +++++++++++ Resources/config/formatters.xml | 3 +++ Resources/views/layout.html.twig | 24 +++++++++---------- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ec79579..f049223 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -46,6 +46,10 @@ class Configuration implements ConfigurationInterface ->scalarNode('enabled')->defaultTrue()->end() ->scalarNode('endpoint')->defaultNull()->end() ->scalarNode('accept_type')->defaultValue('')->end() + ->enumNode('body_format') + ->values(array('form', 'json')) + ->defaultValue('form') + ->end() ->arrayNode('request_format') ->addDefaultsIfNotSet() ->children() diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index ce10263..d26a39d 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -34,6 +34,7 @@ class NelmioApiDocExtension extends Extension $container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']); $container->setParameter('nelmio_api_doc.sandbox.request_format.method', $config['sandbox']['request_format']['method']); $container->setParameter('nelmio_api_doc.sandbox.accept_type', $config['sandbox']['accept_type']); + $container->setParameter('nelmio_api_doc.sandbox.body_format', $config['sandbox']['body_format']); $container->setParameter('nelmio_api_doc.sandbox.request_format.default_format', $config['sandbox']['request_format']['default_format']); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index d4520fc..750f82c 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -50,6 +50,11 @@ class HtmlFormatter extends AbstractFormatter */ private $acceptType; + /** + * @var string + */ + private $bodyFormat; + /** * @var array */ @@ -108,6 +113,14 @@ class HtmlFormatter extends AbstractFormatter $this->acceptType = $acceptType; } + /** + * @param string $bodyFormat + */ + public function setBodyFormat($bodyFormat) + { + $this->bodyFormat = $bodyFormat; + } + /** * @param string $method */ @@ -179,6 +192,7 @@ class HtmlFormatter extends AbstractFormatter 'enableSandbox' => $this->enableSandbox, 'requestFormatMethod' => $this->requestFormatMethod, 'acceptType' => $this->acceptType, + 'bodyFormat' => $this->bodyFormat, 'defaultRequestFormat' => $this->defaultRequestFormat, 'date' => date(DATE_RFC822), 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index 8a21d80..53c31be 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -49,6 +49,9 @@ %nelmio_api_doc.sandbox.accept_type% + + %nelmio_api_doc.sandbox.body_format% + %nelmio_api_doc.sandbox.authentication% diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 0f25f43..7631331 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -16,10 +16,10 @@