Skip to content

Instantly share code, notes, and snippets.

@htuscher
Created March 25, 2020 16:05
Show Gist options
  • Save htuscher/147c26ce712c99a5147e4f0ee03f0691 to your computer and use it in GitHub Desktop.
Save htuscher/147c26ce712c99a5147e4f0ee03f0691 to your computer and use it in GitHub Desktop.
Override Symfony clear cache command for Shopware6
<?php
declare(strict_types=1);
/***************************************************************
* Copyright notice
*
* (c) 2020 Hans Hoechtl <hhoechtl@1drop.de>
* All rights reserved
***************************************************************/
namespace Onedrop\Platform\Command;
use Shopware\Core\Framework\Adapter\Cache\CacheClearer;
use Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
class ClearCacheCommand extends CacheClearCommand
{
protected static $defaultName = 'cache:clear';
/**
* @var CacheClearer
*/
private $shopwareCacheClearer;
/**
* ClearCacheCommand constructor.
*
* @param CacheClearer $cacheClearer
* @param CacheClearerInterface $cacheClearer
* @param Filesystem|null $filesystem
*/
public function __construct(CacheClearer $shopwareCacheClearer, CacheClearerInterface $cacheClearer, Filesystem $filesystem = null)
{
$this->shopwareCacheClearer = $shopwareCacheClearer;
parent::__construct($cacheClearer, $filesystem);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->shopwareCacheClearer->clear();
return parent::execute($input, $output);
}
}
services:
Onedrop\Platform\Command\ClearCacheCommand:
arguments:
- '@Shopware\Core\Framework\Adapter\Cache\CacheClearer'
- '@cache_clearer'
- '@filesystem'
tags:
- {name: 'console.command', command: 'cache:clear'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment