2016-07-12 00:33:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2016-12-29 12:09:26 +01:00
|
|
|
* This file is part of the NelmioApiDocBundle package.
|
2016-07-12 00:33:55 +02:00
|
|
|
*
|
2016-12-29 12:09:26 +01:00
|
|
|
* (c) Nelmio
|
2016-07-12 00:33:55 +02:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-12-29 12:09:26 +01:00
|
|
|
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
2016-07-12 00:33:55 +02:00
|
|
|
|
2016-08-04 22:36:20 +02:00
|
|
|
use FOS\RestBundle\Controller\Annotations\ParamInterface;
|
2016-07-13 23:05:14 +02:00
|
|
|
use phpDocumentor\Reflection\DocBlockFactory;
|
2016-07-28 10:20:59 +02:00
|
|
|
use Swagger\Annotations\Swagger;
|
2016-07-12 00:33:55 +02:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2016-07-15 00:04:07 +02:00
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
2017-01-25 19:38:56 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
2016-07-15 00:04:07 +02:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
2016-07-12 00:33:55 +02:00
|
|
|
|
2017-01-25 19:38:56 +01:00
|
|
|
final class NelmioApiDocExtension extends Extension implements PrependExtensionInterface
|
2016-07-12 00:33:55 +02:00
|
|
|
{
|
2017-01-25 19:38:56 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function prepend(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$container->prependExtensionConfig('framework', ['property_info' => ['enabled' => true]]);
|
|
|
|
}
|
|
|
|
|
2016-07-12 00:33:55 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function load(array $configs, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$config = $this->processConfiguration(new Configuration(), $configs);
|
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
|
|
|
|
|
|
|
$loader->load('services.xml');
|
2016-07-13 23:05:14 +02:00
|
|
|
|
2016-11-30 14:08:10 +01:00
|
|
|
// Filter routes
|
2016-12-29 12:09:26 +01:00
|
|
|
$routeCollectionBuilder = $container->getDefinition('nelmio_api_doc.describers.route.filtered_route_collection_builder');
|
2016-11-30 14:08:10 +01:00
|
|
|
$routeCollectionBuilder->replaceArgument(0, $config['routes']['path_patterns']);
|
|
|
|
|
2016-08-04 22:27:10 +02:00
|
|
|
// Import services needed for each library
|
2017-01-23 19:46:38 +01:00
|
|
|
$loader->load('swagger_php.xml');
|
2016-08-04 22:27:10 +02:00
|
|
|
if (class_exists(DocBlockFactory::class)) {
|
|
|
|
$loader->load('php_doc.xml');
|
2016-07-28 10:20:59 +02:00
|
|
|
}
|
2016-08-04 22:36:20 +02:00
|
|
|
if (interface_exists(ParamInterface::class)) {
|
|
|
|
$loader->load('fos_rest.xml');
|
|
|
|
}
|
2016-07-29 10:22:40 +02:00
|
|
|
|
|
|
|
$bundles = $container->getParameter('kernel.bundles');
|
|
|
|
// ApiPlatform support
|
|
|
|
if (isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Core\Documentation\Documentation')) {
|
|
|
|
$loader->load('api_platform.xml');
|
|
|
|
}
|
2017-01-25 18:53:19 +01:00
|
|
|
|
|
|
|
// Import the base configuration
|
|
|
|
$container->getDefinition('nelmio_api_doc.describers.config')->replaceArgument(0, $config['documentation']);
|
2016-07-12 00:33:55 +02:00
|
|
|
}
|
|
|
|
}
|