Skip to content

Instantly share code, notes, and snippets.

@DazWilkin
Created June 10, 2025 18:26
Show Gist options
  • Save DazWilkin/3a460000fa0b327be7882e90f8e12c6d to your computer and use it in GitHub Desktop.
Save DazWilkin/3a460000fa0b327be7882e90f8e12c6d to your computer and use it in GitHub Desktop.
Stackoverflow: 79660352
<?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