1 | <?php |
||
13 | class ExportCommand extends Command |
||
14 | { |
||
15 | /** |
||
16 | * The console command name. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $name = 'js-localization:export'; |
||
21 | |||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = "Refresh message cache and export to static files"; |
||
28 | |||
29 | /** |
||
30 | * Execute the console command. |
||
31 | * |
||
32 | * @return void |
||
33 | * @throws ConfigException |
||
34 | */ |
||
35 | public function handle() |
||
36 | { |
||
37 | $this->line('Refreshing and exporting the message cache...'); |
||
38 | |||
39 | $locales = Config::get('js-localization.locales'); |
||
40 | |||
41 | if(!is_array($locales)) { |
||
42 | throw new ConfigException('Please set the "locales" config! See https://github.com/andywer/laravel-js-localization#configuration'); |
||
43 | } |
||
44 | |||
45 | MessageCachingService::refreshCache(); |
||
46 | $messagesFilePath = $this->createPath('messages.js'); |
||
47 | $this->generateMessagesFile($messagesFilePath); |
||
48 | |||
49 | ConfigCachingService::refreshCache(); |
||
50 | $configFilePath = $this->createPath('config.js'); |
||
51 | $this->generateConfigFile($configFilePath); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Create full file path. |
||
56 | * This method will also generate the directories if they don't exist already. |
||
57 | * |
||
58 | * @var string $filename |
||
59 | * |
||
60 | * @return string $path |
||
61 | */ |
||
62 | public function createPath($filename) |
||
71 | |||
72 | /** |
||
73 | * Generate the messages file. |
||
74 | * |
||
75 | * @param string $path |
||
76 | */ |
||
77 | public function generateMessagesFile($path) |
||
87 | |||
88 | /** |
||
89 | * Generage the config file. |
||
90 | * |
||
91 | * @param string $path |
||
92 | */ |
||
93 | public function generateConfigFile($path) |
||
107 | } |
||
108 |