-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathExportToCsvCommand.php
More file actions
81 lines (68 loc) · 2 KB
/
ExportToCsvCommand.php
File metadata and controls
81 lines (68 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace UFirst\LangImportExport\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use \UFirst\LangImportExport\Facades\LangListService;
class ExportToCsvCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'lang-export:csv';
/**
* The console command description.
*
* @var string
*/
protected $description = "Exports the language files to CSV files";
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('locale', InputArgument::REQUIRED, 'The locale to be exported.'),
array('group', InputArgument::REQUIRED, 'The group (which is the name of the language file without the extension)'),
);
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getOptions()
{
return array(
array('delimiter', 'd', InputOption::VALUE_OPTIONAL, 'The optional delimiter parameter sets the field delimiter (one character only).', ','),
array('enclosure', 'c', InputOption::VALUE_OPTIONAL, 'The optional enclosure parameter sets the field enclosure (one character only).', '"'),
array('output', 'o', InputOption::VALUE_OPTIONAL, 'Redirect the output to this file'),
);
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$locale = $this->argument('locale');
$group = $this->argument('group');
$delimiter = $this->option('delimiter');
$enclosure = $this->option('enclosure');
$strings = LangListService::loadLangList($locale, $group);
// Create output device and write CSV.
$output = $this->option('output');
if (empty($output) || !($out = fopen($output, 'w'))) {
$out = fopen('php://output', 'w');
}
// Write CSV lintes
foreach ($strings as $key => $value) {
fputcsv($out, array($key, is_array($value) ? implode(',', $value) : $value), $delimiter, $enclosure);
}
fclose($out);
}
}