Created
May 31, 2020 14:22
-
-
Save J7mbo/cb7c343fc431e9000b59310de22f244e to your computer and use it in GitHub Desktop.
php-symfony-controllers-as-services-blog-4.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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