Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save J7mbo/cb7c343fc431e9000b59310de22f244e to your computer and use it in GitHub Desktop.
Save J7mbo/cb7c343fc431e9000b59310de22f244e to your computer and use it in GitHub Desktop.
php-symfony-controllers-as-services-blog-4.php
<?php
namespace App;
use Symfony\Component\DependencyInjection\{Compiler\CompilerPassInterface, ContainerBuilder};
class ControllersAsServices implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// Look at the controllers we get...
foreach ($container->getDefinitions() as $definition) {
// See if it contains "Controller".
if (strpos($definition->getClass(), "Controller") === false) {
continue;
}
// Add the required tag and make it public so Symfony doesn't complain.
$definition->addTag("controller.service_arguments");
$definition->setPublic(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment