1
0
mirror of https://github.com/flarum/core.git synced 2025-07-24 10:11:43 +02:00
Files
php-flarum/src/Foundation/Console/CacheClearCommand.php
2021-03-02 16:21:30 -05:00

75 lines
1.5 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation\Console;
use Flarum\Console\AbstractCommand;
use Flarum\Foundation\Event\ClearingCache;
use Flarum\Foundation\Paths;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Contracts\Events\Dispatcher;
class CacheClearCommand extends AbstractCommand
{
/**
* @var Store
*/
protected $cache;
/**
* @var Dispatcher
*/
protected $events;
/**
* @var Paths
*/
protected $paths;
/**
* @param Store $cache
* @param Paths $paths
*/
public function __construct(Store $cache, Dispatcher $events, Paths $paths)
{
$this->cache = $cache;
$this->events = $events;
$this->paths = $paths;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('cache:clear')
->setDescription('Remove all temporary and generated files');
}
/**
* {@inheritdoc}
*/
protected function fire()
{
$this->info('Clearing the cache...');
$this->cache->flush();
$storagePath = $this->paths->storage;
array_map('unlink', glob($storagePath.'/formatter/*'));
array_map('unlink', glob($storagePath.'/locale/*'));
array_map('unlink', glob($storagePath.'/views/*'));
$this->events->dispatch(new ClearingCache);
}
}