1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Input\InputOption; |
5
|
|
|
|
6
|
|
|
class TextCollectorCommand extends SilverstripeCommand |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var string |
10
|
|
|
*/ |
11
|
|
|
protected $name = 'task:collecttext'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $description = 'Traverses through files in order to collect the \'entity master tables\' stored in each module.'; |
17
|
|
|
|
18
|
|
|
public function fire() |
19
|
|
|
{ |
20
|
|
|
increase_memory_limit_to(); |
21
|
|
|
increase_time_limit_to(); |
22
|
|
|
|
23
|
|
|
/** @var i18nTextCollector $collector */ |
24
|
|
|
$collector = i18nTextCollector::create($this->option('locale')); |
25
|
|
|
|
26
|
|
|
if (!$this->option('locale')) { |
27
|
|
|
$this->info('Starting text collection. No Locale specified'); |
28
|
|
|
} else { |
29
|
|
|
$this->info('Starting text collection for: '.$this->option('locale')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$merge = $this->getIsMerge(); |
33
|
|
|
|
34
|
|
|
if ($merge) { |
35
|
|
|
$this->info('New strings will be merged with existing strings'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// Custom writer |
39
|
|
|
$writerName = $this->option('writer'); |
40
|
|
|
if ($writerName) { |
41
|
|
|
$writer = Injector::inst()->get($writerName); |
|
|
|
|
42
|
|
|
$collector->setWriter($writer); |
43
|
|
|
$this->info('Set collector writer to: '.$writer); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// Get restrictions |
47
|
|
|
$restrictModules = ($this->option('module')) |
48
|
|
|
? explode(',', $this->option('module')) |
49
|
|
|
: null; |
50
|
|
|
|
51
|
|
|
$this->info('Collecting in modules: '.$this->option('module')); |
52
|
|
|
|
53
|
|
|
// hack untill we have something better |
54
|
|
|
ob_start(); |
55
|
|
|
$collector->run($restrictModules, $merge); |
56
|
|
|
$this->warn(ob_get_contents()); |
57
|
|
|
ob_get_clean(); |
58
|
|
|
|
59
|
|
|
$this->info(__CLASS__.' completed!'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function getIsMerge() |
63
|
|
|
{ |
64
|
|
|
$merge = $this->option('merge'); |
65
|
|
|
|
66
|
|
|
// Default to false if not given |
67
|
|
|
if (!isset($merge)) { |
68
|
|
|
$this->error('merge will be enabled by default in 4.0. Please use merge=false if you do not want to merge.'); |
69
|
|
|
|
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// merge=0 or merge=false will disable merge |
74
|
|
|
return !in_array($merge, ['0', 'false']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function getOptions() |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
['module', 'm', InputOption::VALUE_REQUIRED, 'Select the modules to collect'], |
81
|
|
|
['locale', 'l', InputOption::VALUE_REQUIRED, 'Please specify the target locale'], |
82
|
|
|
['merge', 'mr', InputOption::VALUE_NONE, 'Merge with existing'], |
83
|
|
|
['writer', 'w', InputOption::VALUE_OPTIONAL, 'Select a custom writer'], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.