Completed
Pull Request — master (#16)
by
unknown
01:12
created

RouteTranslationsClearCommand::handle()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 4
nc 6
nop 0
1
<?php
2
3
namespace RichanFongdasen\I18n\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use RichanFongdasen\I18n\Traits\TranslatedRouteCommandContext;
8
9
class RouteTranslationsClearCommand extends Command
10
{
11
    use TranslatedRouteCommandContext;
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'route:trans:clear';
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Remove the translated route cache files for each locale';
24
    /**
25
     * The filesystem instance.
26
     *
27
     * @var \Illuminate\Filesystem\Filesystem
28
     */
29
    protected $files;
30
31
    /**
32
     * Create a new route clear command instance.
33
     *
34
     * @param \Illuminate\Filesystem\Filesystem $files
35
     */
36
    public function __construct(Filesystem $files)
37
    {
38
        parent::__construct();
39
        $this->files = $files;
40
    }
41
42
    /**
43
     * Execute the console command.
44
     *
45
     * @return void
46
     */
47
    public function handle()
48
    {
49
        foreach ($this->getSupportedLocales() as $locale => $localeValue) {
50
            $path = $this->makeLocaleRoutesPath($locale);
51
            if ($this->files->exists($path)) {
52
                $this->files->delete($path);
53
            }
54
        }
55
        $path = $this->laravel->getCachedRoutesPath();
56
        if ($this->files->exists($path)) {
57
            $this->files->delete($path);
58
        }
59
        $this->info('Route caches for locales cleared!');
60
    }
61
}
62