for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Ship\Command;
use Rudra\Cli\ConsoleFacade as Cli;
use Rudra\Auth\AuthFacade as Auth;
use Rudra\Container\Facades\Request;
class CacheClearCommand
{
public function actionIndex(): void
Cli::printer("Enter cache type (empty for all): ", "magneta");
$type = str_replace(PHP_EOL, "", Cli::reader());
$folderPath = !empty($type)
? dirname(__DIR__, 2) . "/cache/$type"
: dirname(__DIR__, 2) . "/cache";
if ($this->deleteDirectory($folderPath)) {
Cli::printer(!empty($type)
? "Cache $type was cleared" . PHP_EOL
: "Cache was cleared" . PHP_EOL, "light_green");
} else {
? "Cache type '$type' does not exist." . PHP_EOL
: "Cache directory does not exist." . PHP_EOL, "red");
}
/**
* @param string $dir
* @return bool
*/
private function deleteDirectory(string $dir): bool
if (!is_dir($dir)) {
return false;
foreach (glob($dir . '/*') as $file) {
is_dir($file) ? $this->deleteDirectory($file) : unlink($file);
return rmdir($dir);