*/ class SymfonyCacheManager { protected KernelInterface $kernel; protected HttpClientInterface $httpClient; protected UrlGeneratorInterface $urlGenerator; public function __construct(KernelInterface $kernel, HttpClientInterface $httpClient, UrlGeneratorInterface $urlGenerator) { $this->kernel = $kernel; $this->httpClient = $httpClient; $this->urlGenerator = $urlGenerator; } public function cleanRouting() { $finder = new Finder(); $finder ->in($this->kernel->getCacheDir()) ->depth('== 0') ->name('url_*.php*') ; $pingUrl = $this->urlGenerator->generate('_ping', [], UrlGeneratorInterface::ABSOLUTE_URL); foreach ($finder as $file) { unlink((string) $file->getPathname()); } try { // Hack: used to regenerate cache of url generator $this->httpClient->request('POST', $pingUrl); } catch (ClientException $e) { } } public function cleanAll(OutputInterface $output = null) { $application = new Application($this->kernel); $application->setAutoExit(false); if (null === $output) { $output = new BufferedOutput(); } $input = new ArrayInput([ 'command' => 'cache:clear', '-e' => $this->kernel->getEnvironment(), '--no-warmup' => null, '--ansi' => null, ]); $application->run($input, $output); $input = new ArrayInput([ 'command' => 'cache:warmup', '-e' => $this->kernel->getEnvironment(), ]); $application->run($input, $output); } }