Merge pull request #86 from vslinko/allow-to-disable-inline-doc

Make request listener configurable
This commit is contained in:
Jordi Boggiano 2012-10-19 01:05:37 -07:00
commit 28f059fff0
4 changed files with 25 additions and 3 deletions

View File

@ -23,6 +23,17 @@ class Configuration implements ConfigurationInterface
->root('nelmio_api_doc')
->children()
->scalarNode('name')->defaultValue('API documentation')->end()
->arrayNode('request_listener')
->beforeNormalization()
->ifTrue(function ($a) { return is_bool($a); })
->then(function ($a) { return array('enabled' => $a); })
->end()
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultTrue()->end()
->scalarNode('parameter')->defaultValue('_doc')->end()
->end()
->end()
->arrayNode('sandbox')
->addDefaultsIfNotSet()
->children()

View File

@ -36,9 +36,13 @@ class NelmioApiDocExtension extends Extension
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('formatters.xml');
$loader->load('request_listener.xml');
$loader->load('services.xml');
if ($config['request_listener']['enabled']) {
$container->setParameter('nelmio_api_doc.request_listener.parameter', $config['request_listener']['parameter']);
$loader->load('request_listener.xml');
}
if (isset($config['sandbox']['authentication'])) {
$container->setParameter('nelmio_api_doc.sandbox.authentication', $config['sandbox']['authentication']);
}

View File

@ -30,10 +30,16 @@ class RequestListener
*/
protected $formatter;
public function __construct(ApiDocExtractor $extractor, FormatterInterface $formatter)
/**
* @var string
*/
protected $parameter;
public function __construct(ApiDocExtractor $extractor, FormatterInterface $formatter, $parameter)
{
$this->extractor = $extractor;
$this->formatter = $formatter;
$this->parameter = $parameter;
}
/**
@ -47,7 +53,7 @@ class RequestListener
$request = $event->getRequest();
if (!$request->query->get('_doc')) {
if (!$request->query->has($this->parameter)) {
return;
}

View File

@ -11,6 +11,7 @@
<service id="nelmio_api_doc.event_listener.request" class="%nelmio_api_doc.event_listener.request.class%">
<argument type="service" id="nelmio_api_doc.extractor.api_doc_extractor" />
<argument type="service" id="nelmio_api_doc.formatter.html_formatter" />
<argument>%nelmio_api_doc.request_listener.parameter%</argument>
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" />
</service>
</services>