Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend JMSDiExtraBundle configuration making FosRestBundle/NelmioApiDocBundle optional #829

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion DependencyInjection/SonataUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
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;

/**
* @author Thomas Rabaix <[email protected]>
*/
class SonataUserExtension extends Extension
class SonataUserExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -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.
*
Expand Down