<?php
namespace App\Controller\Back;
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
use SensioLabs\AnsiConverter\Theme\SolarizedTheme;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
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;
/**
* @Route("/admin/cron")
*/
class CronController extends AbstractController
{
/**
* @Route("", name="back_cron_index")
* @return Response
*/
public function index(): Response
{
return $this->render('back/cron/index.html.twig', []);
}
/**
* @Route("/images/upload", name="back_cron_images_upload")
*/
public function imageUpload(KernelInterface $kernel): Response
{
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'command' => 'images:upload'
]);
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output);
// return the output, don't use if you used NullOutput()
$theme = new SolarizedTheme();
$converter = new AnsiToHtmlConverter();
$content = $output->fetch();
// return new Response($converter->convert($content));
return $this->json([
'content' => $converter->convert($content),
]);
}
}