diff --git a/DependencyInjection/SonataUserExtension.php b/DependencyInjection/SonataUserExtension.php index 1a5c18e5d..dd70410f9 100644 --- a/DependencyInjection/SonataUserExtension.php +++ b/DependencyInjection/SonataUserExtension.php @@ -15,6 +15,7 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -22,7 +23,7 @@ /** * @author Thomas Rabaix */ -class SonataUserExtension extends Extension +class SonataUserExtension extends Extension implements PrependExtensionInterface { /** * {@inheritdoc} @@ -368,6 +369,31 @@ public function configureMenu(array $config, ContainerBuilder $container) $container->getDefinition('sonata.user.profile.menu_builder')->replaceArgument(2, $config['profile']['menu']); } + /** + * {@inheritdoc} + */ + public function prepend(ContainerBuilder $container) + { + $bundles = $container->getParameter('kernel.bundles'); + + // Blacklist all API controllers when using JMSDiExtraBundle without NelmioApiDocBundle or FOSRestBundle. API + // controllers use annotations and would be warmed, throwing an exception. + if (isset($bundles['JMSDiExtraBundle']) && !isset($bundles['NelmioApiDocBundle'], $bundles['FOSRestBundle'])) { + $blacklistedControllers = array(); + foreach (glob(__DIR__.'/../Controller/Api/*.php', GLOB_NOSORT) as $filename) { + $blacklistedControllers[] = realpath($filename); + } + + if (!empty($blacklistedControllers)) { + $container->prependExtensionConfig('jms_di_extra', array( + 'cache_warmer' => array( + 'controller_file_blacklist' => $blacklistedControllers, + ), + )); + } + } + } + /** * Adds aliases for user & group managers depending on $managerType. *