1 | <?php |
||
21 | class CreateTranslationResourcesCommand extends Command |
||
22 | { |
||
23 | /** |
||
24 | * @var LanguageRepository |
||
25 | */ |
||
26 | private $languageRepo; |
||
27 | |||
28 | /** |
||
29 | * @var TranslatableRepository |
||
30 | */ |
||
31 | private $translatableRepo; |
||
32 | |||
33 | /** |
||
34 | * @var Filesystem |
||
35 | */ |
||
36 | private $filesystem; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $resourceDir; |
||
42 | |||
43 | /** |
||
44 | * @param LanguageRepository $languageRepo Language Repository |
||
45 | * @param TranslatableRepository $translatableRepo Translatable Repository |
||
46 | * @param Filesystem $filesystem symfony/filesystem tooling |
||
47 | */ |
||
48 | 6 | public function __construct( |
|
60 | |||
61 | /** |
||
62 | * set up command |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | 6 | protected function configure() |
|
74 | |||
75 | /** |
||
76 | * run command |
||
77 | * |
||
78 | * @param InputInterface $input input interface |
||
79 | * @param OutputInterface $output output interface |
||
80 | * |
||
81 | * @return void |
||
82 | */ |
||
83 | 2 | protected function execute(InputInterface $input, OutputInterface $output) |
|
84 | { |
||
85 | 2 | $output->writeln("Creating translation resource stubs"); |
|
86 | |||
87 | // Pause a bit before generating the languages. |
||
88 | 2 | $this->openDbConnection($output); |
|
89 | |||
90 | 2 | $languages = $this->languageRepo->findAll(); |
|
91 | 2 | $domains = $this->translatableRepo->createQueryBuilder() |
|
92 | 2 | ->distinct('domain') |
|
93 | 2 | ->select('domain') |
|
94 | 2 | ->getQuery() |
|
95 | 2 | ->execute() |
|
96 | 2 | ->toArray(); |
|
97 | |||
98 | 2 | array_walk( |
|
99 | $languages, |
||
100 | function ($language) use ($output, $domains) { |
||
101 | 2 | array_walk( |
|
102 | $domains, |
||
103 | 2 | function ($domain) use ($output, $language) { |
|
104 | 2 | $file = implode('.', [$domain, $language->getId(), 'odm']); |
|
105 | 2 | $this->filesystem->touch(implode(DIRECTORY_SEPARATOR, [$this->resourceDir, $file])); |
|
106 | 2 | $output->writeln("<info>Generated file $file</info>"); |
|
107 | 2 | } |
|
108 | ); |
||
109 | 2 | } |
|
110 | ); |
||
111 | 2 | } |
|
112 | |||
113 | /** |
||
114 | * Loop until DB connection is insured. |
||
115 | * |
||
116 | * @param OutputInterface $output Used to inform about db connection status |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | 2 | private function openDbConnection(OutputInterface $output) |
|
143 | } |
||
144 |