Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 101aeb4

Browse files
authored
Merge pull request #12 from modulusphp/feature/clear-commands
Feature/clear commands
2 parents 5fb4649 + f84e2bd commit 101aeb4

4 files changed

Lines changed: 189 additions & 3 deletions

File tree

Commands/ClearLogs.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Modulus\Console\Commands;
4+
5+
use Modulus\Console\ModulusCLI;
6+
use Modulus\Support\Filesystem;
7+
use AtlantisPHP\Console\Command;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class ClearLogs extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'clear:logs';
19+
20+
/**
21+
* The full command description.
22+
*
23+
* @var string
24+
*/
25+
protected $help = 'This command allows you to clear all application logs';
26+
27+
/**
28+
* The descriptions of the console commands.
29+
*
30+
* @var array
31+
*/
32+
protected $descriptions = [
33+
'clear:logs' => 'Clear all logs',
34+
];
35+
36+
/**
37+
* @param InputInterface $input
38+
* @param OutputInterface $output
39+
*
40+
* @return void
41+
*/
42+
protected function execute(InputInterface $input, OutputInterface $output)
43+
{
44+
$searchDir = ModulusCLI::$appdir . 'storage' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR;
45+
46+
$logs = glob($searchDir . '*.log');
47+
48+
if (count($logs) < 1) {
49+
return $output->writeln('Nothing to remove');
50+
}
51+
52+
foreach($logs as $log) {
53+
try {
54+
Filesystem::delete($log);
55+
} catch (\Exception $e) {
56+
return $output->writeln($e->getMessage());
57+
}
58+
}
59+
60+
return $output->writeln('<info>Cleared logs</info>');
61+
}
62+
}

Commands/ClearSessions.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Modulus\Console\Commands;
4+
5+
use Modulus\Console\ModulusCLI;
6+
use Modulus\Support\Filesystem;
7+
use AtlantisPHP\Console\Command;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class ClearSessions extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'clear:sessions';
19+
20+
/**
21+
* The full command description.
22+
*
23+
* @var string
24+
*/
25+
protected $help = 'This command allows you to clear all user sessions';
26+
27+
/**
28+
* The descriptions of the console commands.
29+
*
30+
* @var array
31+
*/
32+
protected $descriptions = [
33+
'clear:sessions' => 'Clear all user sessions',
34+
];
35+
36+
/**
37+
* @param InputInterface $input
38+
* @param OutputInterface $output
39+
*
40+
* @return void
41+
*/
42+
protected function execute(InputInterface $input, OutputInterface $output)
43+
{
44+
$searchDir = ModulusCLI::$appdir . 'storage' . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'sessions' . DIRECTORY_SEPARATOR;
45+
46+
$sessions = glob($searchDir . '*.*.txt');
47+
48+
if (count($sessions) < 1) {
49+
return $output->writeln('Nothing to remove');
50+
}
51+
52+
foreach($sessions as $session) {
53+
try {
54+
Filesystem::delete($session);
55+
} catch (\Exception $e) {
56+
return $output->writeln($e->getMessage());
57+
}
58+
}
59+
60+
return $output->writeln('<info>Cleared sesseions</info>');
61+
}
62+
}

Commands/ClearViews.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Modulus\Console\Commands;
4+
5+
use Modulus\Console\ModulusCLI;
6+
use Modulus\Support\Filesystem;
7+
use AtlantisPHP\Console\Command;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class ClearViews extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'clear:views';
19+
20+
/**
21+
* The full command description.
22+
*
23+
* @var string
24+
*/
25+
protected $help = 'This command allows you to clear all compiled view files';
26+
27+
/**
28+
* The descriptions of the console commands.
29+
*
30+
* @var array
31+
*/
32+
protected $descriptions = [
33+
'clear:views' => 'Clear all compiled view files',
34+
];
35+
36+
/**
37+
* @param InputInterface $input
38+
* @param OutputInterface $output
39+
*
40+
* @return void
41+
*/
42+
protected function execute(InputInterface $input, OutputInterface $output)
43+
{
44+
$searchDir = ModulusCLI::$appdir . 'storage' . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
45+
$extension = config('view.extension');
46+
47+
$views = glob($searchDir . '*@*' . $extension);
48+
49+
if (count($views) < 1) {
50+
return $output->writeln('Nothing to remove');
51+
}
52+
53+
foreach($views as $view) {
54+
try {
55+
Filesystem::delete($view);
56+
} catch (\Exception $e) {
57+
return $output->writeln($e->getMessage());
58+
}
59+
}
60+
61+
return $output->writeln('<info>Cleared views</info>');
62+
}
63+
}

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "modulusphp/console",
33
"description": "Directives for modulusPHP",
4-
"version": "1.9.4",
4+
"version": "1.9.5",
55
"license": "MIT",
66
"type": "package",
77
"authors": [
@@ -12,8 +12,7 @@
1212
],
1313
"require": {
1414
"atlantisphp/console": "^1.0",
15-
"modulusphp/scaffolding": "^1.9.2",
16-
"peppeocchi/php-cron-scheduler": "^2.3"
15+
"modulusphp/scaffolding": "^1.9.2"
1716
},
1817
"autoload": {
1918
"psr-4": {

0 commit comments

Comments
 (0)