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+ }
0 commit comments