2012-04-11 20:00:21 +02:00
|
|
|
<?php
|
|
|
|
|
2012-04-13 11:03:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the NelmioApiDocBundle.
|
|
|
|
*
|
|
|
|
* (c) Nelmio <hello@nelm.io>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-04-12 18:37:42 +02:00
|
|
|
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
2012-04-11 20:00:21 +02:00
|
|
|
|
2014-06-17 17:05:00 -07:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
2014-07-21 10:26:06 -07:00
|
|
|
use Symfony\Component\DependencyInjection\Definition;
|
2012-04-11 20:00:21 +02:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2012-04-12 20:34:19 +02:00
|
|
|
use Symfony\Component\Config\Definition\Processor;
|
2012-04-11 20:00:21 +02:00
|
|
|
|
2012-04-13 10:05:32 +02:00
|
|
|
class NelmioApiDocExtension extends Extension
|
2012-04-11 20:00:21 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function load(array $configs, ContainerBuilder $container)
|
|
|
|
{
|
2012-04-12 20:34:19 +02:00
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration();
|
|
|
|
$config = $processor->processConfiguration($configuration, $configs);
|
|
|
|
|
2013-04-08 11:44:43 +02:00
|
|
|
$container->setParameter('nelmio_api_doc.motd.template', $config['motd']['template']);
|
2014-01-16 13:42:37 +01:00
|
|
|
$container->setParameter('nelmio_api_doc.exclude_sections', $config['exclude_sections']);
|
2012-04-12 20:34:19 +02:00
|
|
|
$container->setParameter('nelmio_api_doc.api_name', $config['name']);
|
2012-07-18 13:18:26 +02:00
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']);
|
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']);
|
2012-12-11 17:59:03 -08:00
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.accept_type', $config['sandbox']['accept_type']);
|
2014-05-21 15:59:55 +02:00
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.body_format.formats', $config['sandbox']['body_format']['formats']);
|
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.body_format.default_format', $config['sandbox']['body_format']['default_format']);
|
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.request_format.method', $config['sandbox']['request_format']['method']);
|
2012-10-17 15:27:20 +04:00
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.request_format.default_format', $config['sandbox']['request_format']['default_format']);
|
2014-05-17 22:45:30 +02:00
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.request_format.formats', $config['sandbox']['request_format']['formats']);
|
2012-04-12 20:34:19 +02:00
|
|
|
|
2012-04-11 20:00:21 +02:00
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
2012-04-12 12:50:20 +02:00
|
|
|
$loader->load('formatters.xml');
|
2012-04-11 20:00:21 +02:00
|
|
|
$loader->load('services.xml');
|
2012-08-10 13:55:35 +02:00
|
|
|
|
2012-10-17 18:44:14 +04:00
|
|
|
if ($config['request_listener']['enabled']) {
|
|
|
|
$container->setParameter('nelmio_api_doc.request_listener.parameter', $config['request_listener']['parameter']);
|
2012-10-17 17:12:36 +04:00
|
|
|
$loader->load('request_listener.xml');
|
|
|
|
}
|
|
|
|
|
2012-08-10 13:55:35 +02:00
|
|
|
if (isset($config['sandbox']['authentication'])) {
|
|
|
|
$container->setParameter('nelmio_api_doc.sandbox.authentication', $config['sandbox']['authentication']);
|
|
|
|
}
|
2013-11-14 10:59:37 +01:00
|
|
|
|
|
|
|
// backwards compatibility for Symfony2.1 https://github.com/nelmio/NelmioApiDocBundle/issues/231
|
|
|
|
if (!interface_exists('\Symfony\Component\Validator\MetadataFactoryInterface')) {
|
|
|
|
$container->setParameter('nelmio_api_doc.parser.validation_parser.class', 'Nelmio\ApiDocBundle\Parser\ValidationParserLegacy');
|
|
|
|
}
|
2014-06-17 17:05:00 -07:00
|
|
|
|
|
|
|
$container->setParameter('nelmio_api_doc.swagger.base_path', $config['swagger']['api_base_path']);
|
|
|
|
$container->setParameter('nelmio_api_doc.swagger.swagger_version', $config['swagger']['swagger_version']);
|
|
|
|
$container->setParameter('nelmio_api_doc.swagger.api_version', $config['swagger']['api_version']);
|
|
|
|
$container->setParameter('nelmio_api_doc.swagger.info', $config['swagger']['info']);
|
|
|
|
|
2014-07-21 10:26:06 -07:00
|
|
|
if ($config['cache']['enabled'] === true) {
|
|
|
|
$arguments = $container->getDefinition('nelmio_api_doc.extractor.api_doc_extractor')->getArguments();
|
|
|
|
$caching = new Definition('Nelmio\ApiDocBundle\Extractor\CachingApiDocExtractor');
|
2014-08-20 10:26:43 -07:00
|
|
|
$arguments[] = $config['cache']['file'];
|
|
|
|
$arguments[] = '%kernel.debug%';
|
2014-07-21 10:26:06 -07:00
|
|
|
$caching->setArguments($arguments);
|
|
|
|
$container->setDefinition('nelmio_api_doc.extractor.api_doc_extractor', $caching);
|
|
|
|
}
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|
2013-09-21 23:31:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getNamespace()
|
|
|
|
{
|
|
|
|
return 'http://nelmio.github.io/schema/dic/nelmio_api_doc';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getXsdValidationBasePath()
|
|
|
|
{
|
|
|
|
return __DIR__ . '/../Resources/config/schema';
|
|
|
|
}
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|