commande create controller symfony code example
Example 1: run command from controller symfony
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'command' => 'swiftmailer:spool:send',
'fooArgument' => 'barValue',
'--message-limit' => $messages,
]);
$output = new BufferedOutput();
$application->run($input, $output);
$content = $output->fetch();
Example 2: Basic Symfony Controller
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class LuckyController
{
public function number(int $max): Response
{
$number = random_int(0, $max);
return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}