您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CommandAdminController.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Lc\SovBundle\Controller\Dashboard;
  3. use Lc\SovBundle\Controller\ControllerTrait;
  4. use Symfony\Bundle\FrameworkBundle\Console\Application;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Console\Input\ArrayInput;
  7. use Symfony\Component\Console\Output\BufferedOutput;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class CommandAdminController extends AbstractController
  12. {
  13. use ControllerTrait;
  14. /**
  15. * @Route("/admin/command/cache/clear", name="admin_command_cache_clear")
  16. */
  17. public function cacheClear(Request $request)
  18. {
  19. $this->doCommand('cache:clear');
  20. $this->addFlashTranslator('success', 'command.cacheClear');
  21. return $this->redirect($request->headers->get('referer'));
  22. }
  23. private function doCommand($command)
  24. {
  25. $kernel = $this->getKernel();
  26. $env = $kernel->getEnvironment();
  27. $application = new Application($kernel);
  28. $application->setAutoExit(false);
  29. $input = new ArrayInput(array(
  30. 'command' => $command,
  31. '--env' => $env
  32. ));
  33. $output = new BufferedOutput();
  34. $application->run($input, $output);
  35. $content = $output->fetch();
  36. //return new Response($content);
  37. }
  38. }