Created
June 10, 2025 18:26
-
-
Save DazWilkin/3a460000fa0b327be7882e90f8e12c6d to your computer and use it in GitHub Desktop.
Stackoverflow: 79660352
This file contains hidden or 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\Controller; | |
| use Symfony\Bundle\FrameworkBundle\Console\Application; | |
| use Symfony\Component\Console\Input\ArrayInput; | |
| use Symfony\Component\Console\Output\BufferedOutput; | |
| use Symfony\Component\HttpFoundation\Response; | |
| use Symfony\Component\HttpKernel\KernelInterface; | |
| use Symfony\Component\Routing\Annotation\Route; | |
| class CommandController | |
| { | |
| #[Route('/secret/run-command')] | |
| public function runCommand(KernelInterface $kernel): Response | |
| { | |
| $application = new Application($kernel); | |
| $application->setAutoExit(false); | |
| $input = new ArrayInput([ | |
| 'command' => 'cache:clear', | |
| // pass arguments and options | |
| // '--env' => 'prod', | |
| ]); | |
| $output = new BufferedOutput(); | |
| $application->run($input, $output); | |
| $content = $output->fetch(); | |
| return new Response($content); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment