From fc5b8c4e63446b134fbc0e4c77d68f5f58e6cd24 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 10 Aug 2012 13:55:35 +0200 Subject: [PATCH] Add optional api_key parameter to sandbox --- DependencyInjection/Configuration.php | 13 ++++++++ DependencyInjection/NelmioApiDocExtension.php | 4 +++ Formatter/HtmlFormatter.php | 26 ++++++++++++---- README.md | 3 ++ Resources/config/formatters.xml | 4 +++ Resources/public/css/screen.css | 6 ++++ Resources/views/layout.html.twig | 31 +++++++++++++++++++ 7 files changed, 81 insertions(+), 6 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1908db1..7a03f78 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -28,6 +28,19 @@ class Configuration implements ConfigurationInterface ->children() ->scalarNode('enabled')->defaultTrue()->end() ->scalarNode('endpoint')->defaultValue('/app_dev.php')->end() + ->arrayNode('authentication') + ->children() + ->scalarNode('name')->isRequired()->end() + ->scalarNode('delivery') + ->isRequired() + ->validate() + // header|query|request, but only query is implemented for now + ->ifNotInArray(array('query')) + ->thenInvalid("Unknown authentication delivery type '%s'.") + ->end() + ->end() + ->end() + ->end() ->end() ->end() ->end(); diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 1ecae53..321a2cc 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -36,5 +36,9 @@ class NelmioApiDocExtension extends Extension $loader->load('formatters.xml'); $loader->load('request_listener.xml'); $loader->load('services.xml'); + + if (isset($config['sandbox']['authentication'])) { + $container->setParameter('nelmio_api_doc.sandbox.authentication', $config['sandbox']['authentication']); + } } } diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 71edc7b..6ab6b15 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -15,6 +15,11 @@ use Symfony\Component\Templating\EngineInterface; class HtmlFormatter extends AbstractFormatter { + /** + * @var array + */ + private $authentication; + /** * @var string */ @@ -35,6 +40,14 @@ class HtmlFormatter extends AbstractFormatter */ private $engine; + /** + * @param array $authentication + */ + public function setAuthentication(array $authentication = null) + { + $this->authentication = $authentication; + } + /** * @param string $apiName */ @@ -95,12 +108,13 @@ class HtmlFormatter extends AbstractFormatter private function getGlobalVars() { return array( - 'apiName' => $this->apiName, - 'endpoint' => $this->endpoint, - 'enableSandbox' => $this->enableSandbox, - 'date' => date(DATE_RFC822), - 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), - 'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'), + 'apiName' => $this->apiName, + 'authentication' => $this->authentication, + 'endpoint' => $this->endpoint, + 'enableSandbox' => $this->enableSandbox, + 'date' => date(DATE_RFC822), + 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), + 'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'), ); } } diff --git a/README.md b/README.md index ae19234..cb23ee7 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,9 @@ configure this sandbox using the following parameters: # app/config/config.yml nelmio_api_doc: sandbox: + authentication: # default null, if set, the value of the api key is read from the query string and appended to every sandbox api call + name: access_token + delivery: query # only query delivery is supported for now enabled: true # default: true, you can set this parameter to `false` to disable the sandbox endpoint: http://sandbox.example.com/ # default: /app_dev.php, use this parameter to define which URL to call through the sandbox diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index 21aa93b..42f189c 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -9,6 +9,7 @@ Nelmio\ApiDocBundle\Formatter\MarkdownFormatter Nelmio\ApiDocBundle\Formatter\SimpleFormatter Nelmio\ApiDocBundle\Formatter\HtmlFormatter + null @@ -35,6 +36,9 @@ %nelmio_api_doc.sandbox.endpoint% + + %nelmio_api_doc.sandbox.authentication% + diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index 86fc9e0..4b73b61 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -141,12 +141,18 @@ table tbody tr:last-child td { #header h1 { font-size: 1.2em; + float: left; } #header a { text-decoration: none; } +#api_key_wrapper { + float: right; + padding: 10px 0 10px 0; +} + #colophon { margin: 0 15px 40px 15px; padding: 10px 0; diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index aa4768c..306befb 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -15,6 +15,12 @@